module ExtendIt::ArrayOf::ArrayClassMethods

Attributes

finder[R]
scopes[R]

Public Instance Methods

entity?(obj) click to toggle source
# File lib/extend_it/array_of.rb, line 33
def entity?(obj)
  obj.is_a?(@entity_class)
end
find_by(name, &block) click to toggle source
# File lib/extend_it/array_of.rb, line 49
def find_by(name, &block)
  name = name.ensure_symbol!
  @finder = block.nil? ? proc { |e| e.send(name) } : block
end
finder?() click to toggle source
# File lib/extend_it/array_of.rb, line 54
def finder?
  !@finder.nil?
end
scope(*names, &block) click to toggle source
# File lib/extend_it/array_of.rb, line 37
def scope(*names, &block)
  names = names.ensure_array(:flatten, :ensure_symbol, :compact, :uniq)
  names.each do |name|
    @scopes[name] = block.nil? ? proc { |e| e.send(name) } : block
    str = name.to_s
    if str[-1] == '?'
      @scopes[str[0..-2].to_sym] =
        block.nil? ? proc { |e| e.send(name) } : block
    end
  end
end
select(arr) click to toggle source
# File lib/extend_it/array_of.rb, line 25
def select(arr)
  if arr.is_a?(self)
    arr.to_a
  else
    arr.select { |a| a.is_a?(@entity_class) }
  end
end