Class: PassiveRecord::Base
- Inherits:
-
Object
- Object
- PassiveRecord::Base
- Defined in:
- lib/passive_record/base.rb
Constant Summary collapse
- @@instances =
{}
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#key ⇒ Object
(also: #id)
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #==(comparison_object) ⇒ Object
- #[](attribute_name) ⇒ Object
- #[]=(attribute_name, value) ⇒ Object
-
#initialize(attributes = {}) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(attributes = {}) {|_self| ... } ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/passive_record/base.rb', line 12 def initialize(attributes = {}) @attributes = attributes yield self if block_given? end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/passive_record/base.rb', line 8 def attributes @attributes end |
#key ⇒ Object Also known as: id
Returns the value of attribute key.
8 9 10 |
# File 'lib/passive_record/base.rb', line 8 def key @key end |
Class Method Details
.count ⇒ Object
51 52 53 |
# File 'lib/passive_record/base.rb', line 51 def count find_every.size end |
.create(*args) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/passive_record/base.rb', line 35 def create(*args) attributes = (args) key = args.first || find_every.size+1 instance = self.new(attributes) instance.key = key @@instances[base_key(key)] = instance return key end |
.find(*args) ⇒ Object
46 47 48 49 |
# File 'lib/passive_record/base.rb', line 46 def find(*args) = (args) args.first == :all ? find_every : find_from_keys(args) end |
Instance Method Details
#==(comparison_object) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/passive_record/base.rb', line 25 def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object.id == id && !comparison_object.new_record?) end |
#[](attribute_name) ⇒ Object
17 18 19 |
# File 'lib/passive_record/base.rb', line 17 def [](attribute_name) self.attributes[attribute_name] end |
#[]=(attribute_name, value) ⇒ Object
21 22 23 |
# File 'lib/passive_record/base.rb', line 21 def []=(attribute_name, value) self.attributes[attribute_name] = value end |