namelessjon-dm-gen 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/lib/dm_gen.rb +1 -1
- data/lib/templates/adapter/lib/%adapter_file%.rb +33 -57
- data/lib/templates/adapter/spec/integration/%adapter_file%_spec.rb +30 -0
- data/lib/templates/one_file.rb +0 -2
- metadata +36 -46
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jonathan Stott
|
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.
|
data/lib/dm_gen.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
gem 'dm-core', '~> <%= DMGen::DM_VERSION %>'
|
2
1
|
require 'dm-core'
|
3
2
|
|
4
3
|
module DataMapper
|
@@ -18,104 +17,81 @@ module DataMapper
|
|
18
17
|
# each have a key that can be used to quickly look them up later without
|
19
18
|
# searching, if the adapter supports it.
|
20
19
|
#
|
21
|
-
# @param [
|
20
|
+
# @param [Enumerable(Resource)] resources
|
22
21
|
# The set of resources (model instances)
|
23
22
|
#
|
24
|
-
# @return [Integer]
|
25
|
-
# The number of records that were actually saved into the data-store
|
26
|
-
#
|
27
23
|
# @api semipublic
|
28
24
|
def create(resources)
|
29
25
|
raise NotImplementedError
|
30
26
|
end
|
31
27
|
|
32
28
|
##
|
33
|
-
#
|
34
|
-
#
|
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
|
29
|
+
# Looks up one record or a collection of records from the data-store:
|
30
|
+
# "SELECT" in SQL.
|
45
31
|
#
|
46
|
-
# @
|
47
|
-
|
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.
|
32
|
+
# @param [Query] query
|
33
|
+
# The query to be used to seach for the resources
|
58
34
|
#
|
59
|
-
# @return [
|
60
|
-
#
|
61
|
-
#
|
35
|
+
# @return [Array]
|
36
|
+
# An Array of Hashes containing the key-value pairs for
|
37
|
+
# each record
|
62
38
|
#
|
63
39
|
# @api semipublic
|
64
|
-
def
|
40
|
+
def read(query)
|
65
41
|
raise NotImplementedError
|
66
42
|
end
|
67
43
|
|
68
44
|
##
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# @param [DataMapper::Query] query
|
74
|
-
# The query to be used to seach for the resources
|
45
|
+
# Used by DataMapper to update the attributes on existing records in a
|
46
|
+
# data-store: "UPDATE" in SQL-speak. It takes a hash of the attributes
|
47
|
+
# to update with, as well as a collection object that specifies which resources
|
48
|
+
# should be updated.
|
75
49
|
#
|
76
|
-
# @
|
77
|
-
# A
|
50
|
+
# @param [Hash] attributes
|
51
|
+
# A set of key-value pairs of the attributes to update the resources with.
|
52
|
+
# @param [DataMapper::Collection] resources
|
53
|
+
# The collection of resources to update.
|
78
54
|
#
|
79
55
|
# @api semipublic
|
80
|
-
def
|
56
|
+
def update(attributes, collection)
|
81
57
|
raise NotImplementedError
|
82
58
|
end
|
83
59
|
|
84
60
|
##
|
85
61
|
# Destroys all the records matching the given query. "DELETE" in SQL.
|
86
62
|
#
|
87
|
-
# @param [DataMapper::
|
88
|
-
# The
|
63
|
+
# @param [DataMapper::Collection] resources
|
64
|
+
# The collection of resources to delete.
|
89
65
|
#
|
90
66
|
# @return [Integer]
|
91
67
|
# The number of records that were deleted.
|
92
68
|
#
|
93
69
|
# @api semipublic
|
94
|
-
def delete(
|
70
|
+
def delete(collection)
|
95
71
|
raise NotImplementedError
|
96
72
|
end
|
97
73
|
|
98
74
|
private
|
99
75
|
|
100
76
|
##
|
101
|
-
# Make a new instance of the adapter.
|
102
|
-
#
|
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
|
-
#
|
77
|
+
# Make a new instance of the adapter.
|
78
|
+
#
|
107
79
|
# @param [String, Symbol] name
|
108
|
-
# The name of the
|
80
|
+
# The name of the Repository using this adapter.
|
109
81
|
# @param [String, Hash] uri_or_options
|
110
82
|
# The connection uri string, or a hash of options to set up
|
111
83
|
# the adapter
|
112
84
|
#
|
113
85
|
# @api semipublic
|
114
|
-
def initialize(name,
|
86
|
+
def initialize(name, options = {})
|
115
87
|
super
|
116
|
-
@identity_maps = {}
|
117
88
|
end
|
118
89
|
|
119
|
-
end
|
120
|
-
|
121
|
-
|
90
|
+
end # class <%= class_name %>
|
91
|
+
|
92
|
+
##
|
93
|
+
#
|
94
|
+
# This can be used by plugins to trigger hooks for your adapter.
|
95
|
+
const_added(:<%= class_name %>)
|
96
|
+
end # module Adapters
|
97
|
+
end # module DataMapper
|
@@ -1,6 +1,36 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
3
|
|
4
|
+
|
5
|
+
# load up the shared specs.
|
6
|
+
require 'dm-core/spec/adapter_shared_spec'
|
7
|
+
|
4
8
|
describe 'DataMapper::Adapters::<%= class_name %>' do
|
9
|
+
before :all do
|
10
|
+
class ::Heffalump
|
11
|
+
include DataMapper::Resource
|
12
|
+
|
13
|
+
property :id, Serial
|
14
|
+
property :name, String
|
15
|
+
property :num_spots, Integer
|
16
|
+
property :striped, Boolean
|
17
|
+
end
|
18
|
+
|
19
|
+
@model = Heffalump
|
20
|
+
end
|
21
|
+
|
22
|
+
supported_by :<%= snake_name %> do
|
23
|
+
before :all do
|
24
|
+
@model.all.destroy!
|
25
|
+
|
26
|
+
@heff1 = @model.create(:color => 'Black', :num_spots => 0, :striped => true)
|
27
|
+
@heff2 = @model.create(:color => 'Brown', :num_spots => 25, :striped => false)
|
28
|
+
@heff3 = @model.create(:color => 'Dark Blue', :num_spots => nil, :striped => false)
|
29
|
+
|
30
|
+
@string_property = @model.color
|
31
|
+
@integer_property = @model.num_spots
|
32
|
+
end
|
5
33
|
|
34
|
+
it_should_behave_like 'An Adapter'
|
35
|
+
end
|
6
36
|
end
|
data/lib/templates/one_file.rb
CHANGED
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.3.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-
|
12
|
+
date: 2009-07-10 00:00:00 -07:00
|
13
13
|
default_executable: dm-gen
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,69 +28,55 @@ executables:
|
|
28
28
|
- dm-gen
|
29
29
|
extensions: []
|
30
30
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
33
|
-
files:
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
34
33
|
- README.rdoc
|
34
|
+
files:
|
35
35
|
- CHANGELOG.rdoc
|
36
|
+
- README.rdoc
|
36
37
|
- bin/dm-gen
|
37
|
-
- lib/
|
38
|
-
- lib/
|
39
|
-
- lib/
|
40
|
-
- lib/
|
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/lib/%gem_name%.rb
|
45
|
-
- lib/templates/is/History.txt
|
46
|
-
- lib/templates/is/LICENSE
|
47
|
-
- lib/templates/is/README.txt
|
48
|
-
- lib/templates/is/TODO
|
49
|
-
- lib/templates/is/spec
|
50
|
-
- lib/templates/is/spec/integration
|
51
|
-
- lib/templates/is/spec/integration/%snake_name%_spec.rb
|
52
|
-
- lib/templates/is/spec/spec.opts
|
53
|
-
- lib/templates/is/spec/spec_helper.rb
|
54
|
-
- lib/templates/is/tasks
|
55
|
-
- lib/templates/is/tasks/install.rb
|
56
|
-
- lib/templates/is/tasks/spec.rb
|
57
|
-
- lib/templates/is/Manifest.txt
|
58
|
-
- lib/templates/is/Rakefile
|
59
|
-
- lib/templates/adapter
|
38
|
+
- lib/dm_gen.rb
|
39
|
+
- lib/generators/adapter.rb
|
40
|
+
- lib/generators/is.rb
|
41
|
+
- lib/generators/one_file.rb
|
60
42
|
- lib/templates/adapter/History.txt
|
61
43
|
- lib/templates/adapter/LICENSE
|
62
44
|
- lib/templates/adapter/Manifest.txt
|
63
45
|
- lib/templates/adapter/README.txt
|
46
|
+
- lib/templates/adapter/Rakefile
|
64
47
|
- lib/templates/adapter/TODO
|
65
|
-
- lib/templates/adapter/lib
|
66
|
-
- lib/templates/adapter/lib/%adapter_file%
|
67
|
-
- lib/templates/adapter/lib/%adapter_file%/version.rb
|
68
48
|
- lib/templates/adapter/lib/%adapter_file%.rb
|
69
|
-
- lib/templates/adapter/
|
70
|
-
- lib/templates/adapter/spec/integration
|
49
|
+
- lib/templates/adapter/lib/%adapter_file%/version.rb
|
71
50
|
- lib/templates/adapter/spec/integration/%adapter_file%_spec.rb
|
72
51
|
- lib/templates/adapter/spec/spec.opts
|
73
52
|
- lib/templates/adapter/spec/spec_helper.rb
|
74
|
-
- lib/templates/adapter/tasks
|
75
53
|
- lib/templates/adapter/tasks/install.rb
|
76
54
|
- lib/templates/adapter/tasks/spec.rb
|
77
|
-
- lib/templates/
|
55
|
+
- lib/templates/is/History.txt
|
56
|
+
- lib/templates/is/LICENSE
|
57
|
+
- lib/templates/is/Manifest.txt
|
58
|
+
- lib/templates/is/README.txt
|
59
|
+
- lib/templates/is/Rakefile
|
60
|
+
- lib/templates/is/TODO
|
61
|
+
- lib/templates/is/lib/%gem_name%.rb
|
62
|
+
- lib/templates/is/lib/%gem_name%/is/%snake_name%.rb
|
63
|
+
- lib/templates/is/lib/%gem_name%/is/version.rb
|
64
|
+
- lib/templates/is/spec/integration/%snake_name%_spec.rb
|
65
|
+
- lib/templates/is/spec/spec.opts
|
66
|
+
- lib/templates/is/spec/spec_helper.rb
|
67
|
+
- lib/templates/is/tasks/install.rb
|
68
|
+
- lib/templates/is/tasks/spec.rb
|
78
69
|
- lib/templates/one_file.rb
|
79
|
-
- lib/generators
|
80
|
-
- lib/generators/one_file.rb
|
81
|
-
- lib/generators/adapter.rb
|
82
|
-
- lib/generators/is.rb
|
83
|
-
- lib/dm_gen.rb
|
84
|
-
- spec/is_plugin_spec.rb
|
85
|
-
- spec/dm_gen_spec.rb
|
86
70
|
- spec/adapter_spec.rb
|
87
|
-
- spec/
|
71
|
+
- spec/dm_gen_spec.rb
|
72
|
+
- spec/is_plugin_spec.rb
|
88
73
|
- spec/one_file_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- LICENSE
|
89
76
|
has_rdoc: false
|
90
77
|
homepage: http://github.com/namelessjon/dm-gen
|
91
78
|
post_install_message:
|
92
79
|
rdoc_options:
|
93
|
-
- --inline-source
|
94
80
|
- --charset=UTF-8
|
95
81
|
require_paths:
|
96
82
|
- lib
|
@@ -113,5 +99,9 @@ rubygems_version: 1.2.0
|
|
113
99
|
signing_key:
|
114
100
|
specification_version: 3
|
115
101
|
summary: Simple commandline tool for generating dm models
|
116
|
-
test_files:
|
117
|
-
|
102
|
+
test_files:
|
103
|
+
- spec/is_plugin_spec.rb
|
104
|
+
- spec/dm_gen_spec.rb
|
105
|
+
- spec/adapter_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/one_file_spec.rb
|