Class: CdnFu::Config
- Inherits:
-
Object
- Object
- CdnFu::Config
- 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
-
#asset_id(*args) ⇒ Object
Accessors.
- #asset_root_dir(*args) ⇒ Object
- #files(&block) ⇒ Object
-
#initialize ⇒ Config
constructor
Make a lister object.
- #minifier(*args, &block) ⇒ Object
- #minify(&block) ⇒ Object
- #prepare_and_upload ⇒ Object
- #preprocess ⇒ Object
- #preprocessor(klass) {|@preprocessor| ... } ⇒ Object
- #tmp_dir(*args) ⇒ Object
- #upload(&block) ⇒ Object
- #uploader(*args, &block) ⇒ Object
- #verbose(*args) ⇒ Object
Constructor Details
Class Method Details
.clear ⇒ Object
10 11 12 |
# File 'lib/cdn_fu/config.rb', line 10 def self.clear @@cfg = nil 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.(asset_root) else @asset_root_dir = File.(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_upload ⇒ Object
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 |
#preprocess ⇒ Object
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
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 |