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.



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

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.



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

def active_config
  @active_config
end

Instance Method Details

#cli(&block) ⇒ Object



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

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



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

def config(key: active_config, update_active: true)
  configs[:default] ||= Eco::API::Session::Config.new(key)
  unless configs.key?(key)
    @active_config = key unless !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



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

def configs
  @configs ||= {}
end

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



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

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