Module: PropertySets::PropertySetModel::ClassMethods

Defined in:
lib/property_sets/property_set_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object


104
105
106
107
108
109
# 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

Instance Method Details

#default(key) ⇒ Object


120
121
122
# File 'lib/property_sets/property_set_model.rb', line 120

def default(key)
  PropertySets::Casting.read(type(key), raw_default(key))
end

#keysObject


116
117
118
# File 'lib/property_sets/property_set_model.rb', line 116

def keys
  @properties.keys
end

#owner_assocObject


148
149
150
# File 'lib/property_sets/property_set_model.rb', line 148

def owner_assoc
  @owner_assoc
end

#owner_assoc=(association) ⇒ Object


144
145
146
# File 'lib/property_sets/property_set_model.rb', line 144

def owner_assoc=(association)
  @owner_assoc = association
end

#owner_class=(owner_class_name) ⇒ Object


136
137
138
139
140
141
142
# File 'lib/property_sets/property_set_model.rb', line 136

def owner_class=(owner_class_name)
  @owner_class_sym = owner_class_name.underscore.to_sym
  belongs_to              owner_class_sym
  validates_presence_of   owner_class_sym
  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_symObject


156
157
158
# File 'lib/property_sets/property_set_model.rb', line 156

def owner_class_key_sym
  "#{owner_class_sym}_id".to_sym
end

#owner_class_symObject


152
153
154
# File 'lib/property_sets/property_set_model.rb', line 152

def owner_class_sym
  @owner_class_sym
end

#property(key, options = nil) ⇒ Object


111
112
113
114
# File 'lib/property_sets/property_set_model.rb', line 111

def property(key, options = nil)
  @properties ||= HashWithIndifferentAccess.new
  @properties[key] = options
end

#protected?(key) ⇒ Boolean

Returns:

  • (Boolean)

132
133
134
# File 'lib/property_sets/property_set_model.rb', line 132

def protected?(key)
  @properties[key].try(:[], :protected) || false
end

#raw_default(key) ⇒ Object


124
125
126
# File 'lib/property_sets/property_set_model.rb', line 124

def raw_default(key)
  @properties[key].try(:[], :default)
end

#type(key) ⇒ Object


128
129
130
# File 'lib/property_sets/property_set_model.rb', line 128

def type(key)
  @properties[key].try(:[], :type) || :string
end