Class: SourcedConfig::Locale::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/sourced_config/locale/loader.rb

Constant Summary collapse

COPY_SOURCE_TYPE_LOCAL_DIRECTORY =
"local-directory"
COPY_SOURCE_TYPE_S3_CONFIG =
"s3-config"
COPY_SOURCE_TYPE_GOOGLE_SHEETS =
"google-sheets"
COPY_SOURCE_TYPE_DEFAULT =
"default"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, source, client: nil) ⇒ Loader

Returns a new instance of Loader.



14
15
16
17
18
# File 'lib/sourced_config/locale/loader.rb', line 14

def initialize(type, source, client: nil)
  @type = type
  @source = source
  @client = client
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



20
21
22
# File 'lib/sourced_config/locale/loader.rb', line 20

def locale
  @locale
end

#sourceObject (readonly)

Returns the value of attribute source.



20
21
22
# File 'lib/sourced_config/locale/loader.rb', line 20

def source
  @source
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/sourced_config/locale/loader.rb', line 20

def type
  @type
end

Instance Method Details

#load(locale) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sourced_config/locale/loader.rb', line 22

def load(locale)
  Rails.logger.debug { "[locale - #{locale}] Load copy from #{type} #{source}" }
  case type
  when COPY_SOURCE_TYPE_LOCAL_DIRECTORY
    HashWithIndifferentAccess.new load_from_local_dir(locale)
  when COPY_SOURCE_TYPE_S3_CONFIG, COPY_SOURCE_TYPE_GOOGLE_SHEETS
    HashWithIndifferentAccess.new(locale => HashWithIndifferentAccess.new(client.load(locale)))
  when COPY_SOURCE_TYPE_DEFAULT
    Rails.logger.warn "[locale - #{locale}] Using only default app copy"
    HashWithIndifferentAccess.new(locale => {})
  else
    raise StandardError, "When loading the locales the type was unrecognised! #{type}"
  end
end