Class: MassiveRecord::ORM::Schema::ColumnFamilies

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

Instance Method Summary collapse

Instance Method Details

#add(family) ⇒ Object Also known as: <<



9
10
11
12
13
# File 'lib/massive_record/orm/schema/column_families.rb', line 9

def add(family)
  family.column_families = self
  raise InvalidColumnFamily.new(family.errors.full_messages.join(". ")) unless family.valid?
  super
end

#attribute_name_taken?(name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/massive_record/orm/schema/column_families.rb', line 42

def attribute_name_taken?(name)
  attribute_names.include? name.to_s
end

#attribute_namesObject



37
38
39
# File 'lib/massive_record/orm/schema/column_families.rb', line 37

def attribute_names
  to_hash.keys
end

#family_by_name(name) ⇒ Object



17
18
19
# File 'lib/massive_record/orm/schema/column_families.rb', line 17

def family_by_name(name)
  detect { |family| family.name == name.to_s }
end

#family_by_name_or_new(name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/massive_record/orm/schema/column_families.rb', line 21

def family_by_name_or_new(name)
  unless known_family = family_by_name(name)
    known_family = ColumnFamily.new(:name => name)
    add(known_family)
  end
  known_family
end

#to_hashObject



30
31
32
33
34
35
# File 'lib/massive_record/orm/schema/column_families.rb', line 30

def to_hash
  inject({}) do |hash, column_family|
    hash.update(column_family.to_hash)
    hash
  end
end