Class: FlexmlsGems::TaskHelper

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/flexmls_gems/task_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TaskHelper

Returns a new instance of TaskHelper.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/flexmls_gems/task_helper.rb', line 9

def initialize(opts={})
  @pwd = opts[:dir] || Dir.pwd
  gemspecs = opts[:name] ? [File.join(pwd, "#{opts[:name]}.gemspec")] : Dir[File.join(pwd, "*.gemspec")]
  raise("FlexmlsGems expects one and only one gemspec in the root of the project.") unless gemspecs.size == 1
  @gemspec = gemspecs.first
  @name = opts[:name] || File.basename(gemspec, '.gemspec')
  begin
    @version = Gem::Specification::load(gemspec).version
  rescue
    $stdout.puts "The version could not be determined from the gemspec.  Defaulting to 0.0.0"
    @version = DEFAULT_VERSION
  end
  @release_dir = opts[:release] || '/opt/gems/dev'
  @dev_release_dir = opts[:dev_release] || '/opt/gems/dev'
  @public_release_dir = opts[:public_release_dir] || '/opt/gems/public'
end

Instance Attribute Details

#dev_release_dirObject (readonly)

Returns the value of attribute dev_release_dir.



7
8
9
# File 'lib/flexmls_gems/task_helper.rb', line 7

def dev_release_dir
  @dev_release_dir
end

#gemspecObject (readonly)

Returns the value of attribute gemspec.



7
8
9
# File 'lib/flexmls_gems/task_helper.rb', line 7

def gemspec
  @gemspec
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/flexmls_gems/task_helper.rb', line 7

def name
  @name
end

#public_release_dirObject (readonly)

Returns the value of attribute public_release_dir.



7
8
9
# File 'lib/flexmls_gems/task_helper.rb', line 7

def public_release_dir
  @public_release_dir
end

#pwdObject (readonly)

Returns the value of attribute pwd.



7
8
9
# File 'lib/flexmls_gems/task_helper.rb', line 7

def pwd
  @pwd
end

#release_dirObject (readonly)

Returns the value of attribute release_dir.



7
8
9
# File 'lib/flexmls_gems/task_helper.rb', line 7

def release_dir
  @release_dir
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/flexmls_gems/task_helper.rb', line 7

def version
  @version
end

Class Method Details

.deploy_gem(gem, dir, remote = false, host = "farnsworth.fbsdata.com") ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/flexmls_gems/task_helper.rb', line 96

def self.deploy_gem(gem, dir, remote = false, host="farnsworth.fbsdata.com")
  gems = Dir[gem]
  raise "No gems built, run rake build to create" if gems.empty?
  if remote
    out = "#{host}:#{dir}"
    copy = "scp #{gem} #{host}:#{dir}/gems/" 
    index = "ssh #{host} gem generate_index -d #{dir}"
  else
    out = dir
    copy = "cp -v #{gem} #{dir}/gems/."
    index = "/usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/gem generate_index -d #{dir}"
  end
  $stdout.puts "Copying #{gem} to #{out}"
  $stdout.puts `#{copy}`
  $stdout.puts "Gemifying #{out}"
  $stdout.puts `env ; #{index}`
end

Instance Method Details

#patch_versionObject



26
27
28
29
30
31
# File 'lib/flexmls_gems/task_helper.rb', line 26

def patch_version
  if version.to_s =~ /^(\d+\.\d+\.\d+).*/
    return $1
  end
  version
end

#setupObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/flexmls_gems/task_helper.rb', line 33

def setup
  namespace :flexmls do
    desc "Release the gem internally"
    task :release do
      FlexmlsGems::TaskHelper.deploy_gem("#{pwd}/pkg/#{name}-#{version}.gem", release_dir)
    end
    desc "Release a development build of the gem"
    task :dev_release do
      FlexmlsGems::TaskHelper.deploy_gem("#{pwd}/pkg/#{name}-#{version}.gem", dev_release_dir)
    end
    desc "Release a public version of the gem"
    task :public_release do
      FlexmlsGems::TaskHelper.deploy_gem("#{pwd}/pkg/#{name}-#{version}.gem", public_release_dir, true)
    end
    desc "Release a build of the gem to a remote gem repository"
    task :remote_release do
      FlexmlsGems::TaskHelper.deploy_gem("#{pwd}/pkg/#{name}-#{version}.gem", dev_release_dir, true, "blanka.flexmls.com")
    end
  end
  namespace :version do
    namespace :bump do
      desc "Bump the major version [#{version}] by 1"
      task :major => [:version] do
        version_helper.bump_major.save
        git_helper.commit_version
        $stdout.puts "Updated version to #{version_helper}"
      end
      desc "Bump the a minor version [#{version}]  by 1"
      task :minor => [:version] do
        version_helper.bump_minor.save
        git_helper.commit_version
        $stdout.puts "Updated version to #{version_helper}"
      end
      desc "Bump the patch version by [#{version}] 1"
      task :patch => [:version] do
        version_helper.bump_patch.save
        git_helper.commit_version
        $stdout.puts "Updated version to #{version_helper}"
      end
      desc "Bump the patch version to [#{patch_version}.pre] or [#{patch_version}.$BUILD].  Set BUILD=tagname in the environment to customize."
      task :build => [:version] do
        if ENV["BUILD"]
          version_helper.bump_build(ENV["BUILD"]).save
        else
          version_helper.bump_build.save
        end
        git_helper.commit_version
        $stdout.puts "Updated version to #{version_helper}"
      end
    end
  end
  task :version do
    $stdout.puts "The current version is #{version_helper}"
  end
  namespace :git do
    desc "Tag and release v#{version} to git"
    task :release do
      git_helper.release
      $stdout.puts "Released #{version}"
    end
  end
end