Class: Daemons::Rails::Config
- Inherits:
-
Object
- Object
- Daemons::Rails::Config
- Defined in:
- lib/daemons/rails/config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(app_name, root_path, daemons_dir = File.join('lib', 'daemons')) ⇒ Config
constructor
A new instance of Config.
- #to_hash ⇒ Object
Constructor Details
#initialize(app_name, root_path, daemons_dir = File.join('lib', 'daemons')) ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 16 17 18 |
# File 'lib/daemons/rails/config.rb', line 10 def initialize(app_name, root_path, daemons_dir = File.join('lib', 'daemons')) @options = {} config_path = File.join(root_path, "config", "#{app_name}-daemon.yml") config_path = File.join(root_path, "config", "daemons.yml") unless File.exist?(config_path) = YAML.load(ERB.new(IO.read(config_path)).result) .each { |key, value| @options[key.to_sym] = value } @options[:dir_mode] = @options[:dir_mode].to_sym @options[:script] ||= File.join(root_path, daemons_dir, "#{app_name}.rb") end |
Class Method Details
.for_controller(controller_path, root = Daemons::Rails.configuration.root) ⇒ Object
20 21 22 |
# File 'lib/daemons/rails/config.rb', line 20 def self.for_controller(controller_path, root = Daemons::Rails.configuration.root) new(File.basename(controller_path, '_ctl'), root, Pathname.new(controller_path).parent.relative_path_from(root)) end |
Instance Method Details
#[](key) ⇒ Object
24 25 26 |
# File 'lib/daemons/rails/config.rb', line 24 def [](key) @options[key] end |
#[]=(key, value) ⇒ Object
28 29 30 |
# File 'lib/daemons/rails/config.rb', line 28 def []=(key, value) @options[key] = value end |
#to_hash ⇒ Object
32 33 34 |
# File 'lib/daemons/rails/config.rb', line 32 def to_hash @options end |