Module: RubySmart::SimpleLogger::Extensions::Scene::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#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

[View source]

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

#scene?(key) ⇒ Boolean

returns true, if provided key is a registered scene option

Parameters:

  • key (Symbol)

Returns:

  • (Boolean)
[View source]

33
34
35
# File 'lib/ruby_smart/simple_logger/extensions/scene.rb', line 33

def scene?(key)
  scenes.key?(key)
end

#scenesHash

returns all registered scene default options

Returns:

  • (Hash)

    scenes

[View source]

20
21
22
# File 'lib/ruby_smart/simple_logger/extensions/scene.rb', line 20

def scenes
  class_variable_get('@@scenes')
end

#scenes=(scenes) ⇒ Object

sets scene options

Parameters:

  • scenes (Hash)
[View source]

26
27
28
# File 'lib/ruby_smart/simple_logger/extensions/scene.rb', line 26

def scenes=(scenes)
  class_variable_set('@@scenes', scenes)
end