Class: YUI::Compressor::Ext::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/yui/compressor/ext/config.rb

Constant Summary collapse

DEFAULT =
'config.yml'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.

Parameters:

  • config (Array, Hash)


36
37
38
# File 'lib/yui/compressor/ext/config.rb', line 36

def initialize(config)
  @config = config
end

Class Method Details

.load_file(path) ⇒ Ext::Config

Parameters:

  • path (String)

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yui/compressor/ext/config.rb', line 11

def load_file(path)
  path ||= DEFAULT
  
  unless File.exist? path
    raise ArgumentError,
      "Not found configuration file to `#{File.expand_path(path)}`."
  end
  
  config = YAML.load_file(path)
  unless validate(config)
    raise 'Invalid configuration file.'
  end

  new(config)
end

Instance Method Details

#files(type) ⇒ Array<String>

Parameters:

  • type (String)

Returns:

  • (Array<String>)


49
50
51
52
53
54
55
# File 'lib/yui/compressor/ext/config.rb', line 49

def files(type)
  base = clean_path(config_for(type, 'base_dir'))
  files = config_for(type, 'files')
  files.map do |file|
    File.join(*[base, clean_path(file)].compact)
  end
end

#options(type) ⇒ Hash

Parameters:

  • type (String)

Returns:

  • (Hash)


59
60
61
62
# File 'lib/yui/compressor/ext/config.rb', line 59

def options(type)
  base = @config['options'] || {}
  base.merge(config_for(type, 'options') || {})
end

#output(type) ⇒ String

Parameters:

  • type (String)

Returns:

  • (String)


42
43
44
45
# File 'lib/yui/compressor/ext/config.rb', line 42

def output(type)
  File.join(*[clean_path(@config['output_dir']),
              clean_path(config_for(type, 'output'))].compact)
end