Module: PropertySets
- Defined in:
- lib/property_sets.rb,
lib/property_sets/casting.rb,
lib/property_sets/version.rb,
lib/property_sets/delegator.rb,
lib/property_sets/property_set_model.rb,
lib/property_sets/active_record_extension.rb
Defined Under Namespace
Modules: ActiveRecordExtension, Casting, Delegator, PropertySetModel
Constant Summary
collapse
- VERSION =
"3.13.0"
Class Method Summary
collapse
Class Method Details
.ensure_property_set_class(association, owner_class_name) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/property_sets.rb', line 15
def self.ensure_property_set_class(association, owner_class_name)
const_name = "#{owner_class_name.demodulize}#{association.to_s.singularize.camelcase}"
namespace = owner_class_name.deconstantize.safe_constantize || Object
unless namespace.const_defined?(const_name, false)
property_class = Class.new(parent_for_property_class(namespace, owner_class_name)) do
include PropertySets::PropertySetModel::InstanceMethods
extend PropertySets::PropertySetModel::ClassMethods
end
namespace.const_set(const_name, property_class)
property_class.owner_class = owner_class_name
property_class.owner_assoc = association
end
namespace.const_get(const_name.to_s)
end
|
.parent_for_property_class(namespace, owner_class_name) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/property_sets.rb', line 34
def self.parent_for_property_class(namespace, owner_class_name)
owner_class = namespace.const_get(owner_class_name)
owner_class.property_sets_connection_class || owner_class.connection_class_for_self
rescue NameError
::ActiveRecord::Base
end
|