Skip to content

Commit

Permalink
Rename defined_property_attributes to property_attributes.
Browse files Browse the repository at this point in the history
Same change to associations and methods.
  • Loading branch information
lfu committed Sep 27, 2016
1 parent f98a4e5 commit e311d9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/models/generic_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class GenericObject < ApplicationRecord
delegate :property_attribute_defined?,
:property_defined?,
:type_cast,
:defined_property_associations, :property_association_defined?,
:defined_property_methods, :property_method_defined?,
:property_associations, :property_association_defined?,
:property_methods, :property_method_defined?,
:to => :generic_object_definition, :allow_nil => true

def initialize(attributes = {})
Expand Down Expand Up @@ -41,8 +41,8 @@ def inspect
end

attributes_as_string += ["attributes: #{property_attributes}"]
attributes_as_string += ["associations: #{defined_property_associations.keys}"]
attributes_as_string += ["methods: #{defined_property_methods}"]
attributes_as_string += ["associations: #{property_associations.keys}"]
attributes_as_string += ["methods: #{property_methods}"]

prefix = Kernel.instance_method(:inspect).bind(self).call.split(' ', 2).first
"#{prefix} #{attributes_as_string.join(", ")}>"
Expand Down Expand Up @@ -89,7 +89,7 @@ def property_setter(name, value)
type_cast(name, value)
elsif property_association_defined?(name)
# property association is of multiple values
value.select { |v| v.kind_of?(defined_property_associations[name].constantize) }.uniq.map(&:id)
value.select { |v| v.kind_of?(property_associations[name].constantize) }.uniq.map(&:id)
end

self.properties = properties.merge(name => val)
Expand Down
11 changes: 6 additions & 5 deletions app/models/generic_object_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ def create_object(options)
end

FEATURES.each do |feature|
define_method("defined_property_#{feature}s") do
define_method("property_#{feature}s") do
return errors[:properties] if properties_changed? && !valid?
properties["#{feature}s".to_sym]
end

define_method("property_#{feature}_defined?") do |attr|
return defined_property_methods.include?(attr.to_s) if feature == 'method'
send("defined_property_#{feature}s").try(:key?, attr.to_s)
attr = attr.to_s
return property_methods.include?(attr) if feature == 'method'
send("property_#{feature}s").key?(attr)
end
end

Expand All @@ -53,7 +54,7 @@ def property_getter(attr, val)
end

def type_cast(attr, value)
TYPE_MAP.fetch(defined_property_attributes[attr]).cast(value)
TYPE_MAP.fetch(property_attributes[attr]).cast(value)
end

def properties=(props)
Expand All @@ -64,7 +65,7 @@ def properties=(props)
private

def get_associations(attr, values)
defined_property_associations[attr].constantize.where(:id => values).to_a
property_associations[attr].constantize.where(:id => values).to_a
end

def normalize_property_attributes
Expand Down

0 comments on commit e311d9a

Please sign in to comment.