Module: Videojuicer::Resource::PropertyRegistry::SingletonMethods

Defined in:
lib/videojuicer/resource/property_registry.rb

Instance Method Summary collapse

Instance Method Details

#property(prop_name, klass, options = {}) ⇒ Object

Registers an attribute using a datamapper-style syntax. Creates setter and getter methods

Raises:

  • (ArgumentError)


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/videojuicer/resource/property_registry.rb', line 118

def property(prop_name, klass, options={})
  # Can't raise twice.          
  prop_name = prop_name.to_sym
  raise ArgumentError, "Property #{prop_name} already registered." if self.attributes.include?(prop_name)
  
  options = {:class=>klass, :writer=>:public}.merge(options)
  # Register with the class
  self.attributes[prop_name] = options
  # Create setter methods
  define_method prop_name do
    attr_get(prop_name)
  end
  
  private if options[:writer] == :private
  protected if options[:writer] == :protected
  
    define_method "#{prop_name}=" do |arg|
      attr_set(prop_name, arg)
    end
  
  public
end