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."

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of GemThis.



16
17
18
19
20
21
# File 'lib/gem_this.rb', line 16

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

Class Attribute Details

.custom_task_fileObject

Returns the value of attribute custom_task_file.



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

def custom_task_file
  @custom_task_file
end

Instance Attribute Details

#debugObject (readonly)

Returns the value of attribute debug.



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

def debug
  @debug
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#create_rakefileObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gem_this.rb', line 23

def create_rakefile
  template = ERB.new File.read(File.join(File.dirname(__FILE__), '..', 'Rakefile.erb')), nil, '<>'
  rakefile = template.result(binding)
  if self.class.custom_task_file && File.exist?(self.class.custom_task_file)
    rakefile += "\n" + File.read(self.class.custom_task_file)
  end

  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