Class: Translatomatic::Config::Selector
- Inherits:
-
Object
- Object
- Translatomatic::Config::Selector
- Includes:
- TypeCast
- Defined in:
- lib/translatomatic/config/selector.rb
Overview
Selects which set of config settings to use
Instance Attribute Summary collapse
-
#for_file ⇒ Object
readonly
Returns the value of attribute for_file.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
-
#initialize(settings, default_location, params = {}) ⇒ Selector
constructor
A new instance of Selector.
-
#settings_for_read(key) ⇒ LocationSettings
Find a settings object for reading the specified option.
-
#settings_for_write(key) ⇒ LocationSettings
Find a settings object for writing the specified option.
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_file ⇒ Object (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 |
#location ⇒ Object (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
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
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 |