Module: MethodFound::AttributeMethods
- Defined in:
- lib/method_found/attribute_methods.rb
Overview
Re-implementation of ActiveModel::AttributeMethods from Rails using Interceptor modules instead of class variables.
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/method_found/attribute_methods.rb', line 50 def self.included(base) base.include(AttributeInterceptor.new) base.instance_eval do def attribute_method_prefix(*prefixes) prefixes.each { |prefix| include AttributeInterceptor.new(prefix: prefix) } end def attribute_method_suffix(*suffixes) suffixes.each { |suffix| include AttributeInterceptor.new(suffix: suffix) } end def attribute_method_affix(*affixes) affixes.each { |affix| include AttributeInterceptor.new(prefix: affix[:prefix], suffix: affix[:suffix]) } end def define_attribute_methods(*attr_names) ancestors.each do |ancestor| ancestor.define_attribute_methods(*attr_names) if ancestor.is_a?(AttributeInterceptor) end end def alias_attribute(new_name, old_name) ancestors.each do |ancestor| ancestor.alias_attribute(new_name, old_name) if ancestor.is_a?(AttributeInterceptor) end end end end |