Sha256: b907a505b641867ada38e4e0afcd344b3d9b45b9557f25838c28412fdd6ac905

Contents?: true

Size: 776 Bytes

Versions: 1

Compression:

Stored size: 776 Bytes

Contents

module Axel
  module CascadableAttribute
    def inherited(klass)
      super
      _cascadable_attributes.each do |attribute_name|
        klass.instance_variable_set "@#{attribute_name}", _instance_var_for("@#{attribute_name}")
      end
    end

    def cascade_attribute(*attribute_names)
      self._cascadable_attributes += attribute_names.map(&:to_s)
    end

    def _cascadable_attributes
      @_cascadable_attributes ||= ["_cascadable_attributes"]
    end

    def _cascadable_attributes=(arry)
      @_cascadable_attributes = arry
    end

    def _instance_var_for(attribute_name)
      attribute = instance_variable_get(attribute_name)
      attribute.clone
    rescue
      begin
        attribute.dup
      rescue
        attribute
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axel-0.0.1 lib/axel/cascadable_attribute.rb