Class: Pkgr::Addon
- Inherits:
-
Object
- Object
- Pkgr::Addon
- Defined in:
- lib/pkgr/addon.rb
Defined Under Namespace
Classes: LiveStream
Instance Attribute Summary collapse
-
#addons_dir ⇒ Object
readonly
Returns the value of attribute addons_dir.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
Instance Method Summary collapse
- #branch ⇒ Object
- #debconfig ⇒ Object
- #debian_dependency_name ⇒ Object
- #debtemplates ⇒ Object
- #dir ⇒ Object
-
#initialize(nickname, addons_dir, config) ⇒ Addon
constructor
A new instance of Addon.
- #install!(src_dir) ⇒ Object
- #name ⇒ Object
- #tarball_url ⇒ Object
- #url ⇒ Object
- #url_without_branch ⇒ Object
Constructor Details
#initialize(nickname, addons_dir, config) ⇒ Addon
Returns a new instance of Addon.
6 7 8 9 10 |
# File 'lib/pkgr/addon.rb', line 6 def initialize(nickname, addons_dir, config) @nickname = nickname @addons_dir = addons_dir @config = config end |
Instance Attribute Details
#addons_dir ⇒ Object (readonly)
Returns the value of attribute addons_dir.
3 4 5 |
# File 'lib/pkgr/addon.rb', line 3 def addons_dir @addons_dir end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/pkgr/addon.rb', line 4 def config @config end |
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
3 4 5 |
# File 'lib/pkgr/addon.rb', line 3 def nickname @nickname end |
Instance Method Details
#branch ⇒ Object
32 33 34 |
# File 'lib/pkgr/addon.rb', line 32 def branch nickname.split("#")[1] || "master" end |
#debconfig ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/pkgr/addon.rb', line 56 def debconfig debconfig_file = File.join(dir, "debian", "config") if File.exists?(debconfig_file) File.new(debconfig_file) else StringIO.new end end |
#debian_dependency_name ⇒ Object
40 41 42 43 44 45 |
# File 'lib/pkgr/addon.rb', line 40 def debian_dependency_name [ [config.name, name].join("-"), "(= #{config.version}-#{config.iteration})" ].join(" ") end |
#debtemplates ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/pkgr/addon.rb', line 47 def debtemplates debtemplates_file = File.join(dir, "debian", "templates") if File.exists?(debtemplates_file) File.new(debtemplates_file) else StringIO.new end end |
#dir ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/pkgr/addon.rb', line 89 def dir @dir ||= begin directory = File.join(addons_dir, File.basename(name)) FileUtils.mkdir_p(directory) directory end end |
#install!(src_dir) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pkgr/addon.rb', line 65 def install!(src_dir) install_addon = Mixlib::ShellOut.new %{curl -L --max-redirs 3 --retry 5 -s '#{tarball_url}' | tar xzf - --strip-components=1 -C '#{dir}'} install_addon.logger = Pkgr.logger install_addon.run_command install_addon.error! # TODO: remove args from command once all addons use env variables compile_addon = Mixlib::ShellOut.new(%{#{dir}/bin/compile '#{config.name}' '#{config.version}' '#{config.iteration}' '#{src_dir}' 2>&1}, { :environment => { "APP_NAME" => config.name, "APP_VERSION" => config.version, "APP_ITERATION" => config.iteration, "APP_SAFE_NAME" => config.name.gsub("-", "_"), "APP_USER" => config.user, "APP_GROUP" => config.group, "APP_WORKSPACE" => src_dir } }) compile_addon.logger = Pkgr.logger compile_addon.live_stream = LiveStream.new(STDOUT) compile_addon.run_command compile_addon.error! end |
#name ⇒ Object
12 13 14 |
# File 'lib/pkgr/addon.rb', line 12 def name File.basename(url_without_branch, ".git").sub("addon-", "") end |
#tarball_url ⇒ Object
36 37 38 |
# File 'lib/pkgr/addon.rb', line 36 def tarball_url "#{url}/archive/#{branch}.tar.gz" end |
#url ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pkgr/addon.rb', line 20 def url if nickname.start_with?("http") url_without_branch else user, repo = nickname.split("/", 2) user, repo = "pkgr", user if repo.nil? repo = "addon-#{repo}" unless repo.start_with?("addon-") "https://github.com/#{user}/#{repo}" end end |
#url_without_branch ⇒ Object
16 17 18 |
# File 'lib/pkgr/addon.rb', line 16 def url_without_branch nickname.split("#")[0].sub(/\.git$/,'') end |