Class: Translatomatic::Config::Selector

Inherits:
Object
  • Object
show all
Includes:
TypeCast
Defined in:
lib/translatomatic/config/selector.rb

Overview

Selects which set of config settings to use

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings, default_location, params = {}) ⇒ Selector

Returns a new instance of Selector.



8
9
10
11
12
13
# File 'lib/translatomatic/config/selector.rb', line 8

def initialize(settings, default_location, params = {})
  @settings = settings
  @for_file = params[:for_file]
  @location = params[:location]
  @default_location = default_location
end

Instance Attribute Details

#for_fileObject (readonly)

Returns the value of attribute for_file.



5
6
7
# File 'lib/translatomatic/config/selector.rb', line 5

def for_file
  @for_file
end

#locationObject (readonly)

Returns the value of attribute location.



6
7
8
# File 'lib/translatomatic/config/selector.rb', line 6

def location
  @location
end

Instance Method Details

#settings_for_read(key) ⇒ LocationSettings

Find a settings object for reading the specified option

Parameters:

  • key (Symbol)

    Option name

Returns:



18
19
20
21
22
23
24
25
26
27
# File 'lib/translatomatic/config/selector.rb', line 18

def settings_for_read(key)
  if location.nil?
    # no location, find first settings for key according to precedence
    settings_with_precedence(key)
  else
    # location is set
    check_valid_location
    location_settings_for_read(key, location)
  end
end

#settings_for_write(key) ⇒ LocationSettings

Find a settings object for writing the specified option

Parameters:

  • key (Symbol)

    Option name

Returns:



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/translatomatic/config/selector.rb', line 32

def settings_for_write(key)
  effective = effective_location(key, location)
  settings = @settings[effective]
  if for_file
    path = file(settings)
    data = settings.files[path.to_s.to_sym] ||= {}
    file_location_settings(settings, data)
  else
    settings
  end
end