Class: MassiveRecord::ORM::Schema::Fields

Inherits:
Set
  • Object
show all
Defined in:
lib/massive_record/orm/schema/fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contained_inObject

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: <<

Raises:



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.full_messages.join(". ")) unless field.valid?
  super
end

#attribute_name_taken?(name, check_only_self = false) ⇒ Boolean

Returns:

  • (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_namesObject



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_hashObject



27
28
29
# File 'lib/massive_record/orm/schema/fields.rb', line 27

def to_hash
  Hash[collect { |field| [field.name, field] }]
end