Class: MiniModel
Defined Under Namespace
Modules: AssociationClassMethods, ClassMethods
Classes: DuplicateKeyError, HasManyAssociation
Instance Method Summary
collapse
all, count, find, indexed_by, insert, keys, load_from, options, primary_key
belongs_to, has_many
Constructor Details
#initialize(attributes) ⇒ MiniModel
Returns a new instance of MiniModel.
4
5
6
|
# File 'lib/minimodel.rb', line 4
def initialize(attributes)
@attributes = attributes.to_hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/minimodel.rb', line 28
def method_missing(symbol, *args, &block)
if @attributes.key?(symbol) && args.empty? && block.nil?
return @attributes[symbol]
else
super symbol, *args, &block
end
end
|
Instance Method Details
#eql?(object) ⇒ Boolean
12
13
14
|
# File 'lib/minimodel.rb', line 12
def eql?(object)
object.class == self.class && object.hash == self.hash
end
|
#hash ⇒ Object
8
9
10
|
# File 'lib/minimodel.rb', line 8
def hash
@attributes.hash
end
|
#read_attribute(name) ⇒ Object
24
25
26
|
# File 'lib/minimodel.rb', line 24
def read_attribute(name)
@attributes[name]
end
|
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
36
37
38
|
# File 'lib/minimodel.rb', line 36
def respond_to_missing?(symbol, include_private = false)
@attributes.key?(symbol)
end
|
#to_hash ⇒ Object
16
17
18
|
# File 'lib/minimodel.rb', line 16
def to_hash
@attributes
end
|
#to_json ⇒ Object
20
21
22
|
# File 'lib/minimodel.rb', line 20
def to_json
@attributes.to_json
end
|