Class: Palco::Extension

Inherits:
Base
  • Object
show all
Defined in:
lib/palco/extension.rb

Constant Summary collapse

FILE_LIST =
[
  {:name=>'README', :file=>true}, 
  {:name=>'LICENSE', :file=>true},
  {:name=>'Rakefile', :file=>true},
  {:name=>'lib', :file=>false},
  {:name=>'lib/sinatra', :file=>false}, 
  {:name=>'spec', :file=>false},
  {:name=>'spec/spec_helper.rb', :file=>true},
  {:name=>'LICENSE', :file=>true},
]

Instance Attribute Summary

Attributes inherited from Base

#generated, #items_list, #project_name, #valid

Instance Method Summary collapse

Methods inherited from Base

#can_generate?, #destroy, #generated?, #valid?

Constructor Details

#initialize(name) ⇒ Extension

Public: creates a new Sinatra Extension skeleton

The idea is to pack the extension as a rubygem as described here: www.sinatrarb.com/extensions.html

Example

ext = Palco::Extension.new('testme')
ext.generate

Returns

A new Sinatra extension directory read to be packed as a rubygem


26
27
28
29
30
31
32
33
34
# File 'lib/palco/extension.rb', line 26

def initialize(name)
  @r = name
  list = FILE_LIST 
  list = list << {:name=>"lib/sinatra/version.rb", :file=>true}
  list = list << {:name=>"spec/sinatra_#{name}_spec.rb", :file=>true}
  list = list << {:name=>"sinatra_#{name}.gemspec", :file=>true}

  super(name, list)
end

Instance Method Details

#generateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/palco/extension.rb', line 36

def generate
  super
  license = Palco::License.new(@r)
  license.create
  gemspec = Palco::Gemspec.new(@r)
  gemspec.create

  file = Palco::FileBase.new(@r, "lib/sinatra/version.rb")
  file.file_content = "module #{@r.capitalize}\nVERSION=\"0.0.0\"\nend\n"
  file.create

  file = Palco::FileBase.new(@r, "spec/spec_helper.rb")
  file.file_content = "require '#{@r}'\n"
  file.create

  file = Palco::FileBase.new(@r, "lib/sinatra/#{@r}.rb")
  file.file_content ="require 'sinatra/base'\n\nmodule Sinatra\nmodule #{@r.capitalize}\nend\nregister #{@r}\nend\n"
  file.create

 
end