Class: WriteDown::Model::Asset
- Inherits:
-
Object
- Object
- WriteDown::Model::Asset
- Defined in:
- lib/write_down/model/asset.rb
Overview
代表 js, css, 图片等资产
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(source_file, target_file = nil, option = {}) ⇒ Asset
constructor
A new instance of Asset.
- #sync ⇒ Object
Constructor Details
#initialize(source_file, target_file = nil, option = {}) ⇒ Asset
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/write_down/model/asset.rb', line 9 def initialize(source_file, target_file = nil, option = {}) @source_file = source_file @base_name = source_file.split("/").last.split(".").first @ext_name = source_file.split("/").last.split(".").last if target_file @target_file = target_file else @target_file = "dist/#{target_file}" end @option = option end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/write_down/model/asset.rb', line 21 def build hash_file_name = "#{@base_name}-#{Time.now.to_s}.#{@ext_name}" output = Pathname.new("#{@target_file}") output.dirname.mkpath @final_path = @source_file.gsub("#{@base_name}.#{@ext_name}", hash_file_name) `cp #{source_file} #{@final_path}` end |
#sync ⇒ Object
29 30 31 32 |
# File 'lib/write_down/model/asset.rb', line 29 def sync # TODO 使用配置文件传入七牛的 key 和 secret QiniuSync.new("", "").sync @final_path #TODO @final_path 放在 initialize 里 end |