Class: Rubiks::Dimension
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
#degenerate(new_value = nil) ⇒ Object
4
5
6
7
|
# File 'lib/rubiks/dimension.rb', line 4
def degenerate(new_value=nil)
@degenerate = new_value.to_s if new_value.present?
@degenerate ||= @options[:degenerate]
end
|
#hierarchies ⇒ Object
14
15
16
|
# File 'lib/rubiks/dimension.rb', line 14
def hierarchies
@hierarchies ||= []
end
|
#hierarchy(hierarchy_name, options = {}, &block) ⇒ Object
18
19
20
21
|
# File 'lib/rubiks/dimension.rb', line 18
def hierarchy(hierarchy_name, options={}, &block)
options.merge!(:table => degenerate ? 'degenerate' : self.table)
hierarchies.push ::Rubiks::Hierarchy.find_or_create(hierarchy_name, options, &block)
end
|
#json_hash ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/rubiks/dimension.rb', line 23
def json_hash
hash = default_json_attributes.merge(
:hierarchies => hierarchies.map{ |hier| hier.json_hash }
)
hash[:type] = type.to_s if type.present?
hash.delete_if { |key,value| value.nil? }
hash.stringify_keys!
end
|
#to_xml(builder = nil) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rubiks/dimension.rb', line 32
def to_xml(builder = nil)
builder = builder || new_builder
xml_attrs = default_xml_attributes
if self.degenerate
xml_attrs.delete(:table)
else
xml_attrs[:foreignKey] = "#{name}_id"
end
xml_attrs[:type] = type if type.present?
builder.dimension(xml_attrs) do
hierarchies.each{ |hierarchy| hierarchy.to_xml(builder) }
end
end
|
#type(new_value = nil) ⇒ Object
9
10
11
12
|
# File 'lib/rubiks/dimension.rb', line 9
def type(new_value=nil)
@type = new_value.to_s if new_value.present?
@type ||= @options[:type]
end
|