Module: Kungfuig
- Defined in:
- lib/kungfuig.rb,
lib/kungfuig/color.rb,
lib/kungfuig/jobber.rb,
lib/kungfuig/version.rb,
lib/kungfuig/aspector.rb,
lib/kungfuig/prepender.rb
Defined Under Namespace
Modules: Aspector, ClassMethods, InstanceMethods, I★I Classes: Color, Jobber, Prepender
Constant Summary collapse
- MX =
Mutex.new
- VERSION =
"0.6.1"- LAMBDA =
lambda do |λ, e, **hash| begin Kungfuig::Prepender.error! e, **hash λ[:on_error].call(e, **hash) if λ[:on_error] rescue => e Kungfuig::Prepender.error! e, reason: :on_error end end
Class Method Summary collapse
- .extended(base) ⇒ Object
- .included(base) ⇒ Object
-
.load_stuff(hos) ⇒ Object
rubocop:enable Style/MethodName.
-
.✍(receiver: nil, method: nil, result: nil, args: nil, **params) ⇒ Object
rubocop:disable Style/MethodName.
Class Method Details
.extended(base) ⇒ Object
121 122 123 |
# File 'lib/kungfuig.rb', line 121 def self.extended base base.include ClassMethods end |
.included(base) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/kungfuig.rb', line 112 def self.included base base.include InstanceMethods base.extend ClassMethods if (base.instance_methods & [:[], :[]=]).empty? base.send :alias_method, :[], :option base.send :alias_method, :[]=, :option! end end |
.load_stuff(hos) ⇒ Object
rubocop:enable Style/MethodName
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kungfuig.rb', line 24 def load_stuff hos case hos when NilClass then Hashie::Mash.new # aka skip when Hash then Hashie::Mash.new(hos) when String begin File.exist?(hos) ? Hashie::Mash.load(hos) : Hashie::Mash.new(YAML.load(hos)) rescue ArgumentError fail ArgumentError, "#{__callee__} expects valid YAML configuration file. “#{hos.inspect}” contains invalid syntax." rescue Psych::SyntaxError fail ArgumentError, "#{__callee__} expects valid YAML configuration string. Got:\n#{hos.inspect}" rescue fail ArgumentError, "#{__callee__} expects valid YAML configuration string (misspelled file name?). Got:\n#{hos.inspect}" end when ->(h) { h.respond_to?(:to_hash) } then Hashie::Mash.new(h.to_hash) else fail ArgumentError.new "#{__callee__} accepts either String or Hash as parameter." end end |
.✍(receiver: nil, method: nil, result: nil, args: nil, **params) ⇒ Object
rubocop:disable Style/MethodName
13 14 15 16 17 18 19 20 |
# File 'lib/kungfuig.rb', line 13 def ✍(receiver: nil, method: nil, result: nil, args: nil, **params) require 'logger' @✍ ||= Kernel.const_defined?('Rails') && Rails.logger || Logger.new($stdout) = receiver.is_a?(String) ? "#{receiver} | #{method}" : "#{receiver.class}##{method}" "#{Color.to_xterm256(, :info)} called with «#{Color.to_xterm256(args.inspect, :success)}» and returned «#{result || 'nothing (was it before aspect?)'}»".tap do |m| @✍.debug m end end |