Class: Kludge::Mishmash

Inherits:
Object
  • Object
show all
Defined in:
lib/kludge/mishmash.rb

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  parts << Many.new(name, options)
  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, options = {})
  parts << One.new(name, options)
  attr_reader name

  define_method "#{name}=" do |value|
    @parts.find { |part| part.name == name }.value = value
    instance_variable_set("@#{name}", value)
  end
end

.partsObject



4
5
6
# File 'lib/kludge/mishmash.rb', line 4

def self.parts
  @parts ||= Parts.new
end

Instance Method Details

#saveObject



35
36
37
# File 'lib/kludge/mishmash.rb', line 35

def save
  @parts.save
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/kludge/mishmash.rb', line 39

def valid?
  @parts.valid?
end