Class: KCommercial::Resources::StarSource
- Inherits:
-
Object
- Object
- KCommercial::Resources::StarSource
- Defined in:
- lib/KCommercialPipeline/core/resource/source/star_source.rb
Defined Under Namespace
Classes: PathSource
Instance Attribute Summary collapse
-
#all_assets_maps ⇒ Object
readonly
Returns the value of attribute all_assets_maps.
-
#app_paths ⇒ Object
readonly
Returns the value of attribute app_paths.
-
#default_path ⇒ Object
readonly
Returns the value of attribute default_path.
-
#root_path ⇒ Pathname
readonly
The local storage path.
-
#url ⇒ String
readonly
The url for the star platform.
Instance Method Summary collapse
- #download_resources(url) ⇒ Object
-
#initialize(url, root_path) ⇒ StarSource
constructor
A new instance of StarSource.
- #load_assets(type) ⇒ Object
- #rename_resources ⇒ Object
- #struct_assets_from_directory(directory) ⇒ Object
- #type_directory_mapper ⇒ Object
-
#update ⇒ Object
Update the source.
Constructor Details
#initialize(url, root_path) ⇒ StarSource
Returns a new instance of StarSource.
79 80 81 82 83 84 85 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 79 def initialize(url, root_path) @url = url @root_path = root_path @temp_path = root_path.split[0].join("temp_#{Time.now.to_i}") @default_path = root_path.join('defaults') @all_assets_maps = {} end |
Instance Attribute Details
#all_assets_maps ⇒ Object (readonly)
Returns the value of attribute all_assets_maps.
72 73 74 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 72 def all_assets_maps @all_assets_maps end |
#app_paths ⇒ Object (readonly)
Returns the value of attribute app_paths.
72 73 74 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 72 def app_paths @app_paths end |
#default_path ⇒ Object (readonly)
Returns the value of attribute default_path.
72 73 74 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 72 def default_path @default_path end |
#root_path ⇒ Pathname (readonly)
The local storage path
75 76 77 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 75 def root_path @root_path end |
#url ⇒ String (readonly)
The url for the star platform
71 72 73 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 71 def url @url end |
Instance Method Details
#download_resources(url) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 124 def download_resources(url) KCommercial::UI.info "download the source #{url}" download = URI.open(url) Zip::File.open_buffer(download) do |zip| zip.each do |entry| path = @temp_path.join(entry.name) entry.extract(path) end end end |
#load_assets(type) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 87 def load_assets(type) directory_name = type_directory_mapper[type] return nil unless directory_name sources = app_paths.map { |c| PathSource.new(directory_name, type, c, c.basename.to_s) } common_source = sources.find_all(&:is_common_asset) sources.each { |items| items.merge(common_source.first) } if common_source.size.positive? all_assets_maps[directory_name] = sources sources end |
#rename_resources ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 136 def rename_resources if root_path.exist? FileUtils.rm_r(root_path) end File.rename(@temp_path, root_path) @app_paths = root_path.children.find_all(&:directory?) || [] if @root_path.exist? end |
#struct_assets_from_directory(directory) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 98 def struct_assets_from_directory(directory) asset_paths = directory.glob('**/*.cdasset') asset_paths.map do |path| name = path.basename('.*').to_s HashAsset.new(name, path) end end |
#type_directory_mapper ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 106 def type_directory_mapper { AssetType::Color => 'Colors', AssetType::File => 'Files', AssetType::Font => 'Fonts', AssetType::I18n => 'I18ns', AssetType::Image => 'Images', } end |
#update ⇒ Object
Update the source
117 118 119 120 121 122 |
# File 'lib/KCommercialPipeline/core/resource/source/star_source.rb', line 117 def update # 先在临时目录下载 download_resources(url) # 最后rename rename_resources end |