Module: Worochi::Config
- Defined in:
- lib/worochi/configurator.rb
Overview
Configuration methods for loading and modifying options.
Class Attribute Summary collapse
-
.logdev ⇒ IO
Logging device.
-
.s3_bucket ⇒ String
Name of S3 bucket.
-
.s3_enabled ⇒ Boolean
(also: s3_enabled?)
Enables AWS S3 support.
-
.s3_prefix ⇒ String
Prefix for S3 resource paths.
-
.silent ⇒ Boolean
(also: silent?)
Disable debug and error messages if ‘true`.
Class Method Summary collapse
-
.enable_services(list) ⇒ Array<Symbol>
Only enable the list of services specified instead of all supported services.
-
.list_services ⇒ Array<Hashie::Mash>
Array of service meta information.
-
.load_yaml ⇒ nil
Loads options from YAML configuration files.
-
.reset_services ⇒ Array<Symbol>
Re-enable all supported services.
-
.service_display_name(arg) ⇒ String
Returns display name for the service.
-
.service_id(service) ⇒ Integer
Returns the service ID for the service, which can be used as a primary key for databases.
-
.service_name(id) ⇒ Symbol?
Returns the service name given the service ID.
-
.service_opts(service) ⇒ Hashie::Mash
Returns the service configurations that was loaded from YAML.
-
.services ⇒ Array<Symbol>
Array of service names.
Class Attribute Details
.logdev ⇒ IO
Logging device.
140 141 142 |
# File 'lib/worochi/configurator.rb', line 140 def logdev @logdev end |
.s3_bucket ⇒ String
Name of S3 bucket.
130 131 132 |
# File 'lib/worochi/configurator.rb', line 130 def s3_bucket @s3_bucket end |
.s3_enabled ⇒ Boolean Also known as: s3_enabled?
Enables AWS S3 support. AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID should be present in ENV.
125 126 127 |
# File 'lib/worochi/configurator.rb', line 125 def s3_enabled @s3_enabled end |
.s3_prefix ⇒ String
Prefix for S3 resource paths.
135 136 137 |
# File 'lib/worochi/configurator.rb', line 135 def s3_prefix @s3_prefix end |
.silent ⇒ Boolean Also known as: silent?
Disable debug and error messages if ‘true`.
145 146 147 |
# File 'lib/worochi/configurator.rb', line 145 def silent @silent end |
Class Method Details
.enable_services(list) ⇒ Array<Symbol>
Only enable the list of services specified instead of all supported services.
60 61 62 63 64 |
# File 'lib/worochi/configurator.rb', line 60 def enable_services(list) @all_services || services @services = @all_services.reject { |service| !list.include?(service) } @services.freeze end |
.list_services ⇒ Array<Hashie::Mash>
Array of service meta information.
46 47 48 49 50 51 52 53 54 |
# File 'lib/worochi/configurator.rb', line 46 def list_services services.map do |service| Hashie::Mash.new({ service: service, display_name: service_display_name(service), id: service_id(service) }) end end |
.load_yaml ⇒ nil
Loads options from YAML configuration files.
8 9 10 11 12 13 14 15 16 |
# File 'lib/worochi/configurator.rb', line 8 def load_yaml = {} services.each do |service| path = File.join(File.dirname(__FILE__), "config/#{service}.yml") raise Error, "Missing config for #{service}" unless File.file?(path) [service] = Hashie::Mash.new(YAML.load_file(path)) [service].service = service end end |
.reset_services ⇒ Array<Symbol>
Re-enable all supported services.
69 70 71 72 |
# File 'lib/worochi/configurator.rb', line 69 def reset_services @services || services @services = @all_services.clone end |
.service_display_name(service) ⇒ String .service_display_name(service_id) ⇒ String
Returns display name for the service.
81 82 83 84 85 86 87 88 89 |
# File 'lib/worochi/configurator.rb', line 81 def service_display_name(arg) service = arg.to_sym if arg.respond_to?(:to_sym) service = service_name(arg) unless .include?(service) if service.nil? nil else [service].display_name end end |
.service_id(service) ⇒ Integer
Returns the service ID for the service, which can be used as a primary key for databases.
96 97 98 99 100 101 102 |
# File 'lib/worochi/configurator.rb', line 96 def service_id(service) if [service.to_sym].nil? nil else [service.to_sym].id end end |
.service_name(id) ⇒ Symbol?
Returns the service name given the service ID.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/worochi/configurator.rb', line 109 def service_name(id) @service_names ||= {} return @service_names[id] if @service_names.include?(id) .each do |key, value| if value.id == id @service_names[value.id] = key return key end end nil end |
.service_opts(service) ⇒ Hashie::Mash
Returns the service configurations that was loaded from YAML.
21 22 23 24 25 26 |
# File 'lib/worochi/configurator.rb', line 21 def service_opts(service) if service.nil? || .nil? || [service].nil? raise Error, "Invalid service (#{service}) specified" end [service].clone end |
.services ⇒ Array<Symbol>
Array of service names. Parsed from the file names of any .yml file names in the worochi/config directory, excluding ones that contain the ‘#` character.
33 34 35 36 37 38 39 40 41 |
# File 'lib/worochi/configurator.rb', line 33 def services return @services if @services files = Dir[File.join(File.dirname(__FILE__), 'config/[^#]*.yml')] @services = files.map do |file| File.basename(file, '.yml').to_sym end @all_services = @services.clone.freeze @services.freeze end |