Class: Kludge::Mishmash
- Inherits:
-
Object
- Object
- Kludge::Mishmash
- Defined in:
- lib/kludge/mishmash.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Mishmash
constructor
A new instance of Mishmash.
- #save ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Mishmash
Returns a new instance of Mishmash.
28 29 30 31 32 33 |
# File 'lib/kludge/mishmash.rb', line 28 def initialize(attributes = {}) @parts = self.class.parts.dup attributes.each do |key, value| send("#{key}=", value) end end |
Class Method Details
.many(name, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/kludge/mishmash.rb', line 18 def self.many(name, = {}) parts << Many.new(name, ) attr_reader name define_method "#{name}=" do |value| @parts.find { |part| part.name == name }.value = value instance_variable_set("@#{name}", value) end end |
.one(name, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/kludge/mishmash.rb', line 8 def self.one(name, = {}) parts << One.new(name, ) attr_reader name define_method "#{name}=" do |value| @parts.find { |part| part.name == name }.value = value instance_variable_set("@#{name}", value) end end |
Instance Method Details
#save ⇒ Object
35 36 37 |
# File 'lib/kludge/mishmash.rb', line 35 def save @parts.save end |
#valid? ⇒ Boolean
39 40 41 |
# File 'lib/kludge/mishmash.rb', line 39 def valid? @parts.valid? end |