Module: Conjur::Policy::Types::InheritableAttribute
- Included in:
- Base
- Defined in:
- lib/conjur/policy/types/base.rb
Overview
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
Defined Under Namespace
Classes: Clone
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.inherit_for(klass, name, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/conjur/policy/types/base.rb', line 22 def self.inherit_for(klass, name, ={}) return unless klass.superclass.respond_to?(name) value = klass.superclass.send(name) # could be nil return value if [:clone] == false Clone.(value) # this could be dynamic, allowing other inheritance strategies. end |
Instance Method Details
#inheritable_attr(name, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/conjur/policy/types/base.rb', line 9 def inheritable_attr(name, ={}) instance_eval %Q{ def #{name}=(v) @#{name} = v end def #{name} return @#{name} if instance_variable_defined?(:@#{name}) @#{name} = InheritableAttribute.inherit_for(self, :#{name}, #{}) end } end |