Method: RubySmart::SimpleLogger::Extensions::Scene::ClassMethods#scene

Defined in:
lib/ruby_smart/simple_logger/extensions/scene.rb

#scene(key, opts = {}, &block) ⇒ Boolean

registers a new scene by provided key & options also defines this method by provided block

Examples:

scene :line, { level: :debug } do |data, opts = {}|
  self.log data, _scene_opt(:line, opts)
end

Parameters:

  • key (Symbol)
    • name of the scene method
  • opts (Hash) (defaults to: {})
    • scene default options
  • block (Proc)
    • scene block to define a appropriate method

Returns:

  • (Boolean)

    created result



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ruby_smart/simple_logger/extensions/scene.rb', line 49

def scene(key, opts = {}, &block)
  # protect overwrite existing methods
  # but allow all severities (levels)
  return false if instance_methods.include?(key) && !self::LEVEL.key?(key)

  # register scene default options
  self.scenes[key] = opts

  # define (or overwrite) this method, if a block was provided
  define_method(key, &block) if block_given?

  # returns success result
  true
end