module PropertySets::PropertySetModel::InstanceMethods

Attributes

value_serialized[RW]

Public Instance Methods

disable() click to toggle source
# File lib/property_sets/property_set_model.rb, line 31
def disable
  update_attribute(:value, "0")
  self
end
enable() click to toggle source
# File lib/property_sets/property_set_model.rb, line 26
def enable
  update_attribute(:value, "1")
  self
end
false?() click to toggle source
# File lib/property_sets/property_set_model.rb, line 18
def false?
  ["false", "0", "", "off", "n"].member?(value.to_s.downcase)
end
protected?() click to toggle source
# File lib/property_sets/property_set_model.rb, line 36
def protected?
  self.class.protected?(name.to_sym)
end
reload(*args, &block) click to toggle source
Calls superclass method
# File lib/property_sets/property_set_model.rb, line 58
def reload(*args, &block)
  @deserialized_value = nil
  super
end
to_s() click to toggle source
# File lib/property_sets/property_set_model.rb, line 63
def to_s
  value.to_s
end
true?() click to toggle source
# File lib/property_sets/property_set_model.rb, line 22
def true?
  !false?
end
value() click to toggle source
Calls superclass method
# File lib/property_sets/property_set_model.rb, line 40
def value
  if value_serialized
    v = read_attribute(:value)
    @deserialized_value ||= PropertySets::Casting.deserialize(v)
  else
    super
  end
end
value=(v) click to toggle source
Calls superclass method
# File lib/property_sets/property_set_model.rb, line 49
def value=(v)
  if value_serialized
    @deserialized_value = v
    write_attribute(:value, v.to_json)
  else
    super
  end
end

Private Instance Methods

coerce_value() click to toggle source
# File lib/property_sets/property_set_model.rb, line 85
def coerce_value
  if value && !value_serialized
    self.value = value.to_s
  end
end
owner_class_instance() click to toggle source
# File lib/property_sets/property_set_model.rb, line 91
def owner_class_instance
  send(self.class.owner_class_sym)
end
validate_format_of_name() click to toggle source
# File lib/property_sets/property_set_model.rb, line 71
def validate_format_of_name
  if name.blank?
    errors.add(:name, :blank)
  elsif !name.is_a?(String) || name !~ /^([a-z0-9]+_?)+$/
    errors.add(:name, :invalid)
  end
end
validate_length_of_serialized_data() click to toggle source
# File lib/property_sets/property_set_model.rb, line 79
def validate_length_of_serialized_data
  if value_serialized && read_attribute(:value).to_s.size > value_column_limit
    errors.add(:value, :invalid)
  end
end
value_column_limit() click to toggle source
# File lib/property_sets/property_set_model.rb, line 95
def value_column_limit
  column = self.class.columns_hash.fetch("value")

  # use sql_type because type returns :text for all text types regardless of length
  column.limit || COLUMN_TYPE_LIMITS.fetch(column.sql_type)
end