Sha256: 5b30e6b7967976713d5979ac74bc0602f355809f1677eafd18a30124d0b8dd0a

Contents?: true

Size: 966 Bytes

Versions: 2

Compression:

Stored size: 966 Bytes

Contents

require 'active_model'

module ActiveModel::AttributeMethods
  module ClassMethods
    def remove_proxy_call(mod, name)
      defn = if NAME_COMPILABLE_REGEXP.match?(name)
               "undef #{name}"
             else
               "remove_method(:'#{name}')"
             end

      mod.module_eval defn, __FILE__, __LINE__ + 1
    end

    def remove_alias_attribute(new_name)
      # association_scope -> add_constraints -> last_chain_scope -> where!(key => model[foreign_key])
      # self[attr_name] -> read_attribute(attr_name) -> attribute_aliases
      # where! -> where_clause_factory.build -> attributes = predicate_builder.resolve_column_aliases(opts) -> attribute_aliases
      self.attribute_aliases = attribute_aliases.except(new_name.to_s)

      attribute_method_matchers.each do |matcher|
        matcher_new = matcher.method_name(new_name).to_s
        remove_proxy_call self, matcher_new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adaptive_alias-0.0.3 lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb
adaptive_alias-0.0.1 lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb