Class: MassiveRecord::ORM::Schema::Fields
- Inherits:
-
Set
- Object
- Set
- MassiveRecord::ORM::Schema::Fields
- Defined in:
- lib/massive_record/orm/schema/fields.rb
Instance Attribute Summary collapse
-
#contained_in ⇒ Object
Returns the value of attribute contained_in.
Instance Method Summary collapse
- #add(field) ⇒ Object (also: #<<)
- #attribute_name_taken?(name, check_only_self = false) ⇒ Boolean
- #attribute_names ⇒ Object
- #field_by_name(name) ⇒ Object
- #to_hash ⇒ Object
Instance Attribute Details
#contained_in ⇒ Object
Returns the value of attribute contained_in.
7 8 9 |
# File 'lib/massive_record/orm/schema/fields.rb', line 7 def contained_in @contained_in end |
Instance Method Details
#add(field) ⇒ Object Also known as: <<
9 10 11 12 13 |
# File 'lib/massive_record/orm/schema/fields.rb', line 9 def add(field) field.fields = self raise InvalidField.new(field.errors..join(". ")) unless field.valid? super end |
#attribute_name_taken?(name, check_only_self = false) ⇒ Boolean
21 22 23 24 |
# File 'lib/massive_record/orm/schema/fields.rb', line 21 def attribute_name_taken?(name, check_only_self = false) name = name.to_s check_only_self || contained_in.nil? ? attribute_names.include?(name) : contained_in.attribute_name_taken?(name) end |
#attribute_names ⇒ Object
31 32 33 |
# File 'lib/massive_record/orm/schema/fields.rb', line 31 def attribute_names to_hash.keys end |
#field_by_name(name) ⇒ Object
16 17 18 19 |
# File 'lib/massive_record/orm/schema/fields.rb', line 16 def field_by_name(name) name = name.to_s detect { |field| field.name == name } end |
#to_hash ⇒ Object
27 28 29 |
# File 'lib/massive_record/orm/schema/fields.rb', line 27 def to_hash Hash[collect { |field| [field.name, field] }] end |