Class: Nesta::Commands::Plugin::Create
- Inherits:
-
Object
- Object
- Nesta::Commands::Plugin::Create
- Defined in:
- lib/nesta/commands.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(*args) ⇒ Create
constructor
A new instance of Create.
- #lib_path(*parts) ⇒ Object
- #modify_init_file ⇒ Object
- #modify_required_file ⇒ Object
- #specify_gem_dependency ⇒ Object
Constructor Details
#initialize(*args) ⇒ Create
Returns a new instance of Create.
156 157 158 159 160 161 162 163 164 |
# File 'lib/nesta/commands.rb', line 156 def initialize(*args) name = args.shift name.nil? && (raise UsageError.new('name not specified')) @name = name @gem_name = "nesta-plugin-#{name}" if File.exist?(@gem_name) raise RuntimeError.new("#{@gem_name} already exists") end end |
Instance Method Details
#execute ⇒ Object
218 219 220 221 222 223 224 |
# File 'lib/nesta/commands.rb', line 218 def execute system('bundle', 'gem', @gem_name) modify_required_file modify_init_file specify_gem_dependency Dir.chdir(@gem_name) { system('git', 'add', '.') } end |
#lib_path(*parts) ⇒ Object
166 167 168 |
# File 'lib/nesta/commands.rb', line 166 def lib_path(*parts) File.join(@gem_name, 'lib', *parts) end |
#modify_init_file ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/nesta/commands.rb', line 180 def modify_init_file module_name = @name.split('-').map { |name| name.capitalize }.join('::') File.open(lib_path(@gem_name, 'init.rb'), 'w') do |file| file.puts <<-EOF module Nesta module Plugin module #{module_name} module Helpers # If your plugin needs any helper methods, add them here... end end end class App helpers Nesta::Plugin::#{module_name}::Helpers end end EOF end end |
#modify_required_file ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/nesta/commands.rb', line 170 def modify_required_file File.open(lib_path("#{@gem_name}.rb"), 'w') do |file| file.write <<-EOF require "#{@gem_name}/version" Nesta::Plugin.register(__FILE__) EOF end end |
#specify_gem_dependency ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/nesta/commands.rb', line 201 def specify_gem_dependency gemspec = File.join(@gem_name, "#{@gem_name}.gemspec") File.open(gemspec, 'r+') do |file| output = '' file.each_line do |line| if line =~ /^end/ output << ' gem.add_dependency("nesta", ">= 0.9.11")' + "\n" output << ' gem.add_development_dependency("rake")' + "\n" end output << line end file.pos = 0 file.print(output) file.truncate(file.pos) end end |