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_host(*args) ⇒ Object


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

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

#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


40
41
42
43
44
45
46
47
48
49
# File 'lib/cdn_fu/config.rb', line 40

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


110
111
112
113
114
115
116
# File 'lib/cdn_fu/config.rb', line 110

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

#minifier(*args, &block) ⇒ Object


126
127
128
129
130
131
# File 'lib/cdn_fu/config.rb', line 126

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


118
119
120
121
122
123
124
# File 'lib/cdn_fu/config.rb', line 118

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

#prepare_and_uploadObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cdn_fu/config.rb', line 56

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


  file_list = @lister.list

  puts "Here"
  case @preprocessor
  when Proc
    @preprocessor.call
  else
    @preprocessor.preprocess(file_list)
  end

  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

#preprocess(&block) ⇒ Object


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

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

#preprocessor(*args, &block) ⇒ Object


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

def preprocessor(*args, &block)
  return @preprocessor if args.size == 0
  preprocessor_class = args[0]
  @preprocessor = preprocessor_class.new
  puts "Setting up preprocessor_class #{@preprocessor}"
  @preprocessor.instance_eval &block if block_given?
end

#setup(&block) ⇒ Object


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

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

#tmp_dir(*args) ⇒ Object


51
52
53
54
# File 'lib/cdn_fu/config.rb', line 51

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

#upload(&block) ⇒ Object


133
134
135
136
137
138
139
# File 'lib/cdn_fu/config.rb', line 133

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

#uploader(*args, &block) ⇒ Object


141
142
143
144
145
146
# File 'lib/cdn_fu/config.rb', line 141

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


35
36
37
38
# File 'lib/cdn_fu/config.rb', line 35

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