Class: Rubiks::Schema
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
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
|
#cubes ⇒ Object
4
5
6
|
# File 'lib/rubiks/schema.rb', line 4
def cubes
@cubes ||= []
end
|
#json_hash ⇒ Object
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
|