Parent

Class Index [+]

Quicksearch

Jeweler::Generator

Generator for creating a jeweler-enabled project

Attributes

target_dir[RW]
user_name[RW]
user_email[RW]
summary[RW]
homepage[RW]
description[RW]
project_name[RW]
github_username[RW]
github_token[RW]
repo[RW]
should_create_remote_repo[RW]
testing_framework[RW]
documentation_framework[RW]
should_use_cucumber[RW]
should_setup_gemcutter[RW]
should_setup_rubyforge[RW]
should_use_reek[RW]
should_use_roodi[RW]
development_dependencies[RW]
options[RW]

Public Class Methods

new(options = {}) click to toggle source
    # File lib/jeweler/generator.rb, line 52
52:     def initialize(options = {})
53:       self.options = options
54: 
55:       self.project_name   = options[:project_name]
56:       if self.project_name.nil? || self.project_name.squeeze.strip == ""
57:         raise NoGitHubRepoNameGiven
58:       end
59: 
60:       self.development_dependencies = []
61:       self.testing_framework  = options[:testing_framework]
62:       self.documentation_framework = options[:documentation_framework]
63:       begin
64:         generator_mixin_name = "#{self.testing_framework.to_s.capitalize}Mixin"
65:         generator_mixin = self.class.const_get(generator_mixin_name)
66:         extend generator_mixin
67:       rescue NameError => e
68:         raise ArgumentError, "Unsupported testing framework (#{testing_framework})"
69:       end
70: 
71:       begin
72:         generator_mixin_name = "#{self.documentation_framework.to_s.capitalize}Mixin"
73:         generator_mixin = self.class.const_get(generator_mixin_name)
74:         extend generator_mixin
75:       rescue NameError => e
76:         raise ArgumentError, "Unsupported documentation framework (#{documentation_framework})"
77:       end
78: 
79:       self.target_dir             = options[:directory] || self.project_name
80: 
81:       self.summary                = options[:summary] || 'TODO: one-line summary of your gem'
82:       self.description            = options[:description] || 'TODO: longer description of your gem'
83:       self.should_use_cucumber    = options[:use_cucumber]
84:       self.should_use_reek        = options[:use_reek]
85:       self.should_use_roodi       = options[:use_roodi]
86:       self.should_setup_gemcutter = options[:gemcutter]
87:       self.should_setup_rubyforge = options[:rubyforge]
88: 
89:       development_dependencies << ["cucumber", ">= 0"] if should_use_cucumber
90: 
91:       self.user_name       = options[:user_name]
92:       self.user_email      = options[:user_email]
93:       self.homepage        = options[:homepage]
94: 
95:       raise NoGitUserName unless self.user_name
96:       raise NoGitUserEmail unless self.user_email
97: 
98:       extend GithubMixin
99:     end

Public Instance Methods

constant_name() click to toggle source
     # File lib/jeweler/generator.rb, line 111
111:     def constant_name
112:       self.project_name.split(/[-_]/).collect{|each| each.capitalize }.join
113:     end
feature_filename() click to toggle source
     # File lib/jeweler/generator.rb, line 131
131:     def feature_filename
132:       "#{project_name}.feature"
133:     end
features_dir() click to toggle source
     # File lib/jeweler/generator.rb, line 139
139:     def features_dir
140:       'features'
141:     end
features_steps_dir() click to toggle source
     # File lib/jeweler/generator.rb, line 147
147:     def features_steps_dir
148:       File.join(features_dir, 'step_definitions')
149:     end
features_support_dir() click to toggle source
     # File lib/jeweler/generator.rb, line 143
143:     def features_support_dir
144:       File.join(features_dir, 'support')
145:     end
file_name_prefix() click to toggle source
     # File lib/jeweler/generator.rb, line 123
123:     def file_name_prefix
124:       self.project_name.gsub('-', '_')
125:     end
lib_dir() click to toggle source
     # File lib/jeweler/generator.rb, line 127
127:     def lib_dir
128:       'lib'
129:     end
lib_filename() click to toggle source
     # File lib/jeweler/generator.rb, line 115
115:     def lib_filename
116:       "#{project_name}.rb"
117:     end
require_name() click to toggle source
     # File lib/jeweler/generator.rb, line 119
119:     def require_name
120:       self.project_name
121:     end
run() click to toggle source
     # File lib/jeweler/generator.rb, line 101
101:     def run
102:       create_files
103:       create_version_control
104:       $stdout.puts "Jeweler has prepared your gem in #{target_dir}"
105:       if should_create_remote_repo
106:         create_and_push_repo
107:         $stdout.puts "Jeweler has pushed your repo to #{homepage}"
108:       end
109:     end
steps_filename() click to toggle source
     # File lib/jeweler/generator.rb, line 135
135:     def steps_filename
136:       "#{project_name}_steps.rb"
137:     end

Private Instance Methods

create_and_push_repo() click to toggle source
     # File lib/jeweler/generator.rb, line 260
260:     def create_and_push_repo
261:       Net::HTTP.post_form URI.parse('http://github.com/api/v2/yaml/repos/create'),
262:                                 'login' => github_username,
263:                                 'token' => github_token,
264:                                 'description' => summary,
265:                                 'name' => project_name
266:       # TODO do a HEAD request to see when it's ready?
267:       @repo.push('origin')
268:     end
create_files() click to toggle source
     # File lib/jeweler/generator.rb, line 152
152:     def create_files
153:       unless File.exists?(target_dir) || File.directory?(target_dir)
154:         FileUtils.mkdir target_dir
155:       else
156:         raise FileInTheWay, "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?"
157:       end
158: 
159: 
160:       output_template_in_target '.gitignore'
161:       output_template_in_target 'Rakefile'
162:       output_template_in_target 'LICENSE'
163:       output_template_in_target 'README.rdoc'
164:       output_template_in_target '.document'
165: 
166:       mkdir_in_target           lib_dir
167:       touch_in_target           File.join(lib_dir, lib_filename)
168: 
169:       mkdir_in_target           test_dir
170:       output_template_in_target File.join(testing_framework.to_s, 'helper.rb'),
171:                                 File.join(test_dir, test_helper_filename)
172:       output_template_in_target File.join(testing_framework.to_s, 'flunking.rb'),
173:                                 File.join(test_dir, test_filename)
174: 
175: 
176:       if testing_framework == :rspec
177:         output_template_in_target File.join(testing_framework.to_s, 'spec.opts'),
178:                                   File.join(test_dir, 'spec.opts')
179: 
180:       end
181: 
182:       if should_use_cucumber
183:         mkdir_in_target           features_dir
184:         output_template_in_target File.join(%(features default.feature)), File.join('features', feature_filename)
185: 
186:         mkdir_in_target           features_support_dir
187:         output_template_in_target File.join(features_support_dir, 'env.rb')
188: 
189:         mkdir_in_target           features_steps_dir
190:         touch_in_target           File.join(features_steps_dir, steps_filename)
191:       end
192: 
193:     end
create_version_control() click to toggle source
     # File lib/jeweler/generator.rb, line 230
230:     def create_version_control
231:       Dir.chdir(target_dir) do
232:         begin
233:           @repo = Git.init()
234:         rescue Git::GitExecuteError => e
235:           raise GitInitFailed, "Encountered an error during gitification. Maybe the repo already exists, or has already been pushed to?"
236:         end
237: 
238:         begin
239:           @repo.add('.')
240:         rescue Git::GitExecuteError => e
241:           #raise GitAddFailed, "There was some problem adding this directory to the git changeset"
242:           raise
243:         end
244: 
245:         begin
246:           @repo.commit "Initial commit to #{project_name}."
247:         rescue Git::GitExecuteError => e
248:           raise
249:         end
250: 
251:         begin
252:           @repo.add_remote('origin', git_remote)
253:         rescue Git::GitExecuteError => e
254:           puts "Encountered an error while adding origin remote. Maybe you have some weird settings in ~/.gitconfig?"
255:           raise
256:         end
257:       end
258:     end
mkdir_in_target(directory) click to toggle source
     # File lib/jeweler/generator.rb, line 216
216:     def mkdir_in_target(directory)
217:       final_destination = File.join(target_dir, directory)
218: 
219:       FileUtils.mkdir final_destination
220: 
221:       $stdout.puts "\tcreate\t#{directory}"
222:     end
output_template_in_target(source, destination = source) click to toggle source
     # File lib/jeweler/generator.rb, line 203
203:     def output_template_in_target(source, destination = source)
204:       final_destination = File.join(target_dir, destination)
205:       template_result   = render_template(source)
206: 
207:       File.open(final_destination, 'w') {|file| file.write(template_result)}
208: 
209:       $stdout.puts "\tcreate\t#{destination}"
210:     end
render_template(source) click to toggle source
     # File lib/jeweler/generator.rb, line 195
195:     def render_template(source)
196:       template_contents = File.read(File.join(template_dir, source))
197:       template          = ERB.new(template_contents, nil, '<>')
198: 
199:       # squish extraneous whitespace from some of the conditionals
200:       template.result(binding).gsub(/\n\n\n+/, "\n\n")
201:     end
template_dir() click to toggle source
     # File lib/jeweler/generator.rb, line 212
212:     def template_dir
213:       File.join(File.dirname(__FILE__), 'templates')
214:     end
touch_in_target(destination) click to toggle source
     # File lib/jeweler/generator.rb, line 224
224:     def touch_in_target(destination)
225:       final_destination = File.join(target_dir, destination)
226:       FileUtils.touch  final_destination
227:       $stdout.puts "\tcreate\t#{destination}"
228:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.