Top Level Namespace

Defined Under Namespace

Modules: Properties

Instance Method Summary collapse

Instance Method Details

#__properties__Object



39
40
41
# File 'lib/properties.rb', line 39

def __properties__
 @__properties__
end

#collection(name, kind) ⇒ Object



84
85
86
# File 'lib/properties.rb', line 84

def collection name, kind
  property name, kind, true
end

#property(name, kind, is_collection = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/properties.rb', line 32

def property name, kind, is_collection = false
  classname = eval kind.to_s.camelcase

  @__properties__ ||= {}
  @__properties__[name] = Properties::Property.new(name, kind, is_collection)
  @is_collection = is_collection
 
  def __properties__
   @__properties__
  end
 

  if is_collection
    code = "
      def #{name}
        @#{name} ||= []
        @#{name}
      end
    " 
    eval code

    code = "
      def #{name}=(values)
        values ||= []
        values.each do |value|
          raise Properties::PropertyError.new(\"Can't set value (\#{value.inspect}) to property #{name} since not all elements are a #{classname}\") if not value.kind_of?(#{classname})
        end

        @#{name} = values
      end
    "
    eval code

  else
    code = "
      def #{name}
        @#{name}
      end
    " 
    eval code

    code = "
      def #{name}=(value)
        raise Properties::PropertyError.new(\"Can't set value (\#{value}.inspect) to property #{name} since it's not a #{classname}\") if not value.kind_of?(#{classname})
        @#{name} = value
      end
    "
    eval code
  end
  
end