Module: Gemstub

Defined in:
lib/gemstub.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.test_frameworkObject

Returns the value of attribute test_framework.



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

def test_framework
  @test_framework
end

Class Method Details

.gem_spec(&block) ⇒ Object



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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/gemstub.rb', line 53

def gem_spec(&block)
  @gem_spec = Gem::Specification.new do |s|
    s.name = File.basename(FileUtils.pwd)
    s.version = "0.0.1"
    s.summary = s.name
    s.author = (ENV["USERNAME"] || ENV["USER"])
    s.description = "#{s.name} was developed by: #{s.author}"
    s.email = ""
    s.homepage = ""
    s.files = FileList['lib/**/*.*', 'README', 'LICENSE', 'bin/**/*.*']
    s.require_paths = ['lib']
    s.bindir = 'bin'
    s.extra_rdoc_files = ['README', 'LICENSE']
    s.has_rdoc = true
    yield s
  end

  # rake package
  Rake::GemPackageTask.new(@gem_spec) do |pkg|
    pkg.need_zip = false
    pkg.need_tar = false
    rm_f FileList['pkg/**/*.*']
  end

  desc 'regenerate the gemspec'
  task :gemspec => [:readme] do
    @gem_spec.version = "#{@gem_spec.version}.#{Time.now.strftime('%Y%m%d%H%M%S')}"
    File.open(File.join("#{@gem_spec.name}.gemspec"), 'w') {|f| f.puts @gem_spec.to_ruby}
  end

  desc "Install the gem"
  task :install => [:readme, :package] do |t|
    sudo = ENV['SUDOLESS'] == 'true' || RUBY_PLATFORM =~ /win32|cygwin/ ? '' : 'sudo'
    puts `#{sudo} gem install #{File.join("pkg", @gem_spec.name)}-#{@gem_spec.version}.gem --no-update-sources --no-ri --no-rdoc`
  end

  desc "Release the gem"
  task :release => :install do |t|
    gem_pkg = File.join("pkg", "#{@gem_spec.name}-#{@gem_spec.version}.gem")
    system "gem push #{gem_pkg}"
    begin
      ac_path = File.join(ENV["HOME"], ".rubyforge", "auto-config.yml")
      if File.exists?(ac_path)
        fixed = File.open(ac_path).read.gsub("  ~: {}\n\n", '')
        fixed.gsub!(/    !ruby\/object:Gem::Version \? \n.+\n.+\n\n/, '')
        puts "Fixing #{ac_path}..."
        File.open(ac_path, "w") {|f| f.puts fixed}
      end
      begin
        rf = RubyForge.new
        rf.configure
        rf.
        rf.add_release(@gem_spec.rubyforge_project, @gem_spec.name, @gem_spec.version, gem_pkg)
      rescue Exception => e
        if e.message.match("Invalid package_id") || e.message.match("no <package_id> configured for")
          puts "You need to create the package!"
          rf.create_package(@gem_spec.rubyforge_project, @gem_spec.name)
          rf.add_release(@gem_spec.rubyforge_project, @gem_spec.name, @gem_spec.version, gem_pkg)
        else
          raise e
        end
      end
    rescue Exception => e
      if e.message == "You have already released this version."
        puts e
      else
        raise e
      end
    end
  end
  
  task :readme do
    txt = File.read(File.join(FileUtils.pwd, 'README.textile'))
    plain = File.join(FileUtils.pwd, 'README')

    # txt.gsub!(/[\s](@\S+@)[\s]/, "<tt>#{$1}</tt>")
    txt.scan(/[\s]@(\S+)@[\s|\.]/).flatten.each do |word|
      # puts "replacing: @#{word}@ w/ <tt>#{word}</tt>"
      txt.gsub!("@#{word}@", "<tt>#{word}</tt>")
    end

    ['h1', 'h2', 'h3', 'h4'].each_with_index do |h, i|
      txt.scan(/(#{h}.\s)/).flatten.each do |word|
        eq = '=' * (i + 1)
        # puts "replacing: '#{word}' w/ #{eq}"
        txt.gsub!(word, eq)
      end
    end

    ['<pre><code>', '</code></pre>'].each do |h|
      txt.scan(/(#{h}.*$)/).flatten.each do |word|
        # puts "replacing: '#{word}' with nothing"
        txt.gsub!(word, '')
      end
    end

    txt.gsub!("\n\n\n", "\n\n")
    File.open(plain, 'w') {|f| f.write txt}
  end

end

.rdoc(&block) ⇒ Object

gem_spec



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/gemstub.rb', line 155

def rdoc(&block)
  Rake::RDocTask.new do |rd|
    rd.main = "README"
    rd.rdoc_files = Dir.glob(File.join('lib', '**', '*.rb'))
    rd.rdoc_files << 'README'
    rd.rdoc_files << 'LICENSE'
    rd.rdoc_dir = "doc"
    rd.options << "--line-numbers"
    rd.options << "--inline-source"
    rd.title = "content_o_matic"
    yield rd if block_given?
  end
  
  task :doc => [:readme, :rerdoc]
end

.rspec?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/gemstub.rb', line 24

def rspec?
  test_framework == :rspec
end

.test_unit?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/gemstub.rb', line 28

def test_unit?
  test_framework == :test_unit
end