Module: HasProperties::InstanceMethods

Defined in:
lib/has_properties.rb

Instance Method Summary collapse

Instance Method Details

#convert_property(value, type, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/has_properties.rb', line 35

def convert_property(value, type, options = {})
  value = evaluate_property_default(options[:default]) if value.nil? && options[:default]
  
  case type.to_sym
  when :string
    value.to_s
  when :integer
    value.to_i
  when :boolean
    !!value
  end
end

#evaluate_property_default(default) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/has_properties.rb', line 48

def evaluate_property_default(default)
  case default
  when Proc
    default.bind(self).call
  else
    default
  end
end

#property_hashObject



30
31
32
33
# File 'lib/has_properties.rb', line 30

def property_hash
  send("#{self.class.property_field}=", {}) unless send(self.class.property_field)
  send(self.class.property_field)
end