Class: Kludge::Part
- Inherits:
-
Object
- Object
- Kludge::Part
- Extended by:
- ActiveModel::Naming, ActiveModel::Translation
- Defined in:
- lib/kludge/part.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #dependency ⇒ Object
- #dependent? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Part
constructor
A new instance of Part.
- #many? ⇒ Boolean
- #one? ⇒ Boolean
- #save ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, options = {}) ⇒ Part
Returns a new instance of Part.
9 10 11 12 13 14 15 |
# File 'lib/kludge/part.rb', line 9 def initialize(name, = {}) @name = name = @value = [:value] @children = [] @errors = ActiveModel::Errors.new(self) end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
7 8 9 |
# File 'lib/kludge/part.rb', line 7 def children @children end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/kludge/part.rb', line 6 def errors @errors end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/kludge/part.rb', line 6 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/kludge/part.rb', line 7 def parent @parent end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/kludge/part.rb', line 6 def value @value end |
Instance Method Details
#dependency ⇒ Object
29 30 31 |
# File 'lib/kludge/part.rb', line 29 def dependency [:belongs_to] end |
#dependent? ⇒ Boolean
25 26 27 |
# File 'lib/kludge/part.rb', line 25 def dependent? [:belongs_to] end |
#many? ⇒ Boolean
17 18 19 |
# File 'lib/kludge/part.rb', line 17 def many? self.class == Many end |
#one? ⇒ Boolean
21 22 23 |
# File 'lib/kludge/part.rb', line 21 def one? self.class == One end |
#save ⇒ Object
33 34 35 |
# File 'lib/kludge/part.rb', line 33 def save children.each(&:save) end |
#valid? ⇒ Boolean
37 38 39 |
# File 'lib/kludge/part.rb', line 37 def valid? validate && children.map(&:valid?).all? end |