Class: ECSBundler::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_bundler/config.rb

Constant Summary collapse

FILE_NAME =
'/.ecsrc.json'.freeze
URL =
'https://ecs-app.eacg.de'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



11
12
13
# File 'lib/ecs_bundler/config.rb', line 11

def initialize
  @data = get_default_options
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/ecs_bundler/config.rb', line 9

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object



27
28
29
# File 'lib/ecs_bundler/config.rb', line 27

def [](key)
  @data[key]
end

#load(path = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ecs_bundler/config.rb', line 15

def load(path = nil)
  path = [path, Dir.pwd, ENV['HOME']].flatten.compact.map do |path|
    if File.directory?(path) && File.exist?("#{path}#{FILE_NAME}")
      "#{path}#{FILE_NAME}"
    elsif File.file?(path) && File.exist?(path)
      path
    end
  end.compact.first
  @data = get_default_options.merge(::JSON.parse(File.read(path)).map { |k, v| [k.to_sym, v] }.to_h) if path
rescue
end