Module: ArrayOfHashSimpleDb::ClassMethods
- Defined in:
- lib/array_of_hash_simple_db.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/array_of_hash_simple_db.rb', line 29
def method_missing(method, *args, &block)
if records.respond_to?(method)
records.public_send(method, *args, &block)
else
super
end
end
|
Instance Attribute Details
#records ⇒ Object
Also known as:
all
11
12
13
|
# File 'lib/array_of_hash_simple_db.rb', line 11
def records
@_initialized_records ||= (@records || []).map { |r| new(r) }
end
|
Instance Method Details
#find_by(condition) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/array_of_hash_simple_db.rb', line 17
def find_by(condition)
records.detect do |record|
condition.all? do |k, v|
[v].flatten.include?(record.public_send(k))
end
end
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
25
26
27
|
# File 'lib/array_of_hash_simple_db.rb', line 25
def respond_to_missing?(name, include_private = false)
records.respond_to?(name) || super
end
|