namelessjon-dm-gen 0.0.4 → 0.1.0
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/lib/dm_gen.rb +1 -0
- data/lib/generators/is.rb +43 -0
- data/lib/templates/is/History.txt +4 -0
- data/lib/templates/is/LICENSE +20 -0
- data/lib/templates/is/Manifest.txt +14 -0
- data/lib/templates/is/README.txt +3 -0
- data/lib/templates/is/Rakefile +30 -0
- data/lib/templates/is/TODO +0 -0
- data/lib/templates/is/lib/%gem_name%.rb +20 -0
- data/lib/templates/is/lib/%gem_name%/is/%snake_name%.rb +38 -0
- data/lib/templates/is/lib/%gem_name%/is/version.rb +7 -0
- data/lib/templates/is/spec/integration/%snake_name%_spec.rb +8 -0
- data/lib/templates/is/spec/spec.opts +1 -0
- data/lib/templates/is/spec/spec_helper.rb +26 -0
- data/lib/templates/is/tasks/install.rb +13 -0
- data/lib/templates/is/tasks/spec.rb +25 -0
- data/spec/is_plugin_spec.rb +41 -0
- metadata +30 -5
data/lib/dm_gen.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module DMGen
|
2
|
+
class Is < Templater::Generator
|
3
|
+
first_argument :name, :required => true
|
4
|
+
|
5
|
+
desc <<-eos
|
6
|
+
Generates an 'is' plugin for DataMapper, such as dm-is-list.
|
7
|
+
|
8
|
+
Use like
|
9
|
+
dm-gen is plugin
|
10
|
+
|
11
|
+
This generates the full plugin structure with skeleton code and specs, as
|
12
|
+
well as a Rakefile. All it needs is a README and some real functionality.
|
13
|
+
|
14
|
+
eos
|
15
|
+
|
16
|
+
def self.source_root
|
17
|
+
File.join(File.dirname(__FILE__), '..', 'templates', 'is')
|
18
|
+
end
|
19
|
+
|
20
|
+
def gem_name
|
21
|
+
"dm-is-#{snake_name}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def snake_name
|
25
|
+
name.snake_case
|
26
|
+
end
|
27
|
+
|
28
|
+
def class_name
|
29
|
+
name.camel_case
|
30
|
+
end
|
31
|
+
|
32
|
+
def destination_root
|
33
|
+
File.join(@destination_root, gem_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
# glob the template dir for all templates.
|
37
|
+
# since we want text files processed, we have to replace the default
|
38
|
+
# extension list.
|
39
|
+
glob!('', %w[rb txt Rakefile LICENSE TODO])
|
40
|
+
end
|
41
|
+
|
42
|
+
add :is, Is
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 John Doe
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
History.txt
|
2
|
+
LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
TODO
|
7
|
+
lib/<%= gem_name %>.rb
|
8
|
+
lib/<%= gem_name %>/is/<%= snake_name %>.rb
|
9
|
+
lib/<%= gem_name %>/is/version.rb
|
10
|
+
spec/integration/<%= snake_name %>_spec.rb
|
11
|
+
spec/spec.opts
|
12
|
+
spec/spec_helper.rb
|
13
|
+
tasks/spec.rb
|
14
|
+
tasks/install.rb
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'hoe'
|
4
|
+
|
5
|
+
ROOT = Pathname(__FILE__).dirname.expand_path
|
6
|
+
JRUBY = RUBY_PLATFORM =~ /java/
|
7
|
+
WINDOWS = Gem.win_platform?
|
8
|
+
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
|
9
|
+
|
10
|
+
require ROOT + 'lib/<%= gem_name %>/is/version'
|
11
|
+
|
12
|
+
# define some constants to help with task files
|
13
|
+
GEM_NAME = '<%= gem_name %>'
|
14
|
+
GEM_VERSION = DataMapper::Is::<%= class_name %>::VERSION
|
15
|
+
|
16
|
+
Hoe.new(GEM_NAME, GEM_VERSION) do |p|
|
17
|
+
p.developer('John Doe', 'john [a] doe [d] com')
|
18
|
+
|
19
|
+
p.description = 'A DataMapper plugin that ...'
|
20
|
+
p.summary = 'A DataMapper plugin that ...'
|
21
|
+
p.url = 'http://github.com/USERNAME/<%= gem_name %>'
|
22
|
+
|
23
|
+
p.clean_globs |= %w[ log pkg coverage ]
|
24
|
+
p.spec_extras = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] }
|
25
|
+
|
26
|
+
p.extra_deps << [['dm-core', "~> 0.9.10"]]
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Needed to import datamapper and other gems
|
2
|
+
require 'rubygems'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# Add all external dependencies for the plugin here
|
6
|
+
gem 'dm-core', '~>0.9.10'
|
7
|
+
require 'dm-core'
|
8
|
+
|
9
|
+
# Require plugin-files
|
10
|
+
require Pathname(__FILE__).dirname.expand_path / '<%= gem_name %>' / 'is' / '<%= snake_name %>.rb'
|
11
|
+
|
12
|
+
|
13
|
+
# Include the plugin in Resource
|
14
|
+
module DataMapper
|
15
|
+
module Resource
|
16
|
+
module ClassMethods
|
17
|
+
include DataMapper::Is::<%= class_name %>
|
18
|
+
end # module ClassMethods
|
19
|
+
end # module Resource
|
20
|
+
end # module DataMapper
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Is
|
3
|
+
module <%= class_name %>
|
4
|
+
|
5
|
+
##
|
6
|
+
# fired when your plugin gets included into Resource
|
7
|
+
#
|
8
|
+
def self.included(base)
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# Methods that should be included in DataMapper::Model.
|
14
|
+
# Normally this should just be your generator, so that the namespace
|
15
|
+
# does not get cluttered. ClassMethods and InstanceMethods gets added
|
16
|
+
# in the specific resources when you fire is :<%= snake_name %>
|
17
|
+
##
|
18
|
+
|
19
|
+
def is_<%= snake_name %>(options)
|
20
|
+
|
21
|
+
# Add class-methods
|
22
|
+
extend DataMapper::Is::<%= class_name %>::ClassMethods
|
23
|
+
# Add instance-methods
|
24
|
+
include DataMapper::Is::<%= class_name %>::InstanceMethods
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
|
30
|
+
end # ClassMethods
|
31
|
+
|
32
|
+
module InstanceMethods
|
33
|
+
|
34
|
+
end # InstanceMethods
|
35
|
+
|
36
|
+
end # <%= class_name %>
|
37
|
+
end # Is
|
38
|
+
end # DataMapper
|
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
gem 'rspec', '~>1.1.11'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/<%= gem_name %>'
|
8
|
+
|
9
|
+
def load_driver(name, default_uri)
|
10
|
+
return false if ENV['ADAPTER'] != name.to_s
|
11
|
+
|
12
|
+
begin
|
13
|
+
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
14
|
+
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
15
|
+
true
|
16
|
+
rescue LoadError => e
|
17
|
+
warn "Could not load do_#{name}: #{e}"
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ENV['ADAPTER'] ||= 'sqlite3'
|
23
|
+
|
24
|
+
HAS_SQLITE3 = load_driver(:sqlite3, 'sqlite3::memory:')
|
25
|
+
HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test')
|
26
|
+
HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
def sudo_gem(cmd)
|
2
|
+
sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
|
3
|
+
end
|
4
|
+
|
5
|
+
desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
6
|
+
task :install => [ :package ] do
|
7
|
+
sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
|
11
|
+
task :uninstall => [ :clobber ] do
|
12
|
+
sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
gem 'rspec', '~>1.1.11'
|
3
|
+
require 'spec'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
task :default => [ :spec ]
|
7
|
+
|
8
|
+
desc 'Run specifications'
|
9
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
10
|
+
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
11
|
+
t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
|
12
|
+
|
13
|
+
begin
|
14
|
+
gem 'rcov', '~>0.8'
|
15
|
+
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
16
|
+
t.rcov_opts << '--exclude' << 'spec'
|
17
|
+
t.rcov_opts << '--text-summary'
|
18
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
19
|
+
rescue LoadError
|
20
|
+
# rcov not installed
|
21
|
+
end
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
# rspec not installed
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "DMGen::OneFile" do
|
4
|
+
before do
|
5
|
+
@generator = DMGen::Is.new('/tmp', {}, 'awesome')
|
6
|
+
end
|
7
|
+
|
8
|
+
# basic file creation.
|
9
|
+
it "creates a Rakefile" do
|
10
|
+
@generator.should create('/tmp/dm-is-awesome/Rakefile')
|
11
|
+
end
|
12
|
+
it "creates the lib folder layout" do
|
13
|
+
@generator.should create('/tmp/dm-is-awesome/lib/dm-is-awesome.rb')
|
14
|
+
@generator.should create('/tmp/dm-is-awesome/lib/dm-is-awesome/is/version.rb')
|
15
|
+
@generator.should create('/tmp/dm-is-awesome/lib/dm-is-awesome/is/awesome.rb')
|
16
|
+
end
|
17
|
+
it "creates the spec folder layout" do
|
18
|
+
@generator.should create('/tmp/dm-is-awesome/spec/integration/awesome_spec.rb')
|
19
|
+
@generator.should create('/tmp/dm-is-awesome/spec/spec.opts')
|
20
|
+
@generator.should create('/tmp/dm-is-awesome/spec/spec_helper.rb')
|
21
|
+
end
|
22
|
+
it "creates a README" do
|
23
|
+
@generator.should create('/tmp/dm-is-awesome/README.txt')
|
24
|
+
end
|
25
|
+
it "creates a History file" do
|
26
|
+
@generator.should create('/tmp/dm-is-awesome/History.txt')
|
27
|
+
end
|
28
|
+
it "creates a LICENSE" do
|
29
|
+
@generator.should create('/tmp/dm-is-awesome/LICENSE')
|
30
|
+
end
|
31
|
+
it "creates a Manifest for Hoe" do
|
32
|
+
@generator.should create('/tmp/dm-is-awesome/Manifest.txt')
|
33
|
+
end
|
34
|
+
it "creates a TODO list" do
|
35
|
+
@generator.should create('/tmp/dm-is-awesome/TODO')
|
36
|
+
end
|
37
|
+
it "creates support tasks" do
|
38
|
+
@generator.should create('/tmp/dm-is-awesome/tasks/spec.rb')
|
39
|
+
@generator.should create('/tmp/dm-is-awesome/tasks/install.rb')
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: namelessjon-dm-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Stott
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-20 00:00:00 -08:00
|
13
13
|
default_executable: dm-gen
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -33,17 +33,42 @@ files:
|
|
33
33
|
- bin/dm-gen
|
34
34
|
- lib/templates
|
35
35
|
- lib/templates/one_file.rb
|
36
|
+
- lib/templates/is
|
37
|
+
- lib/templates/is/lib
|
38
|
+
- lib/templates/is/lib/dm-is-example
|
39
|
+
- lib/templates/is/lib/%gem_name%.rb
|
40
|
+
- lib/templates/is/lib/%gem_name%
|
41
|
+
- lib/templates/is/lib/%gem_name%/is
|
42
|
+
- lib/templates/is/lib/%gem_name%/is/%snake_name%.rb
|
43
|
+
- lib/templates/is/lib/%gem_name%/is/version.rb
|
44
|
+
- lib/templates/is/History.txt
|
45
|
+
- lib/templates/is/LICENSE
|
46
|
+
- lib/templates/is/Manifest.txt
|
47
|
+
- lib/templates/is/README.txt
|
48
|
+
- lib/templates/is/Rakefile
|
49
|
+
- lib/templates/is/TODO
|
50
|
+
- lib/templates/is/spec
|
51
|
+
- lib/templates/is/spec/integration
|
52
|
+
- lib/templates/is/spec/integration/%snake_name%_spec.rb
|
53
|
+
- lib/templates/is/spec/spec.opts
|
54
|
+
- lib/templates/is/spec/spec_helper.rb
|
55
|
+
- lib/templates/is/tasks
|
56
|
+
- lib/templates/is/tasks/install.rb
|
57
|
+
- lib/templates/is/tasks/spec.rb
|
36
58
|
- lib/generators
|
37
59
|
- lib/generators/one_file.rb
|
60
|
+
- lib/generators/is.rb
|
38
61
|
- lib/dm_gen.rb
|
39
62
|
- spec/dm_gen_spec.rb
|
40
63
|
- spec/spec_helper.rb
|
41
64
|
- spec/one_file_spec.rb
|
42
|
-
|
65
|
+
- spec/is_plugin_spec.rb
|
66
|
+
has_rdoc: true
|
43
67
|
homepage: http://github.com/namelessjon/dm-gen
|
44
68
|
post_install_message:
|
45
|
-
rdoc_options:
|
46
|
-
|
69
|
+
rdoc_options:
|
70
|
+
- --inline-source
|
71
|
+
- --charset=UTF-8
|
47
72
|
require_paths:
|
48
73
|
- lib
|
49
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|