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



85
86
87
88
89
# File 'lib/property_sets/property_set_model.rb', line 85

def self.extended(base)
  base.validate      :validate_format_of_name
  base.validate      :validate_length_of_serialized_data
  base.before_create :coerce_value
end

Instance Method Details

#default(key) ⇒ Object



100
101
102
# File 'lib/property_sets/property_set_model.rb', line 100

def default(key)
  @properties[key] && @properties[key].key?(:default) ? @properties[key][:default] : nil
end

#keysObject



96
97
98
# File 'lib/property_sets/property_set_model.rb', line 96

def keys
  @properties.keys
end

#owner_assocObject



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

def owner_assoc
  @owner_assoc
end

#owner_assoc=(association) ⇒ Object



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

def owner_assoc=(association)
  @owner_assoc = association
end

#owner_class=(owner_class) ⇒ Object



112
113
114
115
116
117
# File 'lib/property_sets/property_set_model.rb', line 112

def owner_class=(owner_class)
  @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
end

#owner_class_key_symObject



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

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

#owner_class_symObject



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

def owner_class_sym
  @owner_class_sym
end

#property(key, options = nil) ⇒ Object



91
92
93
94
# File 'lib/property_sets/property_set_model.rb', line 91

def property(key, options = nil)
  @properties ||= {}
  @properties[key] = options
end

#protected?(key) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/property_sets/property_set_model.rb', line 108

def protected?(key)
  @properties[key] && !!@properties[key][:protected]
end

#type(key) ⇒ Object



104
105
106
# File 'lib/property_sets/property_set_model.rb', line 104

def type(key)
  @properties[key] && @properties[key].key?(:type) ? @properties[key][:type] : :string
end