Module: PropertySets::PropertySetModel::InstanceMethods

Defined in:
lib/property_sets/property_set_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#value_serializedObject

Returns the value of attribute value_serialized.



55
56
57
# File 'lib/property_sets/property_set_model.rb', line 55

def value_serialized
  @value_serialized
end

Instance Method Details

#disableObject



18
19
20
21
# File 'lib/property_sets/property_set_model.rb', line 18

def disable
  update_attribute(:value, "0")
  self
end

#enableObject



13
14
15
16
# File 'lib/property_sets/property_set_model.rb', line 13

def enable
  update_attribute(:value, "1")
  self
end

#false?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/property_sets/property_set_model.rb', line 5

def false?
  [ "false", "0", "", "off", "n" ].member?(value.to_s.downcase)
end

#protected?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/property_sets/property_set_model.rb', line 23

def protected?
  self.class.protected?(name.to_sym)
end

#reload(*args, &block) ⇒ Object



46
47
48
49
# File 'lib/property_sets/property_set_model.rb', line 46

def reload(*args, &block)
  @deserialized_value = nil
  super
end

#to_sObject



51
52
53
# File 'lib/property_sets/property_set_model.rb', line 51

def to_s
  value.to_s
end

#true?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/property_sets/property_set_model.rb', line 9

def true?
  !false?
end

#valueObject



27
28
29
30
31
32
33
34
35
# File 'lib/property_sets/property_set_model.rb', line 27

def value
  if value_serialized
    v = read_attribute(:value)
    return nil if v.nil? || v == "null"
    @deserialized_value ||= JSON.parse(v)
  else
    super
  end
end

#value=(v) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/property_sets/property_set_model.rb', line 37

def value=(v)
  if value_serialized
    @deserialized_value = v
    write_attribute(:value, v.to_json)
  else
    super(v)
  end
end