Class: Pione::Package::PackageHandler
- Inherits:
-
Object
- Object
- Pione::Package::PackageHandler
- Defined in:
- lib/pione/package/package-handler.rb
Overview
PackageHandler is a set of operations for package.
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#location ⇒ Object
readonly
local package location.
-
#package_type ⇒ Object
readonly
Returns the value of attribute package_type.
Class Method Summary collapse
-
.write_info_files(location, option = {}) ⇒ Object
Update package info file and scenario info files.
Instance Method Summary collapse
-
#eval(env) ⇒ Object
Evaluate the package context in the environment.
-
#find_scenario(name) ⇒ ScenarioHandler
Find scenario that have the name.
-
#initialize(location, key = {}) ⇒ PackageHandler
constructor
A new instance of PackageHandler.
-
#upload(dest) ⇒ Object
Upload the package files to the location.
Constructor Details
#initialize(location, key = {}) ⇒ PackageHandler
Returns a new instance of PackageHandler.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pione/package/package-handler.rb', line 32 def initialize(location, key={}) @location = location unless key.has_key?(:digest) or key.has_key?(:info) raise ArgumentError end # init with digest if digest = key[:digest] @digest = digest json = (PackageCache.directory_cache(digest) + "pione-package.json").read @info = PackageInfo.read(json) end # init with info for single document location if info = key[:info] @digest = nil @info = info end end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
29 30 31 |
# File 'lib/pione/package/package-handler.rb', line 29 def digest @digest end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
28 29 30 |
# File 'lib/pione/package/package-handler.rb', line 28 def info @info end |
#location ⇒ Object (readonly)
local package location
27 28 29 |
# File 'lib/pione/package/package-handler.rb', line 27 def location @location end |
#package_type ⇒ Object (readonly)
Returns the value of attribute package_type.
30 31 32 |
# File 'lib/pione/package/package-handler.rb', line 30 def package_type @package_type end |
Class Method Details
.write_info_files(location, option = {}) ⇒ Object
Update package info file and scenario info files.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pione/package/package-handler.rb', line 7 def write_info_files(location, option={}) # scan the package directory package_info = PackageScanner.new(location).scan last_time = Util::LastTime.get(package_info.filepaths.map{|path| location + path}) # update the package info file info_location = location + "pione-package.json" if option[:force] or not(info_location.exist?) or last_time > info_location.mtime info_location.write(JSON.pretty_generate(package_info)) Log::SystemLog.info("update the package info file: %s" % info_location.address) end # write scenario info files package_info.scenarios.each do |scenario| scenario_info = ScenarioScanner.new(location + scenario).scan ScenarioHandler.new(location + scenario, scenario_info).write_info_file(option) end end |
Instance Method Details
#eval(env) ⇒ Object
Evaluate the package context in the environment. This method will introduce a new package id, and the context is evaluated under it.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pione/package/package-handler.rb', line 55 def eval(env) # load parent packages parent_package_ids = @info.parents.map do |parent_info| load_parent_package(env, parent_info.name, parent_info.editor, parent_info.tag) end # load this package _env = env.setup_new_package(info.name || "Anonymous", parent_package_ids) @info.documents.inject(Lang::PackageContext.new) do |_context, d| Document.load(_env, @location + d, @info.name, @info.editor, @info.tag, d) end return _env end |
#find_scenario(name) ⇒ ScenarioHandler
Find scenario that have the name.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pione/package/package-handler.rb', line 89 def find_scenario(name) @info.scenarios.each do |path| if name == :anything # read first hit scenario return ScenarioReader.read(@location + path) else # read matched scenario scenario = ScenarioReader.read(@location + path) if scenario.info.name == name return scenario end end end end |
#upload(dest) ⇒ Object
Upload the package files to the location.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pione/package/package-handler.rb', line 71 def upload(dest) # upload bins @info.bins.each do |entry| (@location + entry).copy(dest + entry) end # upload etc files @info.etcs.each do |entry| (@location + entry).copy(dest + entry) end end |