Module: HashDB::Model
- Defined in:
- lib/hash_db/model/core.rb,
lib/hash_db/model/query.rb,
lib/hash_db/model/association.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/hash_db/model/core.rb', line 3 def attributes @attributes end |
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/hash_db/model/core.rb', line 5 def self.included(klass) klass.extend ClassMethods klass.all = {} klass.keys :id klass.primary_key :id end |
Instance Method Details
#destroy ⇒ Object
34 35 36 |
# File 'lib/hash_db/model/core.rb', line 34 def destroy self.class.all.delete id end |
#initialize(args = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hash_db/model/core.rb', line 12 def initialize(args = {}) @attributes = {} args.each do |key, value| if respond_to?("#{key}=") send("#{key}=", value) else raise InvalidKeyError.new "Invalid key #{key}." end end end |
#save ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hash_db/model/core.rb', line 23 def save if id.nil? self.id = if self.class.all.any? self.class.all.keys.last + 1 else 1 end end self.class.all[id] = self end |