module Wardrobe::ClassMethods
Public Class Methods
extended(base)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 10 def self.extended(base) wardrobe_methods = base.instance_variable_set(:@wardrobe_methods, Module.new) base.include(wardrobe_methods) base.instance_variable_set(:@wardrobe_stores, Stores.new) end
Public Instance Methods
attribute(name, klass, *args, &blk)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 83 def attribute(name, klass, *args, &blk) merged_args = option_store.defaults.merge(args.inject({}) { |input, val| input.merge! val }) @wardrobe_stores = wardrobe_stores.add_attribute( name, klass, self, **merged_args, &blk ) define_getter(attribute_store[name]) define_setter(attribute_store[name]) end
attributes(**kargs, &blk)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 92 def attributes(**kargs, &blk) BlockSetup.new(self).run(**kargs, &blk) end
default_getters()
click to toggle source
# File lib/wardrobe/class_methods.rb, line 46 def default_getters [ Wardrobe.getters[:getter] ] end
default_setters()
click to toggle source
# File lib/wardrobe/class_methods.rb, line 52 def default_setters [ Wardrobe.setters[:setter] ] end
define_getter(atr)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 62 def define_getter(atr) @wardrobe_methods.instance_exec do define_method(atr.name) do atr.getters.inject(nil) do |val, getter| getter.block.call(val, atr, self) end end end end
define_setter(atr)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 72 def define_setter(atr) @wardrobe_methods.instance_exec do define_method(atr.setter_name) do |input| atr.setters.inject(input) do |val, setter| setter.block.call(val, atr, self) end end end end
included(base)
click to toggle source
This is called when included in another module/class
# File lib/wardrobe/class_methods.rb, line 17 def included(base) base.include(Wardrobe) unless base.respond_to? :wardrobe_stores base.merge(wardrobe_stores) end
inherited(child)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 22 def inherited(child) wardrobe_methods = child.instance_variable_set(:@wardrobe_methods, Module.new) child.include(wardrobe_methods) child.instance_variable_set(:@wardrobe_stores, Stores.new) child.merge(wardrobe_stores) child.root_config = root_config end
merge(config)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 58 def merge(config) @wardrobe_stores = wardrobe_stores.merge(config, self) end
plugin(name, **args)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 104 def plugin(name, **args) @wardrobe_stores = wardrobe_stores.enable_plugin(name, **args) plugin = plugin_store[name][:klass] if plugin.const_defined?(:ClassMethods) extend(plugin.const_get(:ClassMethods)) end if plugin.const_defined?(:InstanceMethods) include(plugin.const_get(:InstanceMethods)) end # Currently these are not needed # # if plugin.const_defined?(:AttributeClassMethods) # Attribute.extend(plugin.const_get(:AttributeClassMethods)) # end # # if plugin.const_defined?(:AttributeInstanceMethods) # Attribute.include(plugin.const_get(:AttributeInstanceMethods)) # end end
remove_attributes(*wardrobe)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 96 def remove_attributes(*wardrobe) wardrobe.each do |name| @wardrobe_stores = wardrobe_stores.remove_attribute(name) end end
Also aliased as: remove_attribute
root_config()
click to toggle source
# File lib/wardrobe/class_methods.rb, line 42 def root_config @root_config if instance_variable_defined?(:@root_config) end
root_config=(input)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 38 def root_config=(input) @root_config = input end
wardrobe_stores(&blk)
click to toggle source
# File lib/wardrobe/class_methods.rb, line 30 def wardrobe_stores(&blk) if block_given? @wardrobe_stores = wardrobe_stores.update(&blk) else @wardrobe_stores end end