lib/immoscout/models/concerns/propertiable.rb in immoscout-1.3.2 vs lib/immoscout/models/concerns/propertiable.rb in immoscout-1.4.0

- old
+ new

@@ -1,10 +1,12 @@ # frozen_string_literal: true module Immoscout module Models module Concerns + # Includes functionality to access and modify + # model attributes transparently. module Propertiable extend ActiveSupport::Concern included do cattr_reader :properties, instance_accessor: false do @@ -12,11 +14,11 @@ end # :reek:ControlParameter - standard stuff, reek! # :reek:TooManyStatements def method_missing(method_name, *arguments, &block) - if method_name =~ /build\_(\w+)/ + if method_name =~ /build_(\w+)/ match = Regexp.last_match(1).intern properties = self.class.properties coerce_klass = properties.fetch(match).fetch(:coerce, nil) return super if !properties.key?(match) || !coerce_klass @@ -37,9 +39,10 @@ end class_methods do def property(name, **opts) attr_accessor(name) + alias_name = opts.fetch(:alias, false) if alias_name alias_method alias_name, name alias_method "#{opts.fetch(:alias)}=", "#{name}=" end