Class: Yaggy::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/yaggy/gem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options) ⇒ Gem

Returns a new instance of Gem.



5
6
7
8
9
# File 'lib/yaggy/gem.rb', line 5

def initialize(file, options)
  @gemspec = file
  @options = options
  query_gemspec
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



79
80
81
# File 'lib/yaggy/gem.rb', line 79

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



79
80
81
# File 'lib/yaggy/gem.rb', line 79

def minor
  @minor
end

#nameObject (readonly)

Returns the value of attribute name.



79
80
81
# File 'lib/yaggy/gem.rb', line 79

def name
  @name
end

#patchObject (readonly)

Returns the value of attribute patch.



79
80
81
# File 'lib/yaggy/gem.rb', line 79

def patch
  @patch
end

Instance Method Details

#commit!Object



23
24
25
26
27
28
29
30
31
# File 'lib/yaggy/gem.rb', line 23

def commit!
  system("git add #{@gemspec}")
  system("git commit -m 'version #{version}'")
  system("git tag v#{version}")
  if !%x{git remote}.chomp.empty?
    system("git push")
    system("git push --tags")
  end
end

#push!Object



33
34
35
36
37
# File 'lib/yaggy/gem.rb', line 33

def push!
  output = `gem build #{@gemspec}`
  # todo: some minimal error detection
  system("gem push #{@name}-#{version}.gem")
end

#push_gem?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/yaggy/gem.rb', line 11

def push_gem?
  @options[:push_gem]
end

#query_gemspecObject



39
40
41
42
43
44
45
46
# File 'lib/yaggy/gem.rb', line 39

def query_gemspec
  mock_spec = Yaggy::MockSpec.capture_gemspec_info(@gemspec)
  version = mock_spec.version
  @version_line = mock_spec.version_line
  @original_version = version
  @major, @minor, @patch = version.split('.')
  @name = mock_spec.name
end

#rev_major!Object



61
62
63
64
65
# File 'lib/yaggy/gem.rb', line 61

def rev_major!
  @major = (@major.to_i + 1).to_s
  @minor = "0"
  @patch = "0"
end

#rev_minor!Object



56
57
58
59
# File 'lib/yaggy/gem.rb', line 56

def rev_minor!
  @minor = (@minor.to_i + 1).to_s
  @patch = "0"
end

#rev_patch!Object



52
53
54
# File 'lib/yaggy/gem.rb', line 52

def rev_patch!
  @patch = (@patch.to_i + 1).to_s
end

#use_git?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/yaggy/gem.rb', line 15

def use_git?
  if @options.key?(:git_ops)
    @options[:git_ops]
  else
    File.directory?(File.dirname(@gemspec) + "/.git")
  end
end

#versionObject



48
49
50
# File 'lib/yaggy/gem.rb', line 48

def version
  [major, minor, patch].join('.')
end

#write!Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/yaggy/gem.rb', line 67

def write!
  lines = File.readlines(@gemspec)
  if lines[@version_line - 1] !~ /#{@original_version}/
    raise "Couldn't find version in gemspec."
  end

  lines[@version_line - 1].sub!(@original_version, version)
  File.open(@gemspec, "w") { |f|
    f.write(lines.join)
  }
end