Module: Mingle4r::CommonDynClassInstanceMethods

Defined in:
lib/mingle4r/common_dyn_class_instance_methods.rb

Overview

common dynamic class instance methods

Instance Method Summary collapse

Instance Method Details

#custom_propertiesObject



31
32
33
34
35
36
37
38
# File 'lib/mingle4r/common_dyn_class_instance_methods.rb', line 31

def custom_properties
  custom_props = []
  props = attributes.keys
  PropertyDefinition.find(:all).each do |prop|
    custom_props << {prop.name => prop.column_name} if(props.include?(prop.column_name))
  end
  custom_props
end

#property_value(prop_name) ⇒ Object

gets the value of a property. The property name can be given in several ways. suppose we are trying to get the property ‘Iteration Number’ as in mingle

1) give the name as seen card.property_value(‘Iteration Number’)

2) give the property method name i.e. in the active resource object it would become by default ‘cp_iteration_number’ attribute unless set differently in Mingle

3) give the method a ‘space separated’ / ‘camelcased’ method name. e.g. - ‘Iteration Number’ ‘IterationNumber’



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mingle4r/common_dyn_class_instance_methods.rb', line 15

def property_value(prop_name)
  begin
    column_name = PropertyDefinition.column_name_for(prop_name.to_s)
    self.send(column_name.to_sym) 
  rescue NoMethodError
    if self.attributes.has_key?(prop_name)
      self.attributes[prop_name]
    else
      # try calling a underscorized method. eg 'Iteration Number' becomes
      # 'iteration_number'
      method_id = (prop_name.split(' ').map { |substring| substring.downcase }).join('_').underscore.to_sym
      self.send(method_id)
    end
  end
end