Class: Tumbler::Generate
- Inherits:
-
Object
- Object
- Tumbler::Generate
- Defined in:
- lib/tumbler/generate.rb
Constant Summary
Constants included from Informer
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#changelog ⇒ Object
Returns the value of attribute changelog.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#development_dependencies ⇒ Object
readonly
Returns the value of attribute development_dependencies.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
Attributes included from Runner
Class Method Summary collapse
Instance Method Summary collapse
- #config_file ⇒ Object
- #constant_name ⇒ Object
-
#copy_template(template_file, options = {}) ⇒ Object
copy_template(‘generic.rb.erb’, :to => ‘/path/to/file’).
- #gemfile_file ⇒ Object
- #gemspec_file ⇒ Object
- #git_email ⇒ Object
- #git_name ⇒ Object
- #github_user ⇒ Object
- #initial_commit ⇒ Object
-
#initialize(dir, name) ⇒ Generate
constructor
A new instance of Generate.
- #rb_path ⇒ Object
- #template_path(path) ⇒ Object
- #version_path ⇒ Object
- #write ⇒ Object
- #write_changelog ⇒ Object
- #write_file ⇒ Object
- #write_gemfile ⇒ Object
- #write_gemspec ⇒ Object
- #write_rakefile ⇒ Object
- #write_tumbler_config ⇒ Object
- #write_version(version) ⇒ Object
Methods included from Informer
Methods included from Runner
Constructor Details
#initialize(dir, name) ⇒ Generate
Returns a new instance of Generate.
31 32 33 34 35 36 37 38 |
# File 'lib/tumbler/generate.rb', line 31 def initialize(dir, name) @base = dir @name = name @dependencies = [] @development_dependencies = [] @version = Manager::Version::INITIAL_VERSION @changelog = Manager::Changelog::DEFAULT_FILE end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
28 29 30 |
# File 'lib/tumbler/generate.rb', line 28 def base @base end |
#changelog ⇒ Object
Returns the value of attribute changelog.
29 30 31 |
# File 'lib/tumbler/generate.rb', line 29 def changelog @changelog end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
28 29 30 |
# File 'lib/tumbler/generate.rb', line 28 def dependencies @dependencies end |
#development_dependencies ⇒ Object (readonly)
Returns the value of attribute development_dependencies.
28 29 30 |
# File 'lib/tumbler/generate.rb', line 28 def development_dependencies @development_dependencies end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/tumbler/generate.rb', line 28 def name @name end |
#version ⇒ Object
Returns the value of attribute version.
29 30 31 |
# File 'lib/tumbler/generate.rb', line 29 def version @version end |
Class Method Details
.app(dir, name, opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tumbler/generate.rb', line 10 def self.app(dir, name, opts = {}) generator = Generate.new(dir, name) generator.version = opts[:version] if opts[:version] generator.changelog = opts[:changelog] if opts.key?(:changelog) generator.development_dependencies << ::Gem::Dependency.new('tumbler') if opts[:dependencies] Array(opts[:dependencies]).each do |dep| generator.dependencies << (dep.is_a?(Array) ? ::Gem::Dependency.new(*dep) : ::Gem::Dependency.new(dep)) end end if opts[:development_dependencies] Array(opts[:development_dependencies]).each do |dep| generator.development_dependencies << (dep.is_a?(Array) ? ::Gem::Dependency.new(*dep) : ::Gem::Dependency.new(dep)) end end generator end |
Instance Method Details
#config_file ⇒ Object
76 77 78 |
# File 'lib/tumbler/generate.rb', line 76 def config_file File.join(@base, 'Tumbler') end |
#constant_name ⇒ Object
40 41 42 43 44 |
# File 'lib/tumbler/generate.rb', line 40 def constant_name result = @name.split('_').map{|p| p.capitalize}.join result = result.split('-').map{|q| q.capitalize}.join('::') if result =~ /-/ result end |
#copy_template(template_file, options = {}) ⇒ Object
copy_template(‘generic.rb.erb’, :to => ‘/path/to/file’)
139 140 141 142 143 144 |
# File 'lib/tumbler/generate.rb', line 139 def copy_template(template_file, ={}) FileUtils.mkdir_p(File.dirname([:to])) template = ERB.new(File.read(template_path(template_file)), 0, '<>') contents = template.result([:binding] || binding) File.open([:to], 'w') {|f| f << contents } end |
#gemfile_file ⇒ Object
68 69 70 |
# File 'lib/tumbler/generate.rb', line 68 def gemfile_file File.join(@base, 'Gemfile') end |
#gemspec_file ⇒ Object
72 73 74 |
# File 'lib/tumbler/generate.rb', line 72 def gemspec_file File.join(@base, "#{@name}.gemspec") end |
#git_email ⇒ Object
122 123 124 |
# File 'lib/tumbler/generate.rb', line 122 def git_email sh('git config user.email').strip rescue 'user.email' end |
#git_name ⇒ Object
126 127 128 |
# File 'lib/tumbler/generate.rb', line 126 def git_name sh('git config user.name').strip rescue 'user.name' end |
#github_user ⇒ Object
130 131 132 |
# File 'lib/tumbler/generate.rb', line 130 def github_user sh('git config github.user').strip rescue 'github.user' end |
#initial_commit ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/tumbler/generate.rb', line 60 def initial_commit inform "Performing initial commit" sh 'git init' sh 'git add .' sh 'git commit -a -m"Initial commit"' sh "git tag #{@version}" end |
#rb_path ⇒ Object
84 85 86 |
# File 'lib/tumbler/generate.rb', line 84 def rb_path File.join(@base, 'lib', "#{@name}.rb") end |
#template_path(path) ⇒ Object
134 135 136 |
# File 'lib/tumbler/generate.rb', line 134 def template_path(path) File.join(File.dirname(__FILE__), '..', 'template', path) end |
#version_path ⇒ Object
80 81 82 |
# File 'lib/tumbler/generate.rb', line 80 def version_path File.join(@base, 'lib', @name, 'version.rb') end |
#write ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tumbler/generate.rb', line 46 def write inform "Generating gem #{name}" do write_gemspec write_gemfile write_version(@version) write_file write_changelog write_rakefile write_tumbler_config sh 'git init' initial_commit end end |
#write_changelog ⇒ Object
88 89 90 91 |
# File 'lib/tumbler/generate.rb', line 88 def write_changelog inform "Writing changelog file" File.open(File.join(@base, @changelog), 'w') {|f| f << '' } if @changelog end |
#write_file ⇒ Object
98 99 100 |
# File 'lib/tumbler/generate.rb', line 98 def write_file copy_template('generic.rb.erb', :to => rb_path) end |
#write_gemfile ⇒ Object
107 108 109 110 |
# File 'lib/tumbler/generate.rb', line 107 def write_gemfile inform "Writing Gemfile" copy_template('Gemfile.erb', :to => gemfile_file) end |
#write_gemspec ⇒ Object
112 113 114 115 |
# File 'lib/tumbler/generate.rb', line 112 def write_gemspec inform "Writing #{name}.gemspec" copy_template('generic.gemspec.erb', :to => gemspec_file) end |
#write_rakefile ⇒ Object
93 94 95 96 |
# File 'lib/tumbler/generate.rb', line 93 def write_rakefile inform "Writing Rakefile" FileUtils.cp(template_path('Rakefile'), @base) end |
#write_tumbler_config ⇒ Object
117 118 119 120 |
# File 'lib/tumbler/generate.rb', line 117 def write_tumbler_config inform "Writing Tumbler config" copy_template('Tumbler.erb', :to => config_file) end |
#write_version(version) ⇒ Object
102 103 104 105 |
# File 'lib/tumbler/generate.rb', line 102 def write_version(version) inform "Writing version file" copy_template('version.rb.erb', :to => version_path, :binding => binding) end |