Class: Eco::Assets

Inherits:
Object show all
Defined in:
lib/eco/assets.rb,
lib/eco/assets/language.rb

Defined Under Namespace

Classes: Language

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAssets

Returns a new instance of Assets.



5
6
7
8
9
# File 'lib/eco/assets.rb', line 5

def initialize
  @active_config = :default
  @cli      = Eco::CLI.new
  @cli_init = false
end

Instance Attribute Details

#active_configObject (readonly)

Returns the value of attribute active_config.



3
4
5
# File 'lib/eco/assets.rb', line 3

def active_config
  @active_config
end

Instance Method Details

#cli(&block) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/eco/assets.rb', line 35

def cli(&block)
  unless @cli_init
    @cli_init = true
    require_relative('cli_default')
  end

  @cli.tap { yield(@cli) if block_given? }
end

#config(key: active_config, update_active: true) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/eco/assets.rb', line 17

def config(key: active_config, update_active: true)
  configs[:default] ||= Eco::API::Session::Config.new(key)

  unless configs.key?(key)
    @active_config = key if update_active
    configs[key]   = configs[:default].clone(key)
  end

  configs[key].tap do |config|
    config.active_api(key) if config.apis.defined?(key)
    yield(config) if block_given?
  end
end

#configsObject



31
32
33
# File 'lib/eco/assets.rb', line 31

def configs
  @configs ||= {}
end

#session(key: active_config, update_active: true) ⇒ Object



11
12
13
14
15
# File 'lib/eco/assets.rb', line 11

def session(key: active_config, update_active: true)
  config(key: key, update_active: update_active).session.tap do |session|
    yield(session) if block_given?
  end
end