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

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

Constant Summary collapse

DEFAULT =
'config.yml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, path) ⇒ Config

Returns a new instance of Config.

Parameters:

  • config (Array, Hash)
  • path (String)


45
46
47
48
# File 'lib/yui/compressor/ext/config.rb', line 45

def initialize(config, path)
  @config = config
  @path = Pathname.new(path)
end

Instance Attribute Details

#configArray, Hash (readonly)

Returns:

  • (Array, Hash)


38
39
40
# File 'lib/yui/compressor/ext/config.rb', line 38

def config
  @config
end

#pathPathname (readonly)

Returns:

  • (Pathname)


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

def path
  @path
end

Class Method Details

.load_file(path) ⇒ Ext::Config

Parameters:

  • path (String)

Returns:



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

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, File.expand_path(path))
end

Instance Method Details

#files(type) ⇒ Array<String>

Parameters:

  • type (String)

Returns:

  • (Array<String>)


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

def files(type)
  dir = config_for(type, 'files_dir') || config_for(type, 'base_dir')
  config_for(type, 'files').map do |file|
    build_path(dir, file)
  end
end

#options(type) ⇒ Hash

Parameters:

  • type (String)

Returns:

  • (Hash)


67
68
69
70
# File 'lib/yui/compressor/ext/config.rb', line 67

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

#output(type) ⇒ String

Parameters:

  • type (String)

Returns:

  • (String)


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

def output(type)
  build_path(@config['output_dir'], config_for(type, 'output'))
end