reagent-simple-gem 0.3.1 → 0.3.2

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 CHANGED
@@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
17
17
  s.email = 'reaganpr@gmail.com'
18
18
  s.homepage = 'http://sneaq.net'
19
19
  s.executables = ['simple-gem']
20
- s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test,templates}/**/.?*")
20
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test,templates}/**/*")
21
21
  end
22
22
 
23
23
  Rake::GemPackageTask.new(spec) do |pkg|
data/lib/simple_gem.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'simple_gem/version'
2
+ require 'simple_gem/gem'
@@ -0,0 +1,61 @@
1
+ require 'erb'
2
+
3
+ module SimpleGem
4
+ class Gem
5
+
6
+ attr_reader :root_path, :name
7
+
8
+ def initialize(path, name)
9
+ @root_path = path
10
+ self.name = name
11
+ end
12
+
13
+ def name=(name)
14
+ @name = name.gsub(/([A-Z])([a-z])/, '_\1\2').sub(/^_/, '').downcase
15
+ end
16
+
17
+ def module_name
18
+ transform_name {|part| part.capitalize }
19
+ end
20
+
21
+ def ruby_name
22
+ transform_name('_') {|part| part.downcase }
23
+ end
24
+
25
+ def generate
26
+ generate_root_directory
27
+ generate_subdirectories
28
+ generate_file('gitignore.erb', '.gitignore')
29
+ generate_file('lib.rb.erb', "lib/#{self.ruby_name}.rb")
30
+ generate_file('lib_version.rb.erb', "lib/#{self.ruby_name}/version.rb")
31
+ generate_file('Rakefile.erb', 'Rakefile')
32
+ generate_file('README.rdoc.erb', 'README.rdoc')
33
+ generate_file('test_helper.rb.erb', 'test/test_helper.rb')
34
+ generate_file('test.rb.erb', "test/unit/#{self.ruby_name}_test.rb")
35
+ end
36
+
37
+ private
38
+ def transform_name(glue = nil, &block)
39
+ self.name.split(/[_-]/).map {|part| block.call(part) }.join(glue)
40
+ end
41
+
42
+ def generate_root_directory
43
+ FileUtils.mkdir("#{self.root_path}/#{self.name}")
44
+ end
45
+
46
+ def generate_subdirectories
47
+ ['lib', 'test', "lib/#{self.ruby_name}", 'test/unit'].each do |dir|
48
+ FileUtils.mkdir("#{self.root_path}/#{self.name}/#{dir}")
49
+ end
50
+ end
51
+
52
+ def generate_file(source, output)
53
+ source_file = File.dirname(__FILE__) + "/../../templates/#{source}"
54
+ output_file = "#{self.root_path}/#{self.name}/#{output}"
55
+
56
+ erb = ERB.new(File.read(source_file))
57
+ File.open(output_file, 'w') {|f| f << erb.result(binding) }
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ module SimpleGem
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 3
6
+ TINY = 2
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ = <%= self.module_name %>
2
+
3
+ == Description
4
+
5
+ Describe your gem here ...
6
+
7
+ == Installation
8
+
9
+ sudo gem install <%= self.name %>
10
+
11
+ == Usage
12
+
13
+ require '<%= self.ruby_name %>'
14
+
15
+ == License
16
+
17
+ Copyright (c) <year> <copyright holders>
18
+
19
+ Permission is hereby granted, free of charge, to any person
20
+ obtaining a copy of this software and associated documentation
21
+ files (the "Software"), to deal in the Software without
22
+ restriction, including without limitation the rights to use,
23
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ copies of the Software, and to permit persons to whom the
25
+ Software is furnished to do so, subject to the following
26
+ conditions:
27
+
28
+ The above copyright notice and this permission notice shall be
29
+ included in all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
33
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
35
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
36
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
38
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+
5
+ require 'lib/<%= self.ruby_name %>/version'
6
+
7
+ task :default => :test
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = '<%= self.name %>'
11
+ s.version = <%= self.module_name %>::Version.to_s
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w(README.rdoc)
14
+ s.rdoc_options = %w(--main README.rdoc)
15
+ s.summary = "This gem does ... "
16
+ s.author = 'First Last'
17
+ s.email = 'user@example.com'
18
+ s.homepage = 'http://my-site.net'
19
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
20
+ # s.executables = ['<%= self.name %>']
21
+
22
+ # s.add_dependency('gem_name', '~> 0.0.1')
23
+ end
24
+
25
+ Rake::GemPackageTask.new(spec) do |pkg|
26
+ pkg.gem_spec = spec
27
+ end
28
+
29
+ Rake::TestTask.new do |t|
30
+ t.libs << 'test'
31
+ t.test_files = FileList["test/**/*_test.rb"]
32
+ t.verbose = true
33
+ end
34
+
35
+ desc 'Generate the gemspec to serve this Gem from Github'
36
+ task :github do
37
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
38
+ File.open(file, 'w') {|f| f << spec.to_ruby }
39
+ puts "Created gemspec: #{file}"
40
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ # require '<%= self.ruby_name %>/...'
@@ -0,0 +1,13 @@
1
+ module <%= self.module_name %>
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 0
7
+
8
+ def self.to_s # :nodoc:
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class <%= self.module_name %>Test < Test::Unit::TestCase
4
+
5
+ describe "An instance of the <%= self.module_name %> class" do
6
+
7
+ it "should flunk" do
8
+ flunk "Please provide some tests"
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ # http://sneaq.net/textmate-wtf
2
+ $:.reject! { |e| e.include? 'TextMate' }
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'matchy'
7
+ require 'context'
8
+ require 'mocha'
9
+
10
+ require File.dirname(__FILE__) + '/../lib/<%= self.ruby_name %>'
@@ -0,0 +1,113 @@
1
+ require 'rubygems'
2
+ require 'context'
3
+ require 'matchy'
4
+
5
+ require File.dirname(__FILE__) + '/../../lib/simple_gem/gem'
6
+
7
+ module SimpleGem
8
+ class GemTest < Test::Unit::TestCase
9
+
10
+ def self.should_generate(expectations)
11
+ name = expectations[:from].sub(/\W/, '')
12
+ describe "An instance of Gem when given the name: #{name} name" do
13
+ before do
14
+ path = '/this/path'
15
+ @name = expectations[:from]
16
+ @gem = Gem.new(path, @name)
17
+ end
18
+
19
+ expectations.each do |k,v|
20
+ unless k == :from
21
+ it "should know its #{k}" do
22
+ @gem.send(k).should == v
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ should_generate :name => 'simple_gem',
30
+ :module_name => 'SimpleGem',
31
+ :ruby_name => 'simple_gem',
32
+ :from => 'SimpleGem'
33
+
34
+
35
+ should_generate :name => 'simple-gem',
36
+ :module_name => 'SimpleGem',
37
+ :ruby_name => 'simple_gem',
38
+ :from => 'simple-gem'
39
+
40
+ should_generate :name => 'simple_gem',
41
+ :module_name => 'SimpleGem',
42
+ :ruby_name => 'simple_gem',
43
+ :from => 'simple_gem'
44
+
45
+ should_generate :name => 'simple_gem',
46
+ :module_name => 'SimpleGem',
47
+ :ruby_name => 'simple_gem',
48
+ :from => 'simpleGem'
49
+
50
+ describe "An instance of Gem" do
51
+ before { @path = '/this/path' }
52
+
53
+ it "should know its root path" do
54
+ Gem.new(@path, 'name').root_path.should == @path
55
+ end
56
+
57
+ context "when generating the directory structure" do
58
+
59
+ before do
60
+ @tmp_dir = File.dirname(__FILE__) + '/../../tmp'
61
+ FileUtils.mkdir(@tmp_dir) unless File.exist?(@tmp_dir)
62
+
63
+ @name = 'simple-gem'
64
+ Gem.new(@tmp_dir, @name).generate
65
+ end
66
+
67
+ after do
68
+ FileUtils.rm_rf(@tmp_dir)
69
+ end
70
+
71
+ it "should be able to make the root directory" do
72
+ File.exist?("#{@tmp_dir}/#{@name}").should == true
73
+ end
74
+
75
+ %w(lib test lib/simple_gem test/unit).each do |dir|
76
+ it "should create the #{dir} subdirectory" do
77
+ File.exist?("#{@tmp_dir}/#{@name}/#{dir}").should == true
78
+ end
79
+ end
80
+
81
+ it "should create the main library file" do
82
+ File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem.rb").should == true
83
+ end
84
+
85
+ it "should create the version file" do
86
+ File.exist?("#{@tmp_dir}/#{@name}/lib/simple_gem/version.rb").should == true
87
+ end
88
+
89
+ it "should create the main Rakefile" do
90
+ File.exist?("#{@tmp_dir}/#{@name}/Rakefile").should == true
91
+ end
92
+
93
+ it "should create the README file" do
94
+ File.exist?("#{@tmp_dir}/#{@name}/README.rdoc").should == true
95
+ end
96
+
97
+ it "should generate the test helper file" do
98
+ File.exist?("#{@tmp_dir}/#{@name}/test/test_helper.rb").should == true
99
+ end
100
+
101
+ it "should generate the test file" do
102
+ File.exist?("#{@tmp_dir}/#{@name}/test/unit/simple_gem_test.rb").should == true
103
+ end
104
+
105
+ it "should generate the .gitignore file" do
106
+ File.exist?("#{@tmp_dir}/#{@name}/.gitignore").should == true
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+ end
113
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reagent-simple-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Reagan
@@ -24,12 +24,19 @@ extra_rdoc_files:
24
24
  files:
25
25
  - README.rdoc
26
26
  - Rakefile
27
- - lib/..
28
- - lib/simple_gem/..
29
- - test/..
30
- - test/simple_gem/..
31
- - templates/..
32
- - templates/.gitignore.erb
27
+ - lib/simple_gem
28
+ - lib/simple_gem/gem.rb
29
+ - lib/simple_gem/version.rb
30
+ - lib/simple_gem.rb
31
+ - test/simple_gem
32
+ - test/simple_gem/gem_test.rb
33
+ - templates/gitignore.erb
34
+ - templates/lib.rb.erb
35
+ - templates/lib_version.rb.erb
36
+ - templates/Rakefile.erb
37
+ - templates/README.rdoc.erb
38
+ - templates/test.rb.erb
39
+ - templates/test_helper.rb.erb
33
40
  - bin/simple-gem
34
41
  has_rdoc: true
35
42
  homepage: http://sneaq.net