Module: Rocx::PropertyBuilder::ClassMethods

Defined in:
lib/rocx/property_builder.rb

Instance Method Summary collapse

Instance Method Details

#propertiesObject



47
48
49
# File 'lib/rocx/property_builder.rb', line 47

def properties
  @properties ||= {}
end

#properties_tag(*args) ⇒ Object



9
10
11
12
# File 'lib/rocx/property_builder.rb', line 9

def properties_tag(*args)
  @properties_tag = args.first if args.any?
  @properties_tag
end

#property(name, as: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rocx/property_builder.rb', line 29

def property(name, as: nil)
  properties[name] = (as || name).to_s

  class_eval "  def \#{name}\n    property_key = \"\#{name}\".to_sym\n    class_name = properties[property_key].split(\"_\").map(&:capitalize).join\n    prop_class = Rocx::Properties.const_get class_name\n\n    if instance_variable_get(\"@\#{name}\").nil?\n      instance_variable_set \"@\#{name}\", prop_class.new\n    end\n\n    instance_variable_get \"@\#{name}\"\n  end\n  CODE\nend\n", __FILE__, __LINE__ + 1

#value_property(name, as: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rocx/property_builder.rb', line 14

def value_property(name, as: nil)
  attr_reader name

  properties[name] = (as || name).to_s

  class_eval "  def \#{name}=(value)\n    property_key = \"\#{name}\".to_sym\n    class_name = properties[property_key].split(\"_\").map(&:capitalize).join\n    prop_class = Rocx::Properties.const_get class_name\n    instance_variable_set \"@\#{name}\", prop_class.new(value)\n  end\n  CODE\nend\n", __FILE__, __LINE__ + 1