Sha256: b8eae7de210e30d435ac1cf64ae6174cba4aba8e122405c9eb161873488b0b80
Contents?: true
Size: 928 Bytes
Versions: 2
Compression:
Stored size: 928 Bytes
Contents
module AssignableValues module ActiveRecord private def assignable_values_for(property, options = {}, &values) restriction_type = if belongs_to_association?(property) Restriction::BelongsToAssociation elsif store_accessor_attribute?(property) Restriction::StoreAccessorAttribute else Restriction::ScalarAttribute end restriction_type.new(self, property, options, &values) end def belongs_to_association?(property) reflection = reflect_on_association(property) reflection && reflection.macro == :belongs_to end def store_accessor_attribute?(property) store_identifier_of(property).present? end def store_identifier_of(property) stored_attributes.find { |_, attrs| attrs.include?(property.to_sym) }&.first end end end ActiveSupport.on_load(:active_record) do extend(AssignableValues::ActiveRecord) end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
assignable_values-1.1.1 | lib/assignable_values/active_record.rb |
assignable_values-1.1.0 | lib/assignable_values/active_record.rb |