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

Instance Method Details

#child_ids(side = nil) ⇒ Object

eg, A+B is a child of A and B



30
31
32
33
34
35
36
37
# File 'card/lib/card/name/all/descendants.rb', line 30

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(&block) ⇒ Object



21
22
23
24
25
26
27
# File 'card/lib/card/name/all/descendants.rb', line 21

def each_child &block
  return unless id

  Card.where(
    "(left_id = #{id} or right_id = #{id}) and trash is false"
  ).each(&block)
end

#each_descendant(&block) ⇒ Object



39
40
41
42
43
44
# File 'card/lib/card/name/all/descendants.rb', line 39

def each_descendant &block
  each_child do |child|
    yield child
    child.each_descendant(&block)
  end
end

#field_idsObject



17
18
19
# File 'card/lib/card/name/all/descendants.rb', line 17

def field_ids
  child_ids :left
end

#field_namesObject



13
14
15
# File 'card/lib/card/name/all/descendants.rb', line 13

def field_names
  field_ids.map { |id| Card::Name[id] }
end

#fieldsObject

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 fields
  field_ids.map { |id| Card[id] }
end