class Class
Constants
- EMPTY_INHERITABLE_ATTRIBUTES
Prevent this constant from being created multiple times
Public Instance Methods
class_inheritable_accessor(*syms)
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 57 def class_inheritable_accessor(*syms) class_inheritable_reader(*syms) class_inheritable_writer(*syms) end
class_inheritable_reader(*syms)
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 25 def class_inheritable_reader(*syms) syms.each do |sym| next if sym.is_a?(Hash) class_eval <<-EOS def self.#{sym} # def self.before_add_for_comments read_inheritable_attribute(:#{sym}) # read_inheritable_attribute(:before_add_for_comments) end # end # def #{sym} # def before_add_for_comments self.class.#{sym} # self.class.before_add_for_comments end # end EOS end end
class_inheritable_writer(*syms)
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 40 def class_inheritable_writer(*syms) options = syms.extract_options! syms.each do |sym| class_eval <<-EOS def self.#{sym}=(obj) # def self.color=(obj) write_inheritable_attribute(:#{sym}, obj) # write_inheritable_attribute(:color, obj) end # end # #{" # def #{sym}=(obj) # def color=(obj) self.class.#{sym} = obj # self.class.color = obj end # end " unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false EOS end end
inheritable_attributes()
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 62 def inheritable_attributes @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES end
read_inheritable_attribute(key)
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 73 def read_inheritable_attribute(key) inheritable_attributes[key] end
reset_inheritable_attributes()
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 77 def reset_inheritable_attributes @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES end
write_inheritable_attribute(key, value)
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 66 def write_inheritable_attribute(key, value) if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES) @inheritable_attributes = {} end inheritable_attributes[key] = value end
Private Instance Methods
inherited(child)
Also aliased as: inherited_without_inheritable_attributes
Alias for: inherited_with_inheritable_attributes
inherited_with_inheritable_attributes(child)
click to toggle source
# File lib/shadow_puppet/core_ext.rb, line 85 def inherited_with_inheritable_attributes(child) inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes) if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES) new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES else new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)| memo.update(key => value.duplicable? ? value.dup : value) end end child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes) end
Also aliased as: inherited