Class: Gondler::Package
- Inherits:
-
Object
- Object
- Gondler::Package
- Defined in:
- lib/gondler/package.rb
Defined Under Namespace
Classes: InstallError
Instance Attribute Summary collapse
-
#alternate_name ⇒ Object
readonly
Returns the value of attribute alternate_name.
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#commit ⇒ Object
readonly
Returns the value of attribute commit.
-
#fix ⇒ Object
readonly
Returns the value of attribute fix.
-
#flag ⇒ Object
readonly
Returns the value of attribute flag.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #checkout ⇒ Object
- #checkout_with_git(path) ⇒ Object
- #checkout_with_hg(path) ⇒ Object
- #get ⇒ Object
-
#initialize(name, options = {}) ⇒ Package
constructor
A new instance of Package.
- #install ⇒ Object
- #installable? ⇒ Boolean
- #resolve ⇒ Object
- #target ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Package
Returns a new instance of Package.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gondler/package.rb', line 9 def initialize(name, = {}) @name = name @branch = [:branch] @tag = [:tag] @commit = [:commit] @os = [:os] @group = [:group] @fix = [:fix] || false @flag = [:flag] @path = [:path] @alternate_name = [:alternate_name] || [:alias_as] || [:as] end |
Instance Attribute Details
#alternate_name ⇒ Object (readonly)
Returns the value of attribute alternate_name.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def alternate_name @alternate_name end |
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def branch @branch end |
#commit ⇒ Object (readonly)
Returns the value of attribute commit.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def commit @commit end |
#fix ⇒ Object (readonly)
Returns the value of attribute fix.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def fix @fix end |
#flag ⇒ Object (readonly)
Returns the value of attribute flag.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def flag @flag end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def group @group end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def name @name end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def os @os end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def path @path end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
22 23 24 |
# File 'lib/gondler/package.rb', line 22 def tag @tag end |
Instance Method Details
#checkout ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gondler/package.rb', line 75 def checkout @name.split('/').reduce(src_path) do |path, dir| path += dir if File.directory?(path + '.git') break checkout_with_git(path) elsif File.directory?(path + '.hg') break checkout_with_hg(path) end path end end |
#checkout_with_git(path) ⇒ Object
87 88 89 90 91 |
# File 'lib/gondler/package.rb', line 87 def checkout_with_git(path) Dir.chdir(path) do `git checkout -q #{target}` end end |
#checkout_with_hg(path) ⇒ Object
93 94 95 96 97 |
# File 'lib/gondler/package.rb', line 93 def checkout_with_hg(path) Dir.chdir(path) do `hg update #{target}` end end |
#get ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gondler/package.rb', line 63 def get if @path get_by_path else get_by_package end if alternate_name link_alternate_name end end |
#install ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gondler/package.rb', line 99 def install args = %w(go install) args << @flag if @flag args << @name result = `#{args.join(' ')} 2>&1` unless $CHILD_STATUS.success? raise InstallError.new("#{@name} install error\n" + result) end end |
#installable? ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/gondler/package.rb', line 50 def installable? ( (os.nil? || os.include?(Gondler.env.os)) && (group.empty? || (Gondler.without & group).empty?) ) end |
#resolve ⇒ Object
57 58 59 60 61 |
# File 'lib/gondler/package.rb', line 57 def resolve get checkout if target install end |
#target ⇒ Object
46 47 48 |
# File 'lib/gondler/package.rb', line 46 def target @commit || @branch || @tag end |
#to_s ⇒ Object
111 112 113 |
# File 'lib/gondler/package.rb', line 111 def to_s "#{@name}" + (target ? " (#{target})" : '') end |