Class: MakeMeAGemCalled

Inherits:
Object
  • Object
show all
Defined in:
lib/make_me_a_gem_called.rb,
lib/make_me_a_gem_called/version.rb

Constant Summary collapse

VERSION =
"0.1.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ MakeMeAGemCalled

Returns a new instance of MakeMeAGemCalled.



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

def initialize(name)
  @name = name
end

Instance Attribute Details

#command_lineObject (readonly)

Returns the value of attribute command_line.



5
6
7
# File 'lib/make_me_a_gem_called.rb', line 5

def command_line
  @command_line
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



5
6
7
# File 'lib/make_me_a_gem_called.rb', line 5

def instructions
  @instructions
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/make_me_a_gem_called.rb', line 5

def name
  @name
end

#rspecObject (readonly)

Returns the value of attribute rspec.



5
6
7
# File 'lib/make_me_a_gem_called.rb', line 5

def rspec
  @rspec
end

Instance Method Details

#add_require_relative_to_main_fileObject



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

def add_require_relative_to_main_file
  system("sed -i \'\' 1d #{@name}/lib/#{@name}.rb")
  system("echo require_relative \\'#{@name}/version\\' | cat - #{@name}/lib/#{@name}.rb > #{@name}/lib/temp && mv #{@name}/lib/temp #{@name}/lib/#{@name}.rb")
end

#add_to_bin_filesObject



55
56
57
58
# File 'lib/make_me_a_gem_called.rb', line 55

def add_to_bin_files
  system("echo \\#\\!/usr/bin/env ruby >> #{@name}/bin/#{@name}")
  system("echo require \\'#{@name}\\' >> #{@name}/bin/#{@name}")
end

#add_to_gemspecObject



75
76
77
78
79
# File 'lib/make_me_a_gem_called.rb', line 75

def add_to_gemspec
  system("sed -i \'\' \'23i\\
    \\ \\ spec.add_development_dependency \"rspec\"\\
    \' #{name}/#{name}.gemspec")
end

#add_to_rake_fileObject



71
72
73
# File 'lib/make_me_a_gem_called.rb', line 71

def add_to_rake_file
  system("echo \"Dir.glob(\'tasks/**/*.rake\').each(&method(:import))\" >> #{@name}/Rakefile")
end

#add_to_spec_filesObject



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

def add_to_spec_files
  system("echo require \\'spec_helper\\' >> #{@name}/spec/#{@name}_spec.rb")
  system("echo require \\'#{@name}_spec\\' >> #{@name}/spec/spec_helper.rb")
end

#add_to_tasks_filesObject



65
66
67
68
69
# File 'lib/make_me_a_gem_called.rb', line 65

def add_to_tasks_files
  system("echo require \\'rspec/core/rake_task\\' >> #{@name}/tasks/rspec.rake")
  system("echo \'RSpec::Core::RakeTask.new(:spec)\' >> #{@name}/tasks/rspec.rake")

end

#command_line?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/make_me_a_gem_called.rb', line 37

def command_line?
  ['Y','y','yes','Yes'].include?(@command_line)
end

#command_line_questionObject



32
33
34
35
# File 'lib/make_me_a_gem_called.rb', line 32

def command_line_question
  puts "Would you like to run this gem in the command line? Y/N"
  @command_line = STDIN.gets.chomp
end

#create_bin_filesObject



50
51
52
53
# File 'lib/make_me_a_gem_called.rb', line 50

def create_bin_files
  system("mkdir #{@name}/bin")
  system("touch #{@name}/bin/#{@name}")
end

#create_spec_filesObject



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

def create_spec_files
  system("mkdir #{@name}/spec")
  system("touch #{@name}/spec/spec_helper.rb")
  system("touch #{@name}/spec/#{@name}_spec.rb")
end

#create_tasks_filesObject



60
61
62
63
# File 'lib/make_me_a_gem_called.rb', line 60

def create_tasks_files
  system("mkdir #{@name}/tasks")
  system("touch #{@name}/tasks/rspec.rake")
end

#create_with_bundleObject



12
13
14
# File 'lib/make_me_a_gem_called.rb', line 12

def create_with_bundle
  system("bundle gem #{@name}")
end

#instructions?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/make_me_a_gem_called.rb', line 86

def instructions?
  ['Y','y','yes','Yes'].include?(@instructions)
end

#instructions_questionObject



81
82
83
84
# File 'lib/make_me_a_gem_called.rb', line 81

def instructions_question
  puts "Would you like to see Instructions for your next steps? Y/N"
  @instructions = STDIN.gets.chomp
end

#rspec?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/make_me_a_gem_called.rb', line 46

def rspec?
  ['Y','y','yes','Yes'].include?(@rspec)
end

#rspec_questionObject



41
42
43
44
# File 'lib/make_me_a_gem_called.rb', line 41

def rspec_question
  puts "Would you like to use RSpec to test this gem? Y/N"
  @rspec = STDIN.gets.chomp
end

#show_instructionsObject



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/make_me_a_gem_called.rb', line 90

def show_instructions
  puts "Basic Instructions"
  puts "1. Change into the directory   $ cd #{name}"
  puts "2. In your gemspec: Replace 'summary' and 'description' sections with a string using double quotations."
  puts "3. Write your code in the lib/#{name}.rb file."
  puts "4. If you decide to change from a Module to a Class, remember to change the version.rb file to a Class too."
  puts "5. The bin/#{name} file is run when your gem is called from the command line. Run your code in this file."
  puts "6. Don't forget to complete your README.md file."
  puts "7. If using GitHub, set up a new repo on GitHub. You do not need to run $git init because Bundle has done that for you."
  puts "8. To run your tests:  $ bundle exec rake spec"
  puts "9. To uploaded to rubygems.org:  $ bundle exec rake release"
  puts "Note: You must change the version number every time to upload any changes."
end