Module: ActsAsTableless::InstanceMethods
- Defined in:
- lib/acts_as_tableless.rb
Instance Method Summary collapse
- #delete ⇒ Object (also: #delete!)
- #persisted? ⇒ Boolean
- #readonly? ⇒ Boolean
- #save(validate = true) ⇒ Object (also: #save!)
Instance Method Details
#delete ⇒ Object Also known as: delete!
85 86 87 88 |
# File 'lib/acts_as_tableless.rb', line 85 def delete ActsAsTableless.class_variable_get(:"@@#{self.class.name.underscore}").delete(self) return true end |
#persisted? ⇒ Boolean
64 65 66 |
# File 'lib/acts_as_tableless.rb', line 64 def persisted? false end |
#readonly? ⇒ Boolean
68 69 70 |
# File 'lib/acts_as_tableless.rb', line 68 def readonly? true end |
#save(validate = true) ⇒ Object Also known as: save!
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/acts_as_tableless.rb', line 72 def save(validate = true) unless self.id id = ActsAsTableless.class_variable_get(:"@@#{self.class.name.underscore}_increment") id += 1 while self.class.send(:find, id) self.id = ActsAsTableless.class_variable_set(:"@@#{self.class.name.underscore}_increment", id) end raise "Duplicate ID" if self.class.send(:find, id) # these are read only if validate ? valid? : true ActsAsTableless.class_variable_get(:"@@#{self.class.name.underscore}").push(self) return self end end |