Class: CdnFu::Config

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

Overview

This is just a storage class for the configuration for CdnFu

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Make a lister object



20
21
22
# File 'lib/cdn_fu/config.rb', line 20

def initialize
  @lister = Lister.new
end

Class Method Details

.clearObject



10
11
12
# File 'lib/cdn_fu/config.rb', line 10

def self.clear
  @@cfg = nil
end

.configObject



14
15
16
17
# File 'lib/cdn_fu/config.rb', line 14

def self.config
  @@cfg ||= Config.new
  @@cfg
end

.configure(&block) ⇒ Object



4
5
6
7
8
# File 'lib/cdn_fu/config.rb', line 4

def self.configure(&block)
  @@cfg ||= Config.new
  @@cfg.instance_eval &block if block_given?
  @@cfg
end

Instance Method Details

#asset_id(*args) ⇒ Object

Accessors



25
26
27
28
# File 'lib/cdn_fu/config.rb', line 25

def asset_id(*args)
  return @asset_id if args.size == 0
  @asset_id = args[0]
end

#asset_root_dir(*args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/cdn_fu/config.rb', line 35

def asset_root_dir(*args)
  return @asset_root_dir if args.size == 0
  asset_root = args.first
  # TODO add default separator so it works on windows
  if asset_root[0,1] == '/'
    @asset_root_dir = File.expand_path(asset_root)
  else
    @asset_root_dir = File.expand_path(File.join(Dir.pwd,asset_root))
  end
end

#files(&block) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/cdn_fu/config.rb', line 92

def files(&block)
  if block_given?
    @lister.instance_eval &block
  else
    @lister.list
  end
end

#minifier(*args, &block) ⇒ Object



108
109
110
111
112
113
# File 'lib/cdn_fu/config.rb', line 108

def minifier(*args,&block)
  return @minifier if args.size == 0
  minifier_class = args[0]
  @minifier = minifier_class.new
  @minifier.instance_eval &block if block_given?
end

#minify(&block) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/cdn_fu/config.rb', line 100

def minify(&block)
  if block_given?
    @minifier = block 
  else
    raise ConfigError,"No minify block given"
  end
end

#prepare_and_uploadObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cdn_fu/config.rb', line 51

def prepare_and_upload
  @tmp_dir ||= "/tmp"
  FileUtils.mkdir_p(@tmp_dir)

  case @preprocessor
  when Proc
    @preprocessor.call
  when Class
    @preprocessor.preprocess
  end

  file_list = @lister.list

  case @minifier
  when Proc
    @minifier.call(file_list)
  when CdnFu::Minifier
    @minifier.validate_and_minify(file_list)
  end

  case @uploader
  when Proc
    @uploader.call(file_list)
  when CdnFu::Uploader
    @uploader.validate_and_upload(file_list)
  end
end

#preprocessObject



79
80
81
82
83
84
85
# File 'lib/cdn_fu/config.rb', line 79

def preprocess
  if block_given?
    @preprocessor = proc
  else 
    raise ConfigError,"No preprocess block given"
  end
end

#preprocessor(klass) {|@preprocessor| ... } ⇒ Object

Yields:



87
88
89
90
# File 'lib/cdn_fu/config.rb', line 87

def preprocessor(klass)
  @preprocessor = klass
  yield @preprocessor if block_given?
end

#tmp_dir(*args) ⇒ Object



46
47
48
49
# File 'lib/cdn_fu/config.rb', line 46

def tmp_dir(*args)
  return @tmp_dir if args.size == 0
  @tmp_dir = args[0]
end

#upload(&block) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/cdn_fu/config.rb', line 115

def upload(&block)
  if block_given?
    @uploader = block
  else
    raise CdnFuConfigError,"No upload block given"
  end
end

#uploader(*args, &block) ⇒ Object



123
124
125
126
127
128
# File 'lib/cdn_fu/config.rb', line 123

def uploader(*args,&block)
  return @uploader if args.size == 0
  uploader_class = args[0]
  @uploader = uploader_class.new
  @uploader.instance_eval &block if block_given?
end

#verbose(*args) ⇒ Object



30
31
32
33
# File 'lib/cdn_fu/config.rb', line 30

def verbose(*args)
  return @verbose if args.size == 0
  @verbose = args[0]
end