Module: Card::Name::All::Descendants
- Included in:
- Card::Name::All
- Defined in:
- card/lib/card/name/all/descendants.rb
Overview
Card methods for finding name children, eg A+B is a child of A and B
Instance Method Summary collapse
-
#child_ids(side = nil) ⇒ Object
eg, A+B is a child of A and B.
-
#each_child ⇒ Object
-
#each_descendant(&block) ⇒ Object
-
#field_cards ⇒ Object
NOTE: for all these helpers, method returns all fields/children/descendants.
-
#field_ids ⇒ Object
-
#field_names ⇒ Object
Instance Method Details
#child_ids(side = nil) ⇒ Object
eg, A+B is a child of A and B
32 33 34 35 36 37 38 39 |
# File 'card/lib/card/name/all/descendants.rb', line 32 def child_ids side=nil return [] unless id side ||= name.simple? ? :part : :left_id Auth.as_bot do Card.search({ side => id, return: :id, limit: 0 }, "children of #{name}") end end |
#each_child ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'card/lib/card/name/all/descendants.rb', line 21 def each_child return unless id sql = "(left_id = #{id} or right_id = #{id}) and trash is false" Card.where(sql).find_each do |card| card.include_set_modules yield card end end |
#each_descendant(&block) ⇒ Object
41 42 43 44 45 46 |
# File 'card/lib/card/name/all/descendants.rb', line 41 def each_descendant &block each_child do |child| yield child child.each_descendant(&block) end end |
#field_cards ⇒ Object
NOTE: for all these helpers, method returns all fields/children/descendants. (Not just those current user has permission to read.)
9 10 11 |
# File 'card/lib/card/name/all/descendants.rb', line 9 def field_cards field_ids.map(&:card) end |
#field_ids ⇒ Object
17 18 19 |
# File 'card/lib/card/name/all/descendants.rb', line 17 def field_ids child_ids :left end |
#field_names ⇒ Object
13 14 15 |
# File 'card/lib/card/name/all/descendants.rb', line 13 def field_names field_ids.map(&:cardname) end |