module PropertySets::PropertySetModel::ClassMethods
Public Class Methods
extended(base)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 104 def self.extended(base) base.validate :validate_format_of_name base.validate :validate_length_of_serialized_data base.before_create :coerce_value base.attr_accessible :name, :value if defined?(ProtectedAttributes) end
Public Instance Methods
default(key)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 123 def default(key) PropertySets::Casting.read(type(key), raw_default(key)) end
keys()
click to toggle source
# File lib/property_sets/property_set_model.rb, line 119 def keys properties.keys end
owner_assoc()
click to toggle source
# File lib/property_sets/property_set_model.rb, line 152 def owner_assoc @owner_assoc end
owner_assoc=(association)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 148 def owner_assoc=(association) @owner_assoc = association end
owner_class=(owner_class_name)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 139 def owner_class=(owner_class_name) @owner_class_sym = owner_class_name.to_s.demodulize.underscore.to_sym belongs_to owner_class_sym, class_name: owner_class_name validates_presence_of owner_class_sym, class_name: owner_class_name validates_uniqueness_of :name, scope: owner_class_key_sym, case_sensitive: false attr_accessible owner_class_key_sym, owner_class_sym if defined?(ProtectedAttributes) end
owner_class_key_sym()
click to toggle source
# File lib/property_sets/property_set_model.rb, line 160 def owner_class_key_sym :"#{owner_class_sym}_id" end
owner_class_sym()
click to toggle source
# File lib/property_sets/property_set_model.rb, line 156 def owner_class_sym @owner_class_sym end
properties()
click to toggle source
# File lib/property_sets/property_set_model.rb, line 111 def properties @properties ||= HashWithIndifferentAccess.new end
property(key, options = nil)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 115 def property(key, options = nil) properties[key] = options end
protected?(key)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 135 def protected?(key) properties[key].try(:[], :protected) || false end
raw_default(key)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 127 def raw_default(key) properties[key].try(:[], :default) end
type(key)
click to toggle source
# File lib/property_sets/property_set_model.rb, line 131 def type(key) properties[key].try(:[], :type) || :string end