Class: Yapra::Config
- Inherits:
-
Object
- Object
- Yapra::Config
- Defined in:
- lib/yapra/config.rb
Overview
Config Examples
Config file for yapra.
Format 1: Pragger like.
A simplest. You can run one pipeline without global config.
- module: Module:name
config:
a: 3
- module: Module:name2
config:
a: b
- module: Module:name3
config:
a: 88
Format 2: Python habu like.
You can run a lot of pipelines with global config.
global:
log:
out: stderr
level: warn
pipeline:
pipeline1:
- module: Module:name
config:
a: 3
- module: Module:name2
config:
a: b
pipeline2:
- module: Module:name
config:
a: 3
- module: Module:name2
config:
a: b
Format 3: Mixed type.
You can run sigle pipeline with global config.
global:
log:
out: stderr
level: warn
pipeline:
- module: Module:name
config:
a: 3
- module: Module:name2
config:
a: b
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#pipeline_commands ⇒ Object
readonly
Returns the value of attribute pipeline_commands.
Instance Method Summary collapse
- #create_logger ⇒ Object
-
#initialize(config = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(config = {}) ⇒ Config
Returns a new instance of Config.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/yapra/config.rb', line 66 def initialize config={} if config.kind_of?(Hash) @env = config['global'] || {} if config['pipeline'] if config['pipeline'].kind_of?(Hash) @pipeline_commands = config['pipeline'] elsif config['pipeline'].kind_of?(Array) @pipeline_commands = { 'default' => config['pipeline'] } end end raise 'config["global"]["pipeline"] is invalid!' unless @pipeline_commands elsif config.kind_of?(Array) @env = {} @pipeline_commands = { 'default' => config } else raise 'config file is invalid!' end end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
63 64 65 |
# File 'lib/yapra/config.rb', line 63 def env @env end |
#pipeline_commands ⇒ Object (readonly)
Returns the value of attribute pipeline_commands.
64 65 66 |
# File 'lib/yapra/config.rb', line 64 def pipeline_commands @pipeline_commands end |
Instance Method Details
#create_logger ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/yapra/config.rb', line 85 def create_logger logger = nil if env['log'] && env['log']['out'] if env['log']['out'].index('file://') logger = Logger.new(URI.parse(env['log']['out']).path) else logger = Logger.new(Yapra::Inflector.constantize(env['log']['out'].upcase)) end else logger = Logger.new(STDOUT) end if env['log'] && env['log']['level'] logger.level = Yapra::Inflector.constantize("Logger::#{env['log']['level'].upcase}") else logger.level = Logger::WARN end logger end |