Module: Worochi::Config

Defined in:
lib/worochi/configurator.rb

Overview

Configuration methods for loading and modifying options.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.logdevIO

Logging device.

Returns:

  • (IO)

140
141
142
# File 'lib/worochi/configurator.rb', line 140

def logdev
  @logdev
end

.s3_bucketString

Name of S3 bucket.

Returns:

  • (String)

130
131
132
# File 'lib/worochi/configurator.rb', line 130

def s3_bucket
  @s3_bucket
end

.s3_enabledBoolean Also known as: s3_enabled?

Enables AWS S3 support. AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID should be present in ENV.

Returns:

  • (Boolean)

125
126
127
# File 'lib/worochi/configurator.rb', line 125

def s3_enabled
  @s3_enabled
end

.s3_prefixString

Prefix for S3 resource paths.

Returns:

  • (String)

135
136
137
# File 'lib/worochi/configurator.rb', line 135

def s3_prefix
  @s3_prefix
end

.silentBoolean Also known as: silent?

Disable debug and error messages if `true`.

Returns:

  • (Boolean)

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.

Returns:

  • (Array<Symbol>)

    enabled 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_servicesArray<Hashie::Mash>

Array of service meta information.

Returns:

  • (Array<Hashie::Mash>)

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_yamlnil

Loads options from YAML configuration files.

Returns:

  • (nil)

8
9
10
11
12
13
14
15
16
# File 'lib/worochi/configurator.rb', line 8

def load_yaml
  @options = {}
  services.each do |service|
    path = File.join(File.dirname(__FILE__), "config/#{service}.yml")
    raise Error, "Missing config for #{service}" unless File.file?(path)
    @options[service] = Hashie::Mash.new(YAML.load_file(path))
    @options[service].service = service
  end
end

.reset_servicesArray<Symbol>

Re-enable all supported services.

Returns:

  • (Array<Symbol>)

    enabled 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.

Overloads:

  • .service_display_name(service) ⇒ String

    Parameters:

    • service (Symbol)
  • .service_display_name(service_id) ⇒ String

    Parameters:

    • service_id (Integer)

Returns:

  • (String)

    display name


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 @options.include?(service)
  if service.nil?
    nil
  else
    @options[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.

Parameters:

  • service (Symbol)

Returns:

  • (Integer)

    service ID


96
97
98
99
100
101
102
# File 'lib/worochi/configurator.rb', line 96

def service_id(service)
  if @options[service.to_sym].nil?
    nil
  else
    @options[service.to_sym].id
  end
end

.service_name(id) ⇒ Symbol?

Returns the service name given the service ID.

Parameters:

  • id (Integer)

Returns:

  • (Symbol)

    if service exists

  • (nil)

    if service does not exist


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)
  @options.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.

Returns:

  • (Hashie::Mash)

21
22
23
24
25
26
# File 'lib/worochi/configurator.rb', line 21

def service_opts(service)
  if service.nil? || @options.nil? || @options[service].nil?
    raise Error, "Invalid service (#{service}) specified"
  end
  @options[service].clone
end

.servicesArray<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.

Returns:

  • (Array<Symbol>)

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