namelessjon-dm-gen 0.1.0 → 0.2.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/adapter.rb +54 -0
- data/lib/templates/adapter/History.txt +4 -0
- data/lib/templates/adapter/LICENSE +20 -0
- data/lib/templates/adapter/Manifest.txt +1 -0
- data/lib/templates/adapter/README.txt +3 -0
- data/lib/templates/adapter/Rakefile +30 -0
- data/lib/templates/adapter/TODO +0 -0
- data/lib/templates/adapter/lib/%adapter_file%/version.rb +5 -0
- data/lib/templates/adapter/lib/%adapter_file%.rb +121 -0
- data/lib/templates/adapter/spec/integration/%adapter_file%_spec.rb +6 -0
- data/lib/templates/adapter/spec/spec.opts +1 -0
- data/lib/templates/adapter/spec/spec_helper.rb +10 -0
- data/lib/templates/adapter/tasks/install.rb +13 -0
- data/lib/templates/adapter/tasks/spec.rb +25 -0
- data/spec/adapter_spec.rb +96 -0
- metadata +23 -2
data/lib/dm_gen.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
module DMGen
|
2
|
+
class Adapter < Templater::Generator
|
3
|
+
first_argument :name, :required => true
|
4
|
+
|
5
|
+
desc <<-eos
|
6
|
+
Generates a DataMapper Adapter skeleton.
|
7
|
+
|
8
|
+
Use like
|
9
|
+
dm-gen adapter data_source
|
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
|
+
eos
|
14
|
+
|
15
|
+
def self.source_root
|
16
|
+
File.join(File.dirname(__FILE__), '..', 'templates', 'adapter')
|
17
|
+
end
|
18
|
+
|
19
|
+
def gem_name
|
20
|
+
"dm-#{adapter_name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def adapter_name
|
24
|
+
"#{snake_name}-adapter"
|
25
|
+
end
|
26
|
+
|
27
|
+
def adapter_file
|
28
|
+
"#{snake_name}_adapter"
|
29
|
+
end
|
30
|
+
|
31
|
+
def snake_name
|
32
|
+
name.snake_case
|
33
|
+
end
|
34
|
+
|
35
|
+
def class_name
|
36
|
+
"#{name.camel_case}Adapter"
|
37
|
+
end
|
38
|
+
|
39
|
+
def destination_root
|
40
|
+
File.join(@destination_root, gem_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
# glob the template dir for all templates.
|
44
|
+
# since we want text files processed, we have to replace the default
|
45
|
+
# extension list.
|
46
|
+
glob!('', %w[rb txt Rakefile LICENSE TODO])
|
47
|
+
|
48
|
+
def manifest_files
|
49
|
+
self.all_actions.map {|t| t.destination.gsub(/#{destination_root}\//,'') }.sort
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
add :adapter, Adapter
|
54
|
+
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 @@
|
|
1
|
+
<%= manifest_files.join("\n") %>
|
@@ -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/<%= adapter_file %>/version'
|
11
|
+
|
12
|
+
# define some constants to help with task files
|
13
|
+
GEM_NAME = '<%= gem_name %>'
|
14
|
+
GEM_VERSION = DataMapper::<%= 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 Adapter for ...'
|
20
|
+
p.summary = 'A DataMapper Adapter for ...'
|
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,121 @@
|
|
1
|
+
gem 'dm-core', '~>0.9.10'
|
2
|
+
require 'dm-core'
|
3
|
+
|
4
|
+
module DataMapper
|
5
|
+
module Adapters
|
6
|
+
# The documentation for this adapter was taken from
|
7
|
+
#
|
8
|
+
# lib/dm-core/adapters/in_memory_adapter.rb
|
9
|
+
#
|
10
|
+
# Which is intended as a general source of documentation for the
|
11
|
+
# implementation to be followed by all DataMapper adapters. The implementor
|
12
|
+
# is well advised to read over the adapter before implementing their own.
|
13
|
+
#
|
14
|
+
class <%= class_name %> < AbstractAdapter
|
15
|
+
##
|
16
|
+
# Used by DataMapper to put records into a data-store: "INSERT" in SQL-speak.
|
17
|
+
# It takes an array of the resources (model instances) to be saved. Resources
|
18
|
+
# each have a key that can be used to quickly look them up later without
|
19
|
+
# searching, if the adapter supports it.
|
20
|
+
#
|
21
|
+
# @param [Array<DataMapper::Resource>] resources
|
22
|
+
# The set of resources (model instances)
|
23
|
+
#
|
24
|
+
# @return [Integer]
|
25
|
+
# The number of records that were actually saved into the data-store
|
26
|
+
#
|
27
|
+
# @api semipublic
|
28
|
+
def create(resources)
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Used by DataMapper to update the attributes on existing records in a
|
34
|
+
# data-store: "UPDATE" in SQL-speak. It takes a hash of the attributes
|
35
|
+
# to update with, as well as a query object that specifies which resources
|
36
|
+
# should be updated.
|
37
|
+
#
|
38
|
+
# @param [Hash] attributes
|
39
|
+
# A set of key-value pairs of the attributes to update the resources with.
|
40
|
+
# @param [DataMapper::Query] query
|
41
|
+
# The query that should be used to find the resource(s) to update.
|
42
|
+
#
|
43
|
+
# @return [Integer]
|
44
|
+
# the number of records that were successfully updated
|
45
|
+
#
|
46
|
+
# @api semipublic
|
47
|
+
def update(attributes, query)
|
48
|
+
raise NotImplementedError
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Look up a single record from the data-store. "SELECT ... LIMIT 1" in SQL.
|
53
|
+
# Used by Model#get to find a record by its identifier(s), and Model#first
|
54
|
+
# to find a single record by some search query.
|
55
|
+
#
|
56
|
+
# @param [DataMapper::Query] query
|
57
|
+
# The query to be used to locate the resource.
|
58
|
+
#
|
59
|
+
# @return [DataMapper::Resource]
|
60
|
+
# A Resource object representing the record that was found, or nil for no
|
61
|
+
# matching records.
|
62
|
+
#
|
63
|
+
# @api semipublic
|
64
|
+
def read_one(query)
|
65
|
+
raise NotImplementedError
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Looks up a collection of records from the data-store: "SELECT" in SQL.
|
70
|
+
# Used by Model#all to search for a set of records; that set is in a
|
71
|
+
# DataMapper::Collection object.
|
72
|
+
#
|
73
|
+
# @param [DataMapper::Query] query
|
74
|
+
# The query to be used to seach for the resources
|
75
|
+
#
|
76
|
+
# @return [DataMapper::Collection]
|
77
|
+
# A collection of all the resources found by the query.
|
78
|
+
#
|
79
|
+
# @api semipublic
|
80
|
+
def read_many(query)
|
81
|
+
raise NotImplementedError
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Destroys all the records matching the given query. "DELETE" in SQL.
|
86
|
+
#
|
87
|
+
# @param [DataMapper::Query] query
|
88
|
+
# The query used to locate the resources to be deleted.
|
89
|
+
#
|
90
|
+
# @return [Integer]
|
91
|
+
# The number of records that were deleted.
|
92
|
+
#
|
93
|
+
# @api semipublic
|
94
|
+
def delete(query)
|
95
|
+
raise NotImplementedError
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
##
|
101
|
+
# Make a new instance of the adapter. The @model_records ivar is the 'data-store'
|
102
|
+
# for this adapter. It is not shared amongst multiple incarnations of this
|
103
|
+
# adapter, eg DataMapper.setup(:default, :adapter => :in_memory);
|
104
|
+
# DataMapper.setup(:alternate, :adapter => :in_memory) do not share the
|
105
|
+
# data-store between them.
|
106
|
+
#
|
107
|
+
# @param [String, Symbol] name
|
108
|
+
# The name of the DataMapper::Repository using this adapter.
|
109
|
+
# @param [String, Hash] uri_or_options
|
110
|
+
# The connection uri string, or a hash of options to set up
|
111
|
+
# the adapter
|
112
|
+
#
|
113
|
+
# @api semipublic
|
114
|
+
def initialize(name, uri_or_options)
|
115
|
+
super
|
116
|
+
@identity_maps = {}
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
@@ -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,96 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "DMGen::Adapter" do
|
4
|
+
before do
|
5
|
+
@generator = DMGen::Adapter.new('/tmp', {}, 'awesome')
|
6
|
+
end
|
7
|
+
|
8
|
+
# basic file creation.
|
9
|
+
it "creates a Rakefile" do
|
10
|
+
@generator.should create('/tmp/dm-awesome-adapter/Rakefile')
|
11
|
+
end
|
12
|
+
it "creates the lib folder layout" do
|
13
|
+
@generator.should create('/tmp/dm-awesome-adapter/lib/awesome_adapter.rb')
|
14
|
+
@generator.should create('/tmp/dm-awesome-adapter/lib/awesome_adapter/version.rb')
|
15
|
+
end
|
16
|
+
it "creates the spec folder layout" do
|
17
|
+
@generator.should create('/tmp/dm-awesome-adapter/spec/integration/awesome_adapter_spec.rb')
|
18
|
+
@generator.should create('/tmp/dm-awesome-adapter/spec/spec.opts')
|
19
|
+
@generator.should create('/tmp/dm-awesome-adapter/spec/spec_helper.rb')
|
20
|
+
end
|
21
|
+
it "creates a README" do
|
22
|
+
@generator.should create('/tmp/dm-awesome-adapter/README.txt')
|
23
|
+
end
|
24
|
+
it "creates a History file" do
|
25
|
+
@generator.should create('/tmp/dm-awesome-adapter/History.txt')
|
26
|
+
end
|
27
|
+
it "creates a LICENSE" do
|
28
|
+
@generator.should create('/tmp/dm-awesome-adapter/LICENSE')
|
29
|
+
end
|
30
|
+
it "creates a Manifest for Hoe" do
|
31
|
+
@generator.should create('/tmp/dm-awesome-adapter/Manifest.txt')
|
32
|
+
end
|
33
|
+
it "creates a TODO list" do
|
34
|
+
@generator.should create('/tmp/dm-awesome-adapter/TODO')
|
35
|
+
end
|
36
|
+
it "creates support tasks" do
|
37
|
+
@generator.should create('/tmp/dm-awesome-adapter/tasks/spec.rb')
|
38
|
+
@generator.should create('/tmp/dm-awesome-adapter/tasks/install.rb')
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "Manifest.txt" do
|
42
|
+
before do
|
43
|
+
@template = @generator.template(:manifest_txt)
|
44
|
+
@result = @template.render
|
45
|
+
end
|
46
|
+
|
47
|
+
it "contains itself" do
|
48
|
+
@result.should.be.a.match(/^Manifest.txt$/)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "version.rb" do
|
54
|
+
before do
|
55
|
+
@template = @generator.template(:lib_adapter_file_version_rb)
|
56
|
+
@result = @template.render
|
57
|
+
end
|
58
|
+
|
59
|
+
it "generates the correct output" do
|
60
|
+
@result.should.include(<<-eos)
|
61
|
+
module DataMapper
|
62
|
+
module AwesomeAdapter
|
63
|
+
VERSION = '0.0.1'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
eos
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "spec/spec_helper.rb" do
|
71
|
+
before do
|
72
|
+
@template = @generator.template(:spec_spec_helper_rb)
|
73
|
+
@result = @template.render
|
74
|
+
end
|
75
|
+
|
76
|
+
it "contains a connection string for the new adapter" do
|
77
|
+
@result.should.include('DataMapper.setup(:default, "awesome://some/uri/here")')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "requires the adapter library" do
|
81
|
+
@result.should.be.a.match(/require .*lib\/awesome_adapter/)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "Rakefile" do
|
87
|
+
before do
|
88
|
+
@template = @generator.template(:rakefile)
|
89
|
+
@result = @template.render
|
90
|
+
end
|
91
|
+
|
92
|
+
it "requires the version file" do
|
93
|
+
@result.should.include(%q{require ROOT + 'lib/awesome_adapter/version'})
|
94
|
+
end
|
95
|
+
end
|
96
|
+
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.
|
4
|
+
version: 0.2.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: 2009-01-
|
12
|
+
date: 2009-01-21 00:00:00 -08:00
|
13
13
|
default_executable: dm-gen
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,14 +55,35 @@ files:
|
|
55
55
|
- lib/templates/is/tasks
|
56
56
|
- lib/templates/is/tasks/install.rb
|
57
57
|
- lib/templates/is/tasks/spec.rb
|
58
|
+
- lib/templates/adapter
|
59
|
+
- lib/templates/adapter/History.txt
|
60
|
+
- lib/templates/adapter/LICENSE
|
61
|
+
- lib/templates/adapter/Manifest.txt
|
62
|
+
- lib/templates/adapter/README.txt
|
63
|
+
- lib/templates/adapter/Rakefile
|
64
|
+
- lib/templates/adapter/TODO
|
65
|
+
- lib/templates/adapter/lib
|
66
|
+
- lib/templates/adapter/lib/%adapter_file%.rb
|
67
|
+
- lib/templates/adapter/lib/%adapter_file%
|
68
|
+
- lib/templates/adapter/lib/%adapter_file%/version.rb
|
69
|
+
- lib/templates/adapter/spec
|
70
|
+
- lib/templates/adapter/spec/integration
|
71
|
+
- lib/templates/adapter/spec/integration/%adapter_file%_spec.rb
|
72
|
+
- lib/templates/adapter/spec/spec.opts
|
73
|
+
- lib/templates/adapter/spec/spec_helper.rb
|
74
|
+
- lib/templates/adapter/tasks
|
75
|
+
- lib/templates/adapter/tasks/install.rb
|
76
|
+
- lib/templates/adapter/tasks/spec.rb
|
58
77
|
- lib/generators
|
59
78
|
- lib/generators/one_file.rb
|
60
79
|
- lib/generators/is.rb
|
80
|
+
- lib/generators/adapter.rb
|
61
81
|
- lib/dm_gen.rb
|
62
82
|
- spec/dm_gen_spec.rb
|
63
83
|
- spec/spec_helper.rb
|
64
84
|
- spec/one_file_spec.rb
|
65
85
|
- spec/is_plugin_spec.rb
|
86
|
+
- spec/adapter_spec.rb
|
66
87
|
has_rdoc: true
|
67
88
|
homepage: http://github.com/namelessjon/dm-gen
|
68
89
|
post_install_message:
|