Class: GemThis

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

Constant Summary collapse

SUMMARY =
"Creates a Rakefile suitable for turning the current project into a gem."
DEBUG_MESSAGE =
"debug, only prints out the generated Rakefile."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ GemThis

Returns a new instance of GemThis.



11
12
13
14
15
16
# File 'lib/gem_this.rb', line 11

def initialize(name, options={})
  @name = name
  options = {:default => false, :silent => false}.update(options)
  @debug = options[:debug]
  @silent = options[:silent]
end

Instance Attribute Details

#debugObject (readonly)

Returns the value of attribute debug.



9
10
11
# File 'lib/gem_this.rb', line 9

def debug
  @debug
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/gem_this.rb', line 9

def name
  @name
end

Instance Method Details

#create_rakefileObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gem_this.rb', line 18

def create_rakefile
  template = ERB.new File.read(File.join(File.dirname(__FILE__), '..', 'Rakefile.erb')), nil, '<>'
  rakefile = template.result(binding)

  if debug
    puts rakefile
  else
    if File.exist?('Rakefile')
      log "Appended to existing Rakefile"
      File.open('Rakefile', 'a') { |f| 2.times { f.puts }; f.write rakefile }
    else
      log "Writing new Rakefile"
      File.open('Rakefile', 'w') { |f| f.write rakefile }
    end
    add_to_gitignore if using_git?
  end
  unless has_lib_directory?
    log "You don't seem to have a lib directory - please edit the Rakefile to set where your code is."
    false
  end
end