Module: Usable
- Defined in:
- lib/usable.rb,
lib/usable/config.rb,
lib/usable/version.rb,
lib/usable/config_multi.rb,
lib/usable/mod_extender.rb,
lib/usable/config_register.rb
Defined Under Namespace
Modules: ConfigMulti, ConfigRegister Classes: Config, ModExtender
Constant Summary collapse
- VERSION =
"2.2.1".freeze
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#usable(mod, options = {}, &block) ⇒ Object
Self.
-
#usable_method(context, method_name) ⇒ Method
Bound to the given -context-.
Instance Attribute Details
Class Method Details
.extended(base) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/usable.rb', line 9 def self.extended(base) base.class_eval do def usable_method(method_name) self.class.usable_method(self, method_name) end end if base.is_a? Class # Define an instance level version of +usables+ base.class_eval do def usables self.class.usables end end else base.instance_eval do def config(&block) usables(&block) end unless defined? config end end end |
Instance Method Details
#usable(mod, options = {}, &block) ⇒ Object
Note:
Hides methods
Returns self.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/usable.rb', line 57 def usable(mod, = {}, &block) ModExtender.new(mod, only: .delete(:only), method: .delete(:method)).call self # Define settings on @usables and on the scoped @usables scope = Config.new if mod.name scope_name = mod.name.split('::').last.gsub(/\B([A-Z])([a-z_0-9])/, '_\1\2').downcase usables[scope_name] = scope end if mod.respond_to? :usables scope += mod.usables self.usables += mod.usables end # any left over -options- are considered "config" settings if [scope, usables].each { |x| .each { |k, v| x[k] = v } } end if block_given? [scope, usables].each { |x| x.instance_eval &block } end if mod.const_defined?(:InstanceMethods) send :include, mod.const_get(:InstanceMethods) end if mod.const_defined?(:ClassMethods) send :extend, mod.const_get(:ClassMethods) end self end |
#usable_method(context, method_name) ⇒ Method
Returns bound to the given -context-.
86 87 88 |
# File 'lib/usable.rb', line 86 def usable_method(context, method_name) usables.available_methods[method_name].bind(context) end |