module Conjur::DSL2::Types::InheritableAttribute

An inheritable class attribute which is cloned by subclasses so the attribute can be a mutable thing such as a Hash.

raw.githubusercontent.com/apotonick/uber/master/lib/uber/inheritable_attr.rb

Public Class Methods

inherit_for(klass, name, options={}) click to toggle source
# File lib/conjur/dsl2/types/base.rb, line 22
def self.inherit_for(klass, name, options={})
  return unless klass.superclass.respond_to?(name)
    
  value = klass.superclass.send(name) # could be nil
    
  return value if options[:clone] == false
  Clone.(value) # this could be dynamic, allowing other inheritance strategies.
end

Public Instance Methods

inheritable_attr(name, options={}) click to toggle source
# File lib/conjur/dsl2/types/base.rb, line 9
def inheritable_attr(name, options={})
  instance_eval %Q{
    def #{name}=(v)
      @#{name} = v
    end
    
    def #{name}
      return @#{name} if instance_variable_defined?(:@#{name})
      @#{name} = InheritableAttribute.inherit_for(self, :#{name}, #{options})
    end
  }
end