Module: Wardrobe::ModuleMethods
- Included in:
- Wardrobe
- Defined in:
- lib/wardrobe/module_methods.rb
Overview
This module is extended in Wardrobe and extended to anonymous modules created by Wardrobe() method.
Instance Method Summary collapse
- #config ⇒ Object
- #configure(&blk) ⇒ Object
- #create_class(plugins: [], attributes: []) ⇒ Object
- #included(base) ⇒ Object
- #logger ⇒ Object
Instance Method Details
#config ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wardrobe/module_methods.rb', line 32 def config @config ||= begin callee = caller_locations.first if callee.label == 'config' && callee.lineno == (__LINE__ + 3) RootConfig.new else Wardrobe.config end end end |
#configure(&blk) ⇒ Object
43 44 45 |
# File 'lib/wardrobe/module_methods.rb', line 43 def configure(&blk) @config = config.mutate(&blk) end |
#create_class(plugins: [], attributes: []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wardrobe/module_methods.rb', line 21 def create_class(plugins: [], attributes: []) Class.new.class_exec do include Wardrobe plugin(*plugins) attributes.each do |atr| attribute(atr[:name], const_get(atr[:class]), atr.fetch(:options, {})) end self end end |
#included(base) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wardrobe/module_methods.rb', line 9 def included(base) base.extend(ClassMethods) unless base.to_s == 'Wardrobe::RootConfig' base.root_config = config config.default_plugins.each do |plugin| # TODO: Support k_args base.plugin plugin end end base.include(InstanceMethods) end |
#logger ⇒ Object
47 48 49 |
# File 'lib/wardrobe/module_methods.rb', line 47 def logger config.logger end |