Class: Gondler::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/gondler/package.rb

Defined Under Namespace

Classes: InstallError

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @name = name
  @branch = options[:branch]
  @tag = options[:tag]
  @commit = options[:commit]
  @os = options[:os]
  @group = options[:group]
  @fix = options[:fix] || false
  @flag = options[:flag]
  @path = options[:path]
  @alternate_name = options[:alternate_name] || options[:alias_as] || options[:as]
end

Instance Attribute Details

#alternate_nameObject (readonly)

Returns the value of attribute alternate_name.



22
23
24
# File 'lib/gondler/package.rb', line 22

def alternate_name
  @alternate_name
end

#branchObject (readonly)

Returns the value of attribute branch.



22
23
24
# File 'lib/gondler/package.rb', line 22

def branch
  @branch
end

#commitObject (readonly)

Returns the value of attribute commit.



22
23
24
# File 'lib/gondler/package.rb', line 22

def commit
  @commit
end

#fixObject (readonly)

Returns the value of attribute fix.



22
23
24
# File 'lib/gondler/package.rb', line 22

def fix
  @fix
end

#flagObject (readonly)

Returns the value of attribute flag.



22
23
24
# File 'lib/gondler/package.rb', line 22

def flag
  @flag
end

#groupObject (readonly)

Returns the value of attribute group.



22
23
24
# File 'lib/gondler/package.rb', line 22

def group
  @group
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/gondler/package.rb', line 22

def name
  @name
end

#osObject (readonly)

Returns the value of attribute os.



22
23
24
# File 'lib/gondler/package.rb', line 22

def os
  @os
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/gondler/package.rb', line 22

def path
  @path
end

#tagObject (readonly)

Returns the value of attribute tag.



22
23
24
# File 'lib/gondler/package.rb', line 22

def tag
  @tag
end

Instance Method Details

#checkoutObject



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

#getObject



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

#installObject



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

Returns:

  • (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

#resolveObject



57
58
59
60
61
# File 'lib/gondler/package.rb', line 57

def resolve
  get
  checkout if target
  install
end

#targetObject



46
47
48
# File 'lib/gondler/package.rb', line 46

def target
  @commit || @branch || @tag
end

#to_sObject



111
112
113
# File 'lib/gondler/package.rb', line 111

def to_s
  "#{@name}" + (target ? " (#{target})" : '')
end