Class: Woro::Configuration
- Inherits:
-
Object
- Object
- Woro::Configuration
- Defined in:
- lib/woro/configuration.rb
Instance Attribute Summary collapse
-
#adapter_settings ⇒ Object
readonly
Returns the value of attribute adapter_settings.
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#woro_task_dir ⇒ Object
readonly
Returns the value of attribute woro_task_dir.
Class Method Summary collapse
-
.config_file ⇒ Object
Helpers.
- .default_options ⇒ Object
-
.load(options = {}) ⇒ Object
Load configuration file or default_options.
- .rake_task_dir ⇒ Object
-
.save(options = {}) ⇒ Object
Save configuration.
- .woro_task_dir ⇒ Object
Instance Method Summary collapse
- #adapter(adapter_name) ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
Initialize configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Initialize configuration.
10 11 12 13 14 |
# File 'lib/woro/configuration.rb', line 10 def initialize( = {}) @woro_task_dir = Configuration.woro_task_dir @adapter_settings = ['adapters'] || {} @app_name = ['app_name'] end |
Instance Attribute Details
#adapter_settings ⇒ Object (readonly)
Returns the value of attribute adapter_settings.
7 8 9 |
# File 'lib/woro/configuration.rb', line 7 def adapter_settings @adapter_settings end |
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
7 8 9 |
# File 'lib/woro/configuration.rb', line 7 def app_name @app_name end |
#woro_task_dir ⇒ Object (readonly)
Returns the value of attribute woro_task_dir.
7 8 9 |
# File 'lib/woro/configuration.rb', line 7 def woro_task_dir @woro_task_dir end |
Class Method Details
.config_file ⇒ Object
Helpers
52 53 54 |
# File 'lib/woro/configuration.rb', line 52 def self.config_file File.join('config', 'woro.yml') end |
.default_options ⇒ Object
64 65 66 67 |
# File 'lib/woro/configuration.rb', line 64 def self. { } end |
.load(options = {}) ⇒ Object
Load configuration file or default_options. Passed options take precedence.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/woro/configuration.rb', line 17 def self.load( = {}) = .reject { |k, v| !['adapters', 'app_name'].include? k } unless File.exist? config_file File.open(config_file, 'w') { |file| YAML.dump(, file) } say "Initialized default config file in `#{config_file}`. See 'woro help init' for options." end = YAML.load_file(config_file) new(.merge()) end |
.rake_task_dir ⇒ Object
60 61 62 |
# File 'lib/woro/configuration.rb', line 60 def self.rake_task_dir File.join('lib', 'tasks') end |
.save(options = {}) ⇒ Object
Save configuration. Passed options take precendence over default_options.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/woro/configuration.rb', line 30 def self.save( = {}) = .reject { |k, v| !['adapters', 'app_name'].include? k } force_save = .delete :force if !File.exist?(config_file) || force_save File.open(config_file, 'w') do |file| YAML.dump(.merge(), file) end say "Initialized config file in `#{config_file}`" else say_error "Not overwriting existing config file `#{config_file}`, use --force to override. See 'woro help init'." end self end |
.woro_task_dir ⇒ Object
56 57 58 |
# File 'lib/woro/configuration.rb', line 56 def self.woro_task_dir File.join('lib', 'woro_tasks') end |
Instance Method Details
#adapter(adapter_name) ⇒ Object
45 46 47 48 |
# File 'lib/woro/configuration.rb', line 45 def adapter(adapter_name) clazz = Object.const_get("Woro::Adapters::#{adapter_name.capitalize}") clazz.new adapter_settings[adapter_name.downcase] end |