Module: ExtendIt::ArrayOf::ArrayClassMethods
- Includes:
- ExtendIt::Asserts
- Defined in:
- lib/extend_it/array_of.rb
Instance Attribute Summary collapse
-
#finder ⇒ Object
readonly
Returns the value of attribute finder.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
Instance Method Summary collapse
- #entity?(obj) ⇒ Boolean
- #find_by(name, &block) ⇒ Object
- #has_finder? ⇒ Boolean
- #scope(*names, &block) ⇒ Object
- #select(arr) ⇒ Object
Instance Attribute Details
#finder ⇒ Object (readonly)
Returns the value of attribute finder.
25 26 27 |
# File 'lib/extend_it/array_of.rb', line 25 def finder @finder end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
25 26 27 |
# File 'lib/extend_it/array_of.rb', line 25 def scopes @scopes end |
Instance Method Details
#entity?(obj) ⇒ Boolean
35 36 37 |
# File 'lib/extend_it/array_of.rb', line 35 def entity?(obj) obj.is_a?(@entity_class) end |
#find_by(name, &block) ⇒ Object
50 51 52 53 |
# File 'lib/extend_it/array_of.rb', line 50 def find_by(name, &block) assert_symbol(:name) @finder = block.nil? ? proc { |e| e.send(name) } : block end |
#has_finder? ⇒ Boolean
55 56 57 |
# File 'lib/extend_it/array_of.rb', line 55 def has_finder? !@finder.nil? end |
#scope(*names, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/extend_it/array_of.rb', line 39 def scope(*names, &block) names.flatten.uniq.each do |name| name = name.ensure_symbol || next @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) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/extend_it/array_of.rb', line 27 def select(arr) if arr.is_a?(self) arr.to_a else arr.select { |a| a.is_a?(@entity_class) } end end |