dm-gen 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/CHANGELOG.rdoc +48 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +47 -0
  4. data/bin/dm-gen +6 -0
  5. data/lib/dm-gen/generators/adapter.rb +54 -0
  6. data/lib/dm-gen/generators/is.rb +47 -0
  7. data/lib/dm-gen/generators/one_file.rb +51 -0
  8. data/lib/dm-gen/templates/adapter/History.txt +4 -0
  9. data/lib/dm-gen/templates/adapter/LICENSE +20 -0
  10. data/lib/dm-gen/templates/adapter/Manifest.txt +1 -0
  11. data/lib/dm-gen/templates/adapter/README.txt +3 -0
  12. data/lib/dm-gen/templates/adapter/Rakefile +30 -0
  13. data/lib/dm-gen/templates/adapter/TODO +0 -0
  14. data/lib/dm-gen/templates/adapter/lib/%adapter_file%/version.rb +5 -0
  15. data/lib/dm-gen/templates/adapter/lib/%adapter_file%.rb +97 -0
  16. data/lib/dm-gen/templates/adapter/spec/integration/%adapter_file%_spec.rb +36 -0
  17. data/lib/dm-gen/templates/adapter/spec/spec.opts +1 -0
  18. data/lib/dm-gen/templates/adapter/spec/spec_helper.rb +10 -0
  19. data/lib/dm-gen/templates/adapter/tasks/install.rb +13 -0
  20. data/lib/dm-gen/templates/adapter/tasks/spec.rb +25 -0
  21. data/lib/dm-gen/templates/is/History.txt +4 -0
  22. data/lib/dm-gen/templates/is/LICENSE +20 -0
  23. data/lib/dm-gen/templates/is/Manifest.txt +1 -0
  24. data/lib/dm-gen/templates/is/README.txt +3 -0
  25. data/lib/dm-gen/templates/is/Rakefile +30 -0
  26. data/lib/dm-gen/templates/is/TODO +0 -0
  27. data/lib/dm-gen/templates/is/lib/%gem_name%/is/%snake_name%.rb +38 -0
  28. data/lib/dm-gen/templates/is/lib/%gem_name%/is/version.rb +7 -0
  29. data/lib/dm-gen/templates/is/lib/%gem_name%.rb +20 -0
  30. data/lib/dm-gen/templates/is/spec/integration/%snake_name%_spec.rb +8 -0
  31. data/lib/dm-gen/templates/is/spec/spec.opts +1 -0
  32. data/lib/dm-gen/templates/is/spec/spec_helper.rb +26 -0
  33. data/lib/dm-gen/templates/is/tasks/install.rb +13 -0
  34. data/lib/dm-gen/templates/is/tasks/spec.rb +25 -0
  35. data/lib/dm-gen/templates/one_file.rb +32 -0
  36. data/lib/dm_gen.rb +17 -0
  37. data/spec/adapter_spec.rb +99 -0
  38. data/spec/dm_gen_spec.rb +2 -0
  39. data/spec/is_plugin_spec.rb +56 -0
  40. data/spec/one_file_spec.rb +111 -0
  41. data/spec/spec_helper.rb +12 -0
  42. metadata +113 -0
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ === 0.3.0 / 2009-07-10
2
+
3
+ * Updated dm version to 0.10.0
4
+ * Stopped adding a specific gem dependency line to one file scripts
5
+ * Now generates adapters in the 0.10.0 API pattern.
6
+
7
+ === 0.2.5 / 2009-05-23
8
+
9
+ * Fixed extra deps addition in Rakefile
10
+ * Updated dm version to 0.9.11
11
+ * Thanks to irjudson for pointing out problems.
12
+
13
+ === 0.2.4 / 2009-02-19
14
+
15
+ * Small improvements to the Rakefile
16
+
17
+ === 0.2.3 / 2009-02-19
18
+
19
+ * Removed errant directory from gemspec.
20
+
21
+ === 0.2.2 / 2009-01-21
22
+
23
+ * Now using a constant for the DataMapper version supported.
24
+ * Added this changelog
25
+
26
+ === 0.2.1 / 2009-01-21
27
+
28
+ * Minor correction to the is plugin manifest
29
+
30
+ === 0.2.0 / 2009-01-21
31
+
32
+ * Added generator for DataMapper adapters
33
+
34
+ === 0.1.0 / 2009-01-20
35
+
36
+ * Added generator for DataMapper is plugins
37
+
38
+ === 0.0.4 / 2008-12-13
39
+
40
+ * check for .rb extension on the given filename, and ignore it
41
+ * improved documentation for generator
42
+ * filter out serial from the given properties list
43
+ * added a whole bunch of specs!
44
+ * Other, minor, output tweaks
45
+
46
+ === 0.0.3 / 2008-12-01
47
+
48
+ * First working release!
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/README.rdoc ADDED
@@ -0,0 +1,47 @@
1
+ = dm-gen
2
+
3
+
4
+ dm-gen is a collection of generators for DataMapper, to allieviate the need to
5
+ type boilerplate code to get started on a project. dm-gen uses
6
+ templater[http://github.com/jnicklas/templater] as a base.
7
+
8
+ == The Generators
9
+
10
+ === one_file
11
+
12
+
13
+ The one file generator generates a single file, which sets up a connection to an
14
+ in memory sqlite3 database, along with debug logging and a example model, which
15
+ it then automigrates. One file scripts are great to use as demonstration,
16
+ either of a bug, or just how to do something.
17
+
18
+ dm-gen one_file validations_example
19
+
20
+
21
+ === is
22
+
23
+
24
+ The is generator generates an 'is' plugin structure, appropriate for plugins
25
+ such as dm-is-list, dm-is-remixable etc. A complete plugin structure is
26
+ generated, including a Rakefile and spec suite skeleton.
27
+
28
+ dm-gen is example
29
+
30
+
31
+ === adapter
32
+
33
+
34
+ The adapter generator generates an adapter structure, appropriate for adapters
35
+ to new data-sources, such as couchdb, YAML files, or anything else. A complete
36
+ plugin structure is generated. The adapter file generated comes with a lot of
37
+ documentation explaining the arguments and returns of the 4 methods in the DM
38
+ adaptor API.
39
+
40
+ dm-gen adapter example
41
+
42
+ NB: This generates adapters with the 0.10.x API NOT the 0.9.x API. So make sure
43
+ you're running DM from the next branch, or from http://gems.datamapper.org/
44
+
45
+ == COPYRIGHT
46
+
47
+ Copyright (c) 2008-2009 Jonathan Stott. See LICENSE for details.
data/bin/dm-gen ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'dm_gen'
5
+
6
+ DMGen.run_cli Dir.pwd, 'dm-gen', '0.1', ARGV
@@ -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,47 @@
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
+
41
+ def manifest_files
42
+ self.all_actions.map {|t| t.destination.gsub(/#{destination_root}\//,'') }.sort
43
+ end
44
+ end
45
+
46
+ add :is, Is
47
+ end
@@ -0,0 +1,51 @@
1
+ module DMGen
2
+ class OneFile < Templater::Generator
3
+ first_argument :name, :required => true
4
+ second_argument :model
5
+ third_argument :attributes, :as => :hash, :default => {}
6
+
7
+ desc <<-eos
8
+ Generates a 'one file test' for DataMapper, including debug logging and sqlite3 memory DB
9
+ Use like 'dm-gen one_file filename [model] [model,attributes,here]'
10
+
11
+ For example:
12
+ dm-gen one_file validation_test Post title:string,body:text
13
+
14
+ generates a one file test called 'validation_test.rb' which will have a class
15
+ called Post in it, with 3 properties: a Serial id (added for free), and a title
16
+ and a body.
17
+ eos
18
+
19
+ def self.source_root
20
+ File.join(File.dirname(__FILE__), '..', 'templates')
21
+ end
22
+
23
+ template :one_file do |t|
24
+ t.source = 'one_file.rb'
25
+ t.destination = "#{self.filename}.rb"
26
+ end
27
+
28
+ def model_name
29
+ (model) ? model.camel_case : "TestModel"
30
+ end
31
+
32
+ def filename
33
+ name.sub(/\.rb\z/,'')
34
+ end
35
+
36
+ def properties
37
+ h = {}
38
+ attributes.each do |k, v|
39
+ # skip if the property is named id
40
+ next if k == "id"
41
+
42
+ # convert to snake/camel case
43
+ h[k.snake_case] = v.camel_case
44
+ end
45
+ h
46
+ end
47
+
48
+ end
49
+
50
+ add :one_file, OneFile
51
+ end
@@ -0,0 +1,4 @@
1
+ === 0.0.1 / <%= Time.now.strftime('%Y-%m-%d') %>
2
+
3
+ * Release!
4
+
@@ -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,3 @@
1
+ = <%= gem_name %>
2
+
3
+ Description of the adapter. What data-store is it for, what is that good for?
@@ -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', "<%= DMGen::DM_VERSION %>"]
27
+
28
+ end
29
+
30
+ Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
File without changes
@@ -0,0 +1,5 @@
1
+ module DataMapper
2
+ module <%= class_name %>
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,97 @@
1
+ require 'dm-core'
2
+
3
+ module DataMapper
4
+ module Adapters
5
+ # The documentation for this adapter was taken from
6
+ #
7
+ # lib/dm-core/adapters/in_memory_adapter.rb
8
+ #
9
+ # Which is intended as a general source of documentation for the
10
+ # implementation to be followed by all DataMapper adapters. The implementor
11
+ # is well advised to read over the adapter before implementing their own.
12
+ #
13
+ class <%= class_name %> < AbstractAdapter
14
+ ##
15
+ # Used by DataMapper to put records into a data-store: "INSERT" in SQL-speak.
16
+ # It takes an array of the resources (model instances) to be saved. Resources
17
+ # each have a key that can be used to quickly look them up later without
18
+ # searching, if the adapter supports it.
19
+ #
20
+ # @param [Enumerable(Resource)] resources
21
+ # The set of resources (model instances)
22
+ #
23
+ # @api semipublic
24
+ def create(resources)
25
+ raise NotImplementedError
26
+ end
27
+
28
+ ##
29
+ # Looks up one record or a collection of records from the data-store:
30
+ # "SELECT" in SQL.
31
+ #
32
+ # @param [Query] query
33
+ # The query to be used to seach for the resources
34
+ #
35
+ # @return [Array]
36
+ # An Array of Hashes containing the key-value pairs for
37
+ # each record
38
+ #
39
+ # @api semipublic
40
+ def read(query)
41
+ raise NotImplementedError
42
+ end
43
+
44
+ ##
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.
49
+ #
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.
54
+ #
55
+ # @api semipublic
56
+ def update(attributes, collection)
57
+ raise NotImplementedError
58
+ end
59
+
60
+ ##
61
+ # Destroys all the records matching the given query. "DELETE" in SQL.
62
+ #
63
+ # @param [DataMapper::Collection] resources
64
+ # The collection of resources to delete.
65
+ #
66
+ # @return [Integer]
67
+ # The number of records that were deleted.
68
+ #
69
+ # @api semipublic
70
+ def delete(collection)
71
+ raise NotImplementedError
72
+ end
73
+
74
+ private
75
+
76
+ ##
77
+ # Make a new instance of the adapter.
78
+ #
79
+ # @param [String, Symbol] name
80
+ # The name of the Repository using this adapter.
81
+ # @param [String, Hash] uri_or_options
82
+ # The connection uri string, or a hash of options to set up
83
+ # the adapter
84
+ #
85
+ # @api semipublic
86
+ def initialize(name, options = {})
87
+ super
88
+ end
89
+
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
@@ -0,0 +1,36 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
+
4
+
5
+ # load up the shared specs.
6
+ require 'dm-core/spec/adapter_shared_spec'
7
+
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
33
+
34
+ it_should_behave_like 'An Adapter'
35
+ end
36
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
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/<%= adapter_file %>'
8
+
9
+ DataMapper.setup(:default, "<%= name %>://some/uri/here")
10
+
@@ -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,4 @@
1
+ === 0.0.1 / <%= Time.now.strftime('%Y-%m-%d') %>
2
+
3
+ * Release!
4
+
@@ -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,3 @@
1
+ = <%= gem_name %>
2
+
3
+ Description of plugin. What it does, and how.
@@ -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', "~> <%= DMGen::DM_VERSION"]
27
+
28
+ end
29
+
30
+ Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
File without changes
@@ -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,7 @@
1
+ module DataMapper
2
+ module Is
3
+ module <%= class_name %>
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -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', '~> <%= DMGen::DM_VERSION %>'
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,8 @@
1
+ require 'pathname'
2
+ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
+
4
+ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
5
+ describe 'DataMapper::Is::<%= class_name %>' do
6
+
7
+ end
8
+ end
@@ -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,32 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # A one file test to show ...
4
+ require 'rubygems'
5
+ require 'dm-core'
6
+
7
+
8
+ # setup the logger
9
+ DataMapper::Logger.new(STDOUT, :debug)
10
+
11
+ # connect to the DB
12
+ DataMapper.setup(:default, 'sqlite3::memory:')
13
+
14
+ class <%= model_name %>
15
+ include DataMapper::Resource
16
+
17
+ # properties
18
+ property :id, Serial
19
+ <% properties.each do |name, type| -%>
20
+ property :<%= name %>, <%= type %>
21
+ <% end %>
22
+ end
23
+
24
+ DataMapper.auto_migrate!
25
+
26
+ # put the code here!
27
+
28
+
29
+ __END__
30
+
31
+ # put a copy of the output here!
32
+
data/lib/dm_gen.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'templater'
2
+
3
+ # setup manifold
4
+ module DMGen
5
+ extend Templater::Manifold
6
+
7
+ DM_VERSION = '0.10.0'
8
+
9
+ desc <<-eos
10
+ Generates files for the DataMapper ORM.
11
+ eos
12
+ end
13
+
14
+ # require generators
15
+ require 'dm-gen/generators/one_file'
16
+ require 'dm-gen/generators/is'
17
+ require 'dm-gen/generators/adapter'
@@ -0,0 +1,99 @@
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
+ it "is the sorted list of its contents" do
52
+ @result.split("\n").sort.should == @result.split("\n")
53
+ end
54
+ end
55
+
56
+ describe "version.rb" do
57
+ before do
58
+ @template = @generator.template(:lib_adapter_file_version_rb)
59
+ @result = @template.render
60
+ end
61
+
62
+ it "generates the correct output" do
63
+ @result.should.include(<<-eos)
64
+ module DataMapper
65
+ module AwesomeAdapter
66
+ VERSION = '0.0.1'
67
+ end
68
+ end
69
+ eos
70
+ end
71
+ end
72
+
73
+ describe "spec/spec_helper.rb" do
74
+ before do
75
+ @template = @generator.template(:spec_spec_helper_rb)
76
+ @result = @template.render
77
+ end
78
+
79
+ it "contains a connection string for the new adapter" do
80
+ @result.should.include('DataMapper.setup(:default, "awesome://some/uri/here")')
81
+ end
82
+
83
+ it "requires the adapter library" do
84
+ @result.should.be.a.match(/require .*lib\/awesome_adapter/)
85
+ end
86
+
87
+ end
88
+
89
+ describe "Rakefile" do
90
+ before do
91
+ @template = @generator.template(:rakefile)
92
+ @result = @template.render
93
+ end
94
+
95
+ it "requires the version file" do
96
+ @result.should.include(%q{require ROOT + 'lib/awesome_adapter/version'})
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "DMGen::Is" 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
+
42
+ describe "Manifest.txt" do
43
+ before do
44
+ @template = @generator.template(:manifest_txt)
45
+ @result = @template.render
46
+ end
47
+
48
+ it "contains itself" do
49
+ @result.should.be.a.match(/^Manifest.txt$/)
50
+ end
51
+
52
+ it "is the sorted list of its contents" do
53
+ @result.split("\n").sort.should == @result.split("\n")
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,111 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ shared "one file generator" do
5
+ before do
6
+ @result = @generator.render!.first
7
+ end
8
+
9
+ it "successfully renders" do
10
+ lambda { @generator.render! }.should.not.raise
11
+ end
12
+
13
+ it "makes a file named 'validation_test.rb' when passed 'validation_test'" do
14
+ @generator.should create('/tmp/validation_test.rb')
15
+ end
16
+
17
+ it "makes a file named 'validation_test.rb' when passed 'validation_test.rb'" do
18
+ @generator = DMGen::OneFile.new('/tmp', {}, 'validation_test.rb')
19
+ @generator.should create('/tmp/validation_test.rb')
20
+ end
21
+
22
+ # model stuff
23
+ it "includes DataMapper::Resource" do
24
+ @result.should.match(/include DataMapper::Resource/)
25
+ end
26
+
27
+ it "has a serial id property" do
28
+ @result.should.match(/property :id, Serial/)
29
+ end
30
+
31
+ # requires
32
+ it "requires rubygems" do
33
+ @result.should.match(/require 'rubygems'/)
34
+ end
35
+
36
+ it "requires dm-core" do
37
+ @result.should.match(/require 'dm-core'/)
38
+ end
39
+
40
+ # other boilerplate
41
+ it "sets up a logger" do
42
+ @result.should.match(/DataMapper::Logger\.new\(STDOUT, :debug\)/)
43
+ end
44
+
45
+ it "sets up a connection to an sqlite3 in-memory db" do
46
+ @result.should.match(/DataMapper\.setup\(:default, 'sqlite3::memory:'\)/)
47
+ end
48
+
49
+ it "automigrates the db!" do
50
+ @result.should.match(/DataMapper\.auto_migrate!/)
51
+ end
52
+ end
53
+
54
+
55
+
56
+ describe "DMGen::OneFile" do
57
+ describe "with name option only" do
58
+ before do
59
+ @generator = DMGen::OneFile.new('/tmp', {}, 'validation_test')
60
+ end
61
+
62
+ behaves_like "one file generator"
63
+
64
+ it "makes a Model called TestModel" do
65
+ @result.should.match(/class TestModel/)
66
+ end
67
+ end
68
+
69
+
70
+ describe "with a model name too!" do
71
+ before do
72
+ @generator = DMGen::OneFile.new('/tmp', {}, 'validation_test', 'post')
73
+ end
74
+
75
+ behaves_like "one file generator"
76
+
77
+ it "makes a Model called Post" do
78
+ @result.should.match(/class Post/)
79
+ end
80
+ end
81
+
82
+
83
+ describe "and attributes!" do
84
+ before do
85
+ @generator = DMGen::OneFile.new('/tmp', {}, 'validation_test', 'post',
86
+ 'title:string,PostBody:text,created_at:date_time,id:serial')
87
+ end
88
+
89
+ behaves_like "one file generator"
90
+
91
+ it "makes a Model called Post" do
92
+ @result.should.match(/class Post/)
93
+ end
94
+
95
+ it "includes the title property as a string" do
96
+ @result.should.match(/property :title, String/)
97
+ end
98
+
99
+ it "snake cases the property name" do
100
+ @result.should.match(/property :post_body, Text/)
101
+ end
102
+
103
+ it "camel cases the property type" do
104
+ @result.should.match(/property :created_at, DateTime/)
105
+ end
106
+
107
+ it "only includes a serial property once" do
108
+ @result.should.not.match(/property :id, Serial.*?property :id, Serial/m)
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ gem('bacon')
3
+ require 'bacon'
4
+
5
+ require 'dm_gen'
6
+
7
+ # get a summary of errors raised and such
8
+ Bacon.summary_on_exit
9
+
10
+ def create(file)
11
+ lambda { |obj| obj.all_actions.map{|t| t.destination }.include?(file) }
12
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-gen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Stott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-06 00:00:00 +00:00
13
+ default_executable: dm-gen
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: templater
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
24
+ version:
25
+ description: |
26
+ dm-gen is a simple commandline tool for generating DataMapper related files.
27
+ It includes generators for standalone or one file examples, is plugins, adapters
28
+ and may eventually be expanded to do more.
29
+
30
+ email: jonathan.stott@gmail.com
31
+ executables:
32
+ - dm-gen
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - LICENSE
37
+ - README.rdoc
38
+ files:
39
+ - CHANGELOG.rdoc
40
+ - README.rdoc
41
+ - bin/dm-gen
42
+ - lib/dm-gen/generators/adapter.rb
43
+ - lib/dm-gen/generators/is.rb
44
+ - lib/dm-gen/generators/one_file.rb
45
+ - lib/dm-gen/templates/adapter/History.txt
46
+ - lib/dm-gen/templates/adapter/LICENSE
47
+ - lib/dm-gen/templates/adapter/Manifest.txt
48
+ - lib/dm-gen/templates/adapter/README.txt
49
+ - lib/dm-gen/templates/adapter/Rakefile
50
+ - lib/dm-gen/templates/adapter/TODO
51
+ - lib/dm-gen/templates/adapter/lib/%adapter_file%.rb
52
+ - lib/dm-gen/templates/adapter/lib/%adapter_file%/version.rb
53
+ - lib/dm-gen/templates/adapter/spec/integration/%adapter_file%_spec.rb
54
+ - lib/dm-gen/templates/adapter/spec/spec.opts
55
+ - lib/dm-gen/templates/adapter/spec/spec_helper.rb
56
+ - lib/dm-gen/templates/adapter/tasks/install.rb
57
+ - lib/dm-gen/templates/adapter/tasks/spec.rb
58
+ - lib/dm-gen/templates/is/History.txt
59
+ - lib/dm-gen/templates/is/LICENSE
60
+ - lib/dm-gen/templates/is/Manifest.txt
61
+ - lib/dm-gen/templates/is/README.txt
62
+ - lib/dm-gen/templates/is/Rakefile
63
+ - lib/dm-gen/templates/is/TODO
64
+ - lib/dm-gen/templates/is/lib/%gem_name%.rb
65
+ - lib/dm-gen/templates/is/lib/%gem_name%/is/%snake_name%.rb
66
+ - lib/dm-gen/templates/is/lib/%gem_name%/is/version.rb
67
+ - lib/dm-gen/templates/is/spec/integration/%snake_name%_spec.rb
68
+ - lib/dm-gen/templates/is/spec/spec.opts
69
+ - lib/dm-gen/templates/is/spec/spec_helper.rb
70
+ - lib/dm-gen/templates/is/tasks/install.rb
71
+ - lib/dm-gen/templates/is/tasks/spec.rb
72
+ - lib/dm-gen/templates/one_file.rb
73
+ - lib/dm_gen.rb
74
+ - spec/adapter_spec.rb
75
+ - spec/dm_gen_spec.rb
76
+ - spec/is_plugin_spec.rb
77
+ - spec/one_file_spec.rb
78
+ - spec/spec_helper.rb
79
+ - LICENSE
80
+ has_rdoc: true
81
+ homepage: http://github.com/namelessjon/dm-gen
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --charset=UTF-8
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ version:
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.5
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Simple commandline tool for generating DataMapper related files
108
+ test_files:
109
+ - spec/adapter_spec.rb
110
+ - spec/is_plugin_spec.rb
111
+ - spec/dm_gen_spec.rb
112
+ - spec/one_file_spec.rb
113
+ - spec/spec_helper.rb