Class: Rubiks::Schema

Inherits:
NamedObject show all
Defined in:
lib/rubiks/schema.rb

Instance Method Summary collapse

Methods inherited from NamedObject

[], #caption, clear!, #column, default, #default_json_attributes, #default_xml_attributes, define, #description, find_or_create, #hidden, #icon_type, #initialize, instances, #name, #table, #to_json

Constructor Details

This class inherits a constructor from Rubiks::NamedObject

Instance Method Details

#cube(cube_name, options = {}, &block) ⇒ Object



8
9
10
# File 'lib/rubiks/schema.rb', line 8

def cube(cube_name, options={}, &block)
  cubes.push ::Rubiks::Cube.find_or_create(cube_name, options, &block)
end

#cubesObject



4
5
6
# File 'lib/rubiks/schema.rb', line 4

def cubes
  @cubes ||= []
end

#json_hashObject



12
13
14
15
16
# File 'lib/rubiks/schema.rb', line 12

def json_hash
  hash = default_json_attributes
  hash[:cubes] = cubes.map{ |c| c.json_hash } if cubes.present?
  hash.stringify_keys!
end

#to_xml(builder = nil) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/rubiks/schema.rb', line 18

def to_xml(builder = nil)
  builder = builder || new_builder
  builder.instruct!

  builder.schema(:name => caption) do
    cubes.each{ |cube| cube.to_xml(builder) }
  end
end