skullet 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile.rb ADDED
@@ -0,0 +1,12 @@
1
+ desc "same as rake specs"
2
+ task :default => [:specs]
3
+
4
+ desc "same as rake specs:all"
5
+ task :specs => [:"specs:all"]
6
+ namespace :specs do
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new "all" do |t|
9
+ t.pattern = "spec/**/*_spec.rb"
10
+ t.rspec_opts = ['--color', '--format documentation', '--require spec_helper']
11
+ end
12
+ end
data/Readme.md ADDED
@@ -0,0 +1,54 @@
1
+ skullet
2
+ =======
3
+
4
+ #What is this?
5
+ A (one more) Ruby project skeleton generator, creates the initial dir
6
+ structure.
7
+
8
+ #Why is this?
9
+ * a scratch your own itch gem
10
+
11
+ I don't wanna look for the dir structure and the basic spec files
12
+ every time I need to create a new project, so I decided to automate it.
13
+
14
+ #How is this?
15
+ You install the gem:
16
+
17
+ gem install skullet
18
+
19
+ ##Usage
20
+ If you want to create a project named full_of_awesome, you can use the
21
+ skullet executable:
22
+
23
+ skullet full_of_awesome
24
+
25
+ The current default dir structure is the follow:
26
+
27
+ full_of_awesome/
28
+ -bin/
29
+ full_of_awesome
30
+ -lib/
31
+ full_of_awesome/
32
+ full_of_awesome.rb
33
+ -spec/
34
+ full_of_awesome/
35
+ spec_helper.rb
36
+ .gitignore
37
+ .rvmrc
38
+ Gemfile
39
+ Rakefile.rb
40
+
41
+ ###Rakefile.rb
42
+ The rake tasks created within the Rakefile.rb are listed below:
43
+
44
+ ```
45
+ $ rake -T
46
+ rake default # same as rake specs
47
+ rake specs # same as rake specs:all
48
+ rake specs:all # Run RSpec code examples
49
+ ```
50
+
51
+ ###TODO:
52
+ * add -g parameter to create the git repo after the dir structure
53
+ * add -b parameter to install bundler and run `bundle install`
54
+ * add rdoc to this gem
data/bin/skullet ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path("../../lib", __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+ require 'skullet'
5
+
6
+ cli = Skullet::CLI.new
7
+ cli.run
data/lib/skullet.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'skullet/string_extensions'
2
+ require 'skullet/generator'
3
+ require 'skullet/cli'
4
+
5
+ module Skullet
6
+ VERSION = "0.0.1"
7
+ NAME = "skullet"
8
+ end
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ group :test do
4
+ gem "rspec"
5
+ end
@@ -0,0 +1,12 @@
1
+ desc "same as rake specs"
2
+ task :default => [:specs]
3
+
4
+ desc "same as rake specs:all"
5
+ task :specs => [:"specs:all"]
6
+ namespace :specs do
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new "all" do |t|
9
+ t.pattern = "spec/**/*_spec.rb"
10
+ t.rspec_opts = ['--color', '--format documentation', '--require spec_helper']
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path("../../lib", __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
@@ -0,0 +1,4 @@
1
+ module <%= project_name.camelize %>
2
+ VERSION = "0.0.0"
3
+ NAME = "<%= project_name %>"
4
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+
3
+ require '<%= project_name %>'
@@ -0,0 +1,58 @@
1
+ require 'optparse'
2
+
3
+ module Skullet
4
+
5
+ class CLI
6
+ def initialize(output=STDOUT)
7
+ @out = output
8
+ end
9
+
10
+ def run(args=ARGV)
11
+ options = parse(args)
12
+ generator = args[0] && Generator.new(args[0])
13
+ process(options, generator)
14
+ end
15
+
16
+ private
17
+ def parse(args)
18
+ options = {}
19
+
20
+ @parser ||= OptionParser.new do |args|
21
+ args.banner = banner
22
+
23
+ args.on("-v", "--version", "print the version") do
24
+ options[:version] = true
25
+ end
26
+
27
+ args.on("-h", "--help", "print this help") do
28
+ options[:help] = true
29
+ end
30
+ end
31
+
32
+ @parser.parse!(args)
33
+
34
+ options
35
+ end
36
+
37
+ def banner
38
+ banner = "Usage: #{Skullet::NAME} PROJECT [OPTION]...\n"
39
+ banner << "Generate a Ruby project skeleton"
40
+ end
41
+
42
+ def version
43
+ "#{Skullet::NAME} version #{Skullet::VERSION}"
44
+ end
45
+
46
+ def exit_with(msg, code)
47
+ @out.puts(msg)
48
+ exit(code)
49
+ end
50
+
51
+ def process(options, generator)
52
+ exit_with(version, 0) if options[:version]
53
+ exit_with(@parser.help, 0) if options[:help]
54
+
55
+ generator && generator.make_project
56
+ end
57
+ end# CLI
58
+ end
@@ -0,0 +1,98 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+
4
+ module Skullet
5
+
6
+ class Generator
7
+
8
+ def initialize(project)
9
+ @project = project
10
+
11
+ @base_files_path = File.join(File.expand_path("../", __FILE__), "base_files")
12
+ @project_dir = @project.dup
13
+ end
14
+
15
+ def make_root_dir
16
+ mkdir
17
+ end
18
+
19
+ def make_rake_file
20
+ copy("Rakefile.rb", "Rakefile.rb")
21
+ end
22
+
23
+ def make_bin_dir
24
+ mkdir("bin")
25
+ executable = copy("executable.rb", File.join("bin", @project))
26
+ system("chmod +x #{executable}")
27
+ end
28
+
29
+ def make_spec_dir
30
+ spec_dir = mkdir(File.join("spec", @project))
31
+ file_from_template(File.join("spec", "spec_helper.rb"), "spec_helper.erb")
32
+ end
33
+
34
+ def make_git_repo
35
+ file(".gitignore", ".rvmrc")
36
+ end
37
+
38
+ def make_rvm
39
+ ruby_version = %x(ruby -v).split(" ")[1]
40
+ if ruby_version.include? "p"
41
+ with_patch = ruby_version.split "p"
42
+ ruby_version = "#{with_patch[0]}-p#{with_patch[1]}"
43
+ end
44
+ file(".rvmrc", "rvm #{ruby_version}@#{@project} --create")
45
+ end
46
+
47
+ def make_lib_dir
48
+ project_lib_dir = mkdir(File.join("lib", @project))
49
+ file_from_template(File.join("lib", "#{@project}.rb"), "project_file.erb")
50
+ end
51
+
52
+ def make_bundle
53
+ copy("Gemfile.rb", "Gemfile")
54
+ end
55
+
56
+ def make_project
57
+ make_root_dir
58
+ make_bin_dir
59
+ make_lib_dir
60
+ make_spec_dir
61
+ make_git_repo
62
+ make_rvm
63
+ make_bundle
64
+ make_rake_file
65
+ end
66
+
67
+ private
68
+ def path_to(file_or_dir)
69
+ File.join @project_dir, file_or_dir
70
+ end
71
+
72
+ def file_from_template(file, template_file)
73
+ erb_file = File.join(@base_files_path, template_file)
74
+ tpl = ERB.new(IO.read(erb_file))
75
+ project = @project.dup
76
+ project.class.send(:include, Skullet::StringExtensions)
77
+ bind = Object.new.instance_eval { project_name = project; binding }
78
+ file(file, tpl.result(bind))
79
+ end
80
+
81
+ def mkdir(subdir=nil)
82
+ new_dir = path_to(subdir || "")
83
+ FileUtils.mkdir_p(new_dir)
84
+ new_dir
85
+ end
86
+
87
+ def copy(base_file, dest_file)
88
+ from = File.join @base_files_path, base_file
89
+ to = path_to(dest_file)
90
+ FileUtils.cp(from, to)
91
+ to
92
+ end
93
+
94
+ def file(file, content)
95
+ File.open(path_to(file), "w+") { |f| f.write(content) }
96
+ end
97
+ end# Generator
98
+ end# Skullet
@@ -0,0 +1,19 @@
1
+ module Skullet
2
+ module StringExtensions
3
+
4
+ def camelize
5
+ camelize_feature(self)
6
+ end
7
+
8
+ private
9
+ # the next one is brought to you by rails...
10
+ # File activesupport/lib/active_support/inflector/methods.rb, line 28
11
+ def camelize_feature(lower_case_and_underscored_word, first_letter_in_uppercase = true)
12
+ if first_letter_in_uppercase
13
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
14
+ else
15
+ lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
16
+ end
17
+ end
18
+ end# StringExtensions
19
+ end# Skullet
data/skullet.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib/', __FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "skullet"
8
+ s.version = "0.0.1"
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Ricardo Valeriano"]
11
+ s.email = ["ricardo.valeriano@gmail.com"]
12
+ s.homepage = "http://github.com/ricardovaleriano/gemusta"
13
+ s.summary = "A (one more) Ruby project skeleton generator, creates the initial dir structure."
14
+ s.description = "You don't have look for the dir structure, the basic spec files, a basic .rmvrc file and such everytime you need to create a new Ruby project, automate it!"
15
+
16
+ s.required_rubygems_version = ">= 0"
17
+
18
+ s.add_development_dependency "rspec"
19
+
20
+ s.require_path = 'lib'
21
+
22
+ s.files = ["Rakefile.rb", "Readme.md", "bin/skullet", "lib/skullet.rb", "lib/skullet/base_files/Gemfile.rb", "lib/skullet/base_files/Rakefile.rb", "lib/skullet/base_files/executable.rb", "lib/skullet/base_files/project_file.erb", "lib/skullet/base_files/spec_helper.erb", "lib/skullet/cli.rb", "lib/skullet/generator.rb", "lib/skullet/string_extensions.rb", "skullet.gemspec", "spec/skullet/cli_spec.rb", "spec/skullet/generator_spec.rb", "spec/skullet_spec.rb", "spec/spec_helper.rb"]
23
+ s.test_files = ["spec/skullet/cli_spec.rb", "spec/skullet/generator_spec.rb", "spec/skullet_spec.rb", "spec/spec_helper.rb"]
24
+
25
+
26
+ s.executables = ["skullet"]
27
+
28
+ end
@@ -0,0 +1,43 @@
1
+ module Skullet
2
+
3
+ describe CLI do
4
+
5
+ let(:output) {
6
+ o = Object.new { attr_reader :messages }
7
+ o.instance_eval {
8
+ def puts(msg)
9
+ (@output ||= []) << msg
10
+ end
11
+
12
+ def current
13
+ (@output ||= []).last
14
+ end
15
+ }
16
+ o
17
+ }
18
+
19
+ let(:cli) { CLI.new(output) }
20
+
21
+ def exec
22
+ begin
23
+ yield if block_given?
24
+ rescue SystemExit => e
25
+ return e.status
26
+ end
27
+ end
28
+
29
+ context "command line args" do
30
+
31
+ it "-v, shows the version" do
32
+ string = "#{Skullet::NAME} version #{Skullet::VERSION}"
33
+ output.should_receive(:puts).with(string)
34
+ exec { cli.run(["-v"]) }
35
+ end
36
+
37
+ it "-h, shows help" do
38
+ exec { cli.run(["-h"]) }
39
+ output.current.should include("Usage: #{Skullet::NAME} PROJECT [OPTION]...")
40
+ end
41
+ end# command line args
42
+ end# CLI
43
+ end
@@ -0,0 +1,162 @@
1
+ module Skullet
2
+
3
+ describe Generator do
4
+ let(:project_name) {
5
+ name = "full_of_awesome"
6
+ name.class.send(:include, Skullet::StringExtensions)
7
+ name
8
+ }
9
+ let(:generator) { Generator.new(project_name) }
10
+
11
+ before(:all) { FileUtils.rm_rf project_name }
12
+
13
+ context "project dir" do
14
+
15
+ it "creates the project dir" do
16
+ generator.make_root_dir
17
+ Dir.exists?(project_name).should be_true
18
+ end
19
+
20
+ context "git" do
21
+ before(:all) { generator.make_git_repo }
22
+
23
+ it "creates a .gitignore file" do
24
+ File.exists?("#{project_name}/.gitignore").should be_true
25
+ end
26
+
27
+ it "ignores the .rvmrc file" do
28
+ IO.read("#{project_name}/.gitignore").should include ".rvmrc"
29
+ end
30
+ end# git
31
+
32
+ context "rvm" do
33
+ before(:all) { generator.make_rvm }
34
+ let(:rvmrc) { IO.read(File.join(project_name, ".rvmrc")) }
35
+
36
+ it "creates the .rvmrc file" do
37
+ File.exists?("#{project_name}/.rvmrc").should be_true
38
+ end
39
+
40
+ it "uses current ruby, a gemset named after the project and the option --create" do
41
+ version = %x(ruby -v).split(" ")[1]
42
+ if version.include? "p"
43
+ with_patch = version.split "p"
44
+ version = "#{with_patch[0]}-p#{with_patch[1]}"
45
+ end
46
+ rvmrc.should == "rvm #{version}@#{project_name} --create"
47
+ end
48
+ end# rvm
49
+
50
+ context "Gemfile" do
51
+ before(:all) { generator.make_bundle }
52
+
53
+ it "creates a Gemfile" do
54
+ File.exists?("#{project_name}/Gemfile").should be_true
55
+ end
56
+
57
+ it "includes rspec on Gemfile" do
58
+ IO.read("#{project_name}/Gemfile").should include "gem \"rspec\""
59
+ end
60
+ end# Gemfile
61
+
62
+ context "Rakefile.rb" do
63
+ let(:rakefile) { "#{project_name}/Rakefile.rb" }
64
+
65
+ it "creates the file" do
66
+ generator.make_rake_file
67
+ File.exists?(rakefile).should be_true
68
+ end
69
+
70
+ context "tasks" do
71
+ require 'rake'
72
+
73
+ before(:all) do
74
+ require "./#{rakefile}"
75
+ end
76
+
77
+ it "enables :default" do
78
+ Rake::Task.task_defined?(:default).should be_true
79
+ end
80
+
81
+ it "enables :specs" do
82
+ Rake::Task.task_defined?(:specs).should be_true
83
+ end
84
+
85
+ it "enables specs:all" do
86
+ Rake::Task.task_defined?(:"specs:all").should be_true
87
+ end
88
+ end# tasks
89
+ end# rake file
90
+
91
+ context "bin dir" do
92
+ before :all do
93
+ generator.make_bin_dir
94
+ end
95
+
96
+ it "creates the bin dir" do
97
+ Dir.exists?("#{project_name}/bin").should be_true
98
+ end
99
+
100
+ it "creates the file" do
101
+ File.exists?("#{project_name}/bin/#{project_name}").should be_true
102
+ end
103
+
104
+ it "should be executable" do
105
+ File.executable?("#{project_name}/bin/#{project_name}").should be_true
106
+ end
107
+ end# bin dir
108
+
109
+ context "lib dir" do
110
+ before :all do
111
+ generator.make_lib_dir
112
+ end
113
+
114
+ it "creates de lib dir" do
115
+ Dir.exists?("#{project_name}/lib").should be_true
116
+ end
117
+
118
+ it "creates the project dir" do
119
+ Dir.exists?("#{project_name}/lib/#{project_name}").should be_true
120
+ end
121
+
122
+ context "project file" do
123
+
124
+ it "creates the file" do
125
+ File.exists?("#{project_name}/lib/#{project_name}.rb").should be_true
126
+ end
127
+
128
+ it "creates the module for the project" do
129
+ require "./#{project_name}/lib/#{project_name}.rb"
130
+ Object.const_defined?(project_name.camelize).should be_true
131
+ end
132
+
133
+ it "defines a version constant within the module" do
134
+ m = Object.const_get(project_name.camelize)
135
+ m::VERSION.should == "0.0.0"
136
+ end
137
+ end# project file
138
+ end# lib dir
139
+
140
+ context "spec dir" do
141
+ before :all do
142
+ generator.make_spec_dir
143
+ end
144
+
145
+ it "generate a spec dir" do
146
+ Dir.exists?("#{project_name}/spec").should be_true
147
+ end
148
+
149
+ it "generates a subdir on spec with the project name" do
150
+ Dir.exists?("#{project_name}/spec/#{project_name}").should be_true
151
+ end
152
+
153
+ it "creates the spec_helper.rb file" do
154
+ File.exists?("#{project_name}/spec/spec_helper.rb").should be_true
155
+ end
156
+ end # spec dir
157
+ end# project dir
158
+
159
+ after(:all) { FileUtils.rm_rf project_name }
160
+
161
+ end # Generator
162
+ end
@@ -0,0 +1,91 @@
1
+ module Skullet
2
+
3
+ describe "happy path, project creation using the executable" do
4
+
5
+ let(:executable) { File.expand_path("../../bin/skullet", __FILE__) }
6
+ let(:temp) do
7
+ temp = File.expand_path("../temp", __FILE__)
8
+ FileUtils.mkdir_p(temp)
9
+ temp
10
+ end
11
+ let(:project) { "project_test" }
12
+ let(:project_dir) { File.join(temp, project) }
13
+
14
+ before(:all) do
15
+ @current_path = Dir.pwd
16
+ FileUtils.chdir(temp)
17
+ end
18
+
19
+ it "-v, shows the version" do
20
+ %x(#{executable} -v).should include(Skullet::VERSION)
21
+ end
22
+
23
+ context "basic project structure" do
24
+ before(:all) do
25
+ system "#{executable} #{project}"
26
+ end
27
+
28
+ it "creates the project dir" do
29
+ Dir.exists?(project_dir).should be_true
30
+ end
31
+
32
+ it "creates the bin dir" do
33
+ Dir.exists?(File.join(project_dir, "bin")).should be_true
34
+ end
35
+
36
+ it "creates the executable" do
37
+ bin = File.join(project_dir, "bin")
38
+ File.exists?(File.join(bin, project)).should be_true
39
+ end
40
+
41
+ it "creates the lib dir" do
42
+ Dir.exists?(File.join(project_dir, "lib")).should be_true
43
+ end
44
+
45
+ it "creates the project dir" do
46
+ lib = File.join(project_dir, "lib")
47
+ Dir.exists?(File.join(lib, "#{project}")).should be_true
48
+ end
49
+
50
+ it "creates the project file" do
51
+ lib = File.join(project_dir, "lib")
52
+ File.exists?(File.join(lib, "#{project}.rb")).should be_true
53
+ end
54
+
55
+ it "creates the spec dir" do
56
+ Dir.exists?(File.join(project_dir, "spec")).should be_true
57
+ end
58
+
59
+ it "creates the application spec dir" do
60
+ spec = File.join(project_dir, "spec")
61
+ Dir.exists?(File.join(spec, project)).should be_true
62
+ end
63
+
64
+ it "creates the spec helper file" do
65
+ spec = File.join(project_dir, "spec")
66
+ File.exists?(File.join(spec, "spec_helper.rb")).should be_true
67
+ end
68
+
69
+ it "creates the .gitignore" do
70
+ File.exists?(File.join(project_dir, ".gitignore")).should be_true
71
+ end
72
+
73
+ it "creates the .rvmrc" do
74
+ File.exists?(File.join(project_dir, ".rvmrc")).should be_true
75
+ end
76
+
77
+ it "creates the Gemfile" do
78
+ File.exists?(File.join(project_dir, "Gemfile")).should be_true
79
+ end
80
+
81
+ it "creates the Rakefile.rb" do
82
+ File.exists?(File.join(project_dir, "Rakefile.rb")).should be_true
83
+ end
84
+ end# basic project structure
85
+
86
+ after(:all) do
87
+ FileUtils.chdir(@current_path)
88
+ FileUtils.rm_rf(temp)
89
+ end
90
+ end# happy path
91
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+
3
+ require 'skullet'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,46 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-14 00:00:00.000000000Z
13
- dependencies: []
14
- description: Just a simple and light Ruby app Skeleton generator
12
+ date: 2012-01-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70231419247320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70231419247320
25
+ description: You don't have look for the dir structure, the basic spec files, a basic
26
+ .rmvrc file and such everytime you need to create a new Ruby project, automate it!
15
27
  email:
16
28
  - ricardo.valeriano@gmail.com
17
- executables: []
29
+ executables:
30
+ - skullet
18
31
  extensions: []
19
32
  extra_rdoc_files: []
20
- files: []
21
- homepage: http://github.com/ricardovaleriano/skullet
33
+ files:
34
+ - Rakefile.rb
35
+ - Readme.md
36
+ - bin/skullet
37
+ - lib/skullet.rb
38
+ - lib/skullet/base_files/Gemfile.rb
39
+ - lib/skullet/base_files/Rakefile.rb
40
+ - lib/skullet/base_files/executable.rb
41
+ - lib/skullet/base_files/project_file.erb
42
+ - lib/skullet/base_files/spec_helper.erb
43
+ - lib/skullet/cli.rb
44
+ - lib/skullet/generator.rb
45
+ - lib/skullet/string_extensions.rb
46
+ - skullet.gemspec
47
+ - spec/skullet/cli_spec.rb
48
+ - spec/skullet/generator_spec.rb
49
+ - spec/skullet_spec.rb
50
+ - spec/spec_helper.rb
51
+ homepage: http://github.com/ricardovaleriano/gemusta
22
52
  licenses: []
23
53
  post_install_message:
24
54
  rdoc_options: []
@@ -41,5 +71,9 @@ rubyforge_project:
41
71
  rubygems_version: 1.8.13
42
72
  signing_key:
43
73
  specification_version: 3
44
- summary: Ruby project skeleton generator
45
- test_files: []
74
+ summary: A (one more) Ruby project skeleton generator, creates the initial dir structure.
75
+ test_files:
76
+ - spec/skullet/cli_spec.rb
77
+ - spec/skullet/generator_spec.rb
78
+ - spec/skullet_spec.rb
79
+ - spec/spec_helper.rb