dm-gen 0.4.2 → 0.5.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.
Files changed (66) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.rdoc +6 -0
  3. data/LICENSE +1 -1
  4. data/README.rdoc +2 -3
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/dm-gen.gemspec +105 -0
  8. data/lib/dm-gen/generators/adapter.rb +3 -30
  9. data/lib/dm-gen/generators/is.rb +2 -26
  10. data/lib/dm-gen/generators/plugin_generator.rb +44 -0
  11. data/lib/dm-gen/templates/adapter/.gitignore +35 -0
  12. data/lib/dm-gen/templates/adapter/Gemfile +82 -0
  13. data/lib/dm-gen/templates/adapter/LICENSE +1 -1
  14. data/lib/dm-gen/templates/adapter/README.rdoc +3 -0
  15. data/lib/dm-gen/templates/adapter/Rakefile +17 -24
  16. data/lib/dm-gen/templates/adapter/lib/%gem_name%.rb +1 -0
  17. data/lib/dm-gen/templates/adapter/lib/{%adapter_file%.rb → %gem_name%/adapter.rb} +8 -17
  18. data/lib/dm-gen/templates/adapter/lib/%gem_name%/spec/setup.rb +21 -0
  19. data/lib/dm-gen/templates/adapter/spec/adapter_spec.rb +21 -0
  20. data/lib/dm-gen/templates/adapter/spec/rcov.opts +5 -0
  21. data/lib/dm-gen/templates/adapter/spec/spec.opts +2 -0
  22. data/lib/dm-gen/templates/adapter/spec/spec_helper.rb +4 -9
  23. data/lib/dm-gen/templates/adapter/tasks/local_gemfile.rake +18 -0
  24. data/lib/dm-gen/templates/adapter/tasks/spec.rake +38 -0
  25. data/lib/dm-gen/templates/adapter/tasks/yard.rake +9 -0
  26. data/lib/dm-gen/templates/adapter/tasks/yardstick.rake +19 -0
  27. data/lib/dm-gen/templates/is/.gitignore +36 -0
  28. data/lib/dm-gen/templates/is/Gemfile +143 -0
  29. data/lib/dm-gen/templates/is/LICENSE +1 -1
  30. data/lib/dm-gen/templates/is/README.rdoc +2 -0
  31. data/lib/dm-gen/templates/is/Rakefile +16 -24
  32. data/lib/dm-gen/templates/is/VERSION +1 -0
  33. data/lib/dm-gen/templates/is/lib/%gem_name%.rb +1 -8
  34. data/lib/dm-gen/templates/is/lib/%gem_name%/is/%name%.rb +30 -0
  35. data/lib/dm-gen/templates/is/spec/integration/%name%_spec.rb +16 -0
  36. data/lib/dm-gen/templates/is/spec/rcov.opts +6 -0
  37. data/lib/dm-gen/templates/is/spec/spec.opts +3 -0
  38. data/lib/dm-gen/templates/is/spec/spec_helper.rb +7 -21
  39. data/lib/dm-gen/templates/is/tasks/ci.rake +1 -0
  40. data/lib/dm-gen/templates/is/tasks/local_gemfile.rake +18 -0
  41. data/lib/dm-gen/templates/is/tasks/metrics.rake +36 -0
  42. data/lib/dm-gen/templates/is/tasks/spec.rake +38 -0
  43. data/lib/dm-gen/templates/is/tasks/yard.rake +9 -0
  44. data/lib/dm-gen/templates/is/tasks/yardstick.rake +19 -0
  45. data/lib/dm-gen/templates/one_file.rb +3 -2
  46. data/lib/dm_gen.rb +1 -1
  47. data/spec/adapter_spec.rb +34 -52
  48. data/spec/is_plugin_spec.rb +13 -28
  49. metadata +59 -30
  50. data/lib/dm-gen/templates/adapter/History.txt +0 -4
  51. data/lib/dm-gen/templates/adapter/Manifest.txt +0 -1
  52. data/lib/dm-gen/templates/adapter/README.txt +0 -3
  53. data/lib/dm-gen/templates/adapter/TODO +0 -0
  54. data/lib/dm-gen/templates/adapter/lib/%adapter_file%/version.rb +0 -5
  55. data/lib/dm-gen/templates/adapter/spec/integration/%adapter_file%_spec.rb +0 -36
  56. data/lib/dm-gen/templates/adapter/tasks/install.rb +0 -13
  57. data/lib/dm-gen/templates/adapter/tasks/spec.rb +0 -25
  58. data/lib/dm-gen/templates/is/History.txt +0 -4
  59. data/lib/dm-gen/templates/is/Manifest.txt +0 -1
  60. data/lib/dm-gen/templates/is/README.txt +0 -3
  61. data/lib/dm-gen/templates/is/TODO +0 -0
  62. data/lib/dm-gen/templates/is/lib/%gem_name%/is/%snake_name%.rb +0 -38
  63. data/lib/dm-gen/templates/is/lib/%gem_name%/is/version.rb +0 -7
  64. data/lib/dm-gen/templates/is/spec/integration/%snake_name%_spec.rb +0 -8
  65. data/lib/dm-gen/templates/is/tasks/install.rb +0 -13
  66. data/lib/dm-gen/templates/is/tasks/spec.rb +0 -25
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 John Doe
1
+ Copyright (c) <%= Time.now.year %> NAME
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,3 @@
1
+ = <%= gem_name %>
2
+
3
+ A DataMapper adapter for <%= snake_name %>
@@ -1,30 +1,23 @@
1
- require 'pathname'
2
- require 'rubygems'
3
- require 'hoe'
1
+ begin
2
+ require 'jeweler'
4
3
 
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'])
4
+ Jeweler::Tasks.new do |gem|
5
+ gem.name = '<%= gem_name %>'
6
+ gem.summary = "SUMMARY"
7
+ gem.description = gem.summary
8
+ gem.authors = ["NAME"]
9
+ gem.email = %q{EMAIL}
10
+ gem.homepage = 'http://github.com/USERNAME/<%= gem_name %>'
9
11
 
10
- require ROOT + 'lib/<%= adapter_file %>/version'
12
+ gem.add_dependency 'dm-core', '~> <%= DMGen::DM_VERSION %>'
11
13
 
12
- # define some constants to help with task files
13
- GEM_NAME = '<%= gem_name %>'
14
- GEM_VERSION = DataMapper::<%= class_name %>::VERSION
14
+ gem.add_development_dependency 'rspec', '~> 1.3'
15
+ gem.add_development_dependency 'yard', '~> 0.5'
16
+ end
15
17
 
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 %>"]
18
+ Jeweler::GemcutterTasks.new
27
19
 
20
+ FileList['tasks/**/*.rake'].each { |task| import task }
21
+ rescue LoadError
22
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
28
23
  end
29
-
30
- Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
@@ -0,0 +1 @@
1
+ require '<%= gem_name %>/adapter'
@@ -2,16 +2,9 @@ require 'dm-core'
2
2
 
3
3
  module DataMapper
4
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
- #
5
+ # This documentation is taken from the in_memory adapter in dm-core. It
6
+ # explains the expected behaviour of the core methods which make up the API.
13
7
  class <%= class_name %> < AbstractAdapter
14
- ##
15
8
  # Used by DataMapper to put records into a data-store: "INSERT" in SQL-speak.
16
9
  # It takes an array of the resources (model instances) to be saved. Resources
17
10
  # each have a key that can be used to quickly look them up later without
@@ -25,7 +18,6 @@ module DataMapper
25
18
  raise NotImplementedError
26
19
  end
27
20
 
28
- ##
29
21
  # Looks up one record or a collection of records from the data-store:
30
22
  # "SELECT" in SQL.
31
23
  #
@@ -41,7 +33,6 @@ module DataMapper
41
33
  raise NotImplementedError
42
34
  end
43
35
 
44
- ##
45
36
  # Used by DataMapper to update the attributes on existing records in a
46
37
  # data-store: "UPDATE" in SQL-speak. It takes a hash of the attributes
47
38
  # to update with, as well as a collection object that specifies which resources
@@ -57,7 +48,6 @@ module DataMapper
57
48
  raise NotImplementedError
58
49
  end
59
50
 
60
- ##
61
51
  # Destroys all the records matching the given query. "DELETE" in SQL.
62
52
  #
63
53
  # @param [DataMapper::Collection] resources
@@ -71,11 +61,15 @@ module DataMapper
71
61
  raise NotImplementedError
72
62
  end
73
63
 
64
+ # TODO consider proper automigrate functionality
65
+ def reset
66
+ raise NotImplementedError
67
+ end
68
+
74
69
  private
75
70
 
76
- ##
77
71
  # Make a new instance of the adapter.
78
- #
72
+ #
79
73
  # @param [String, Symbol] name
80
74
  # The name of the Repository using this adapter.
81
75
  # @param [String, Hash] uri_or_options
@@ -89,9 +83,6 @@ module DataMapper
89
83
 
90
84
  end # class <%= class_name %>
91
85
 
92
- ##
93
- #
94
- # This can be used by plugins to trigger hooks for your adapter.
95
86
  const_added(:<%= class_name %>)
96
87
  end # module Adapters
97
88
  end # module DataMapper
@@ -0,0 +1,21 @@
1
+ require '<%= gem_name %>'
2
+ require 'dm-core/spec/setup'
3
+
4
+
5
+ module DataMapper
6
+ module Spec
7
+ module Adapters
8
+
9
+ # This class sets up the adapter for the spec framework DataMapper ships
10
+ # with
11
+ class <%= class_name %> < Adapter
12
+ def connection_uri
13
+ "<%= snake_name %>://..."
14
+ end
15
+ end
16
+
17
+ use <%= class_name %>
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ require 'dm-core'
4
+ require 'dm-core/spec/shared/adapter_spec'
5
+
6
+ require 'dm-migrations'
7
+ require '<%= gem_name %>/spec/setup'
8
+
9
+ ENV['ADAPTER'] = '<%= snake_name %>'
10
+ ENV['ADAPTER_SUPPORTS'] = 'all'
11
+
12
+ describe 'DataMapper::Adapters::<%= class_name %>' do
13
+
14
+ before :all do
15
+ @adapter = DataMapper::Spec.adapter
16
+ @repository = DataMapper.repository(@adapter.name)
17
+ end
18
+
19
+ it_should_behave_like "An Adapter"
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ --exclude "spec"
2
+ --sort coverage
3
+ --callsites
4
+ --xrefs
5
+ --text-summary
@@ -1 +1,3 @@
1
1
  --colour
2
+ --loadby random
3
+ --backtrace
@@ -1,10 +1,5 @@
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")
1
+ require 'dm-core/spec/lib/pending_helpers'
10
2
 
3
+ Spec::Runner.configure do |config|
4
+ config.include(DataMapper::Spec::PendingHelpers)
5
+ end
@@ -0,0 +1,18 @@
1
+ desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
2
+ task :local_gemfile do |t|
3
+
4
+ root = Pathname(__FILE__).dirname.parent
5
+ datamapper = root.parent
6
+
7
+ source_regex = /DATAMAPPER = 'git:\/\/github.com\/datamapper'/
8
+ gem_source_regex = /:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/
9
+
10
+ root.join('Gemfile.local').open('w') do |f|
11
+ root.join('Gemfile').open.each do |line|
12
+ line.sub!(source_regex, "DATAMAPPER = '#{datamapper}'")
13
+ line.sub!(gem_source_regex, ':path => "#{DATAMAPPER}/\1"')
14
+ f.puts line
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,38 @@
1
+ spec_defaults = lambda do |spec|
2
+ spec.pattern = 'spec/**/*_spec.rb'
3
+ spec.libs << 'lib' << 'spec'
4
+ spec.spec_opts << '--options' << 'spec/spec.opts'
5
+ end
6
+
7
+ begin
8
+ require 'spec/rake/spectask'
9
+
10
+ Spec::Rake::SpecTask.new(:spec, &spec_defaults)
11
+ rescue LoadError
12
+ task :spec do
13
+ abort 'rspec is not available. In order to run spec, you must: gem install rspec'
14
+ end
15
+ end
16
+
17
+ begin
18
+ require 'rcov'
19
+ require 'spec/rake/verify_rcov'
20
+
21
+ Spec::Rake::SpecTask.new(:rcov) do |rcov|
22
+ spec_defaults.call(rcov)
23
+ rcov.rcov = true
24
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
25
+ end
26
+
27
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
28
+ rcov.threshold = 100
29
+ end
30
+ rescue LoadError
31
+ %w[ rcov verify_rcov ].each do |name|
32
+ task name do
33
+ abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
34
+ end
35
+ end
36
+ end
37
+
38
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'yard'
3
+
4
+ YARD::Rake::YardocTask.new
5
+ rescue LoadError
6
+ task :yard do
7
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'pathname'
3
+ require 'yardstick/rake/measurement'
4
+ require 'yardstick/rake/verify'
5
+
6
+ # yardstick_measure task
7
+ Yardstick::Rake::Measurement.new
8
+
9
+ # verify_measurements task
10
+ Yardstick::Rake::Verify.new do |verify|
11
+ verify.threshold = 100
12
+ end
13
+ rescue LoadError
14
+ %w[ yardstick_measure verify_measurements ].each do |name|
15
+ task name.to_s do
16
+ abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## Rubinius
17
+ *.rbc
18
+
19
+ ## PROJECT::GENERAL
20
+ *.gem
21
+ coverage
22
+ rdoc
23
+ pkg
24
+ tmp
25
+ doc
26
+ log
27
+ .yardoc
28
+ measurements
29
+
30
+ ## BUNDLER
31
+ .bundle
32
+ Gemfile.local
33
+ Gemfile.lock
34
+
35
+ ## PROJECT::SPECIFIC
36
+ spec/db/
@@ -0,0 +1,143 @@
1
+ # If you're working on more than one datamapper gem at a time, then it's
2
+ # recommended to create a local Gemfile and use this instead of the git
3
+ # sources. This will make sure that you are developing against your
4
+ # other local datamapper sources that you currently work on. Gemfile.local
5
+ # will behave identically to the standard Gemfile apart from the fact that
6
+ # it fetches the datamapper gems from local paths. This means that you can use
7
+ # the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
8
+ # bundle commands. Gemfile.local is added to .gitignore, so you don't need to
9
+ # worry about accidentally checking local development paths into git.
10
+ # In order to create a local Gemfile, all you need to do is run:
11
+ #
12
+ # bundle exec rake local_gemfile
13
+ #
14
+ # This will give you a Gemfile.local file that points to your local clones of
15
+ # the various datamapper gems. It's assumed that all datamapper repo clones
16
+ # reside in the same directory. You can use the Gemfile.local like so for
17
+ # running any bundle command:
18
+ #
19
+ # BUNDLE_GEMFILE=Gemfile.local bundle foo
20
+ #
21
+ # You can also specify which adapter(s) should be part of the bundle by setting
22
+ # an environment variable. This of course also works when using the Gemfile.local
23
+ #
24
+ # bundle foo # dm-sqlite-adapter
25
+ # ADAPTER=mysql bundle foo # dm-mysql-adapter
26
+ # ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
27
+ #
28
+ # Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
29
+ # and running specs against selected adapters.
30
+ #
31
+ # For easily working with adapters supported on your machine, it's recommended
32
+ # that you first install all adapters that you are planning to use or work on
33
+ # by doing something like
34
+ #
35
+ # ADAPTERS=sqlite,mysql,postgres bundle install
36
+ #
37
+ # This will clone the various repositories and make them available to bundler.
38
+ # Once you have them installed you can easily switch between adapters for the
39
+ # various development tasks. Running something like
40
+ #
41
+ # ADAPTER=mysql bundle exec rake spec
42
+ #
43
+ # will make sure that the dm-mysql-adapter is part of the bundle, and will be used
44
+ # when running the specs.
45
+ #
46
+ # You can also specify which plugin(s) should be part of the bundle by setting
47
+ # an environment variable. This also works when using the Gemfile.local
48
+ #
49
+ # bundle foo # dm-migrations
50
+ # PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
51
+ # PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
52
+ #
53
+ # Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
54
+ # for certain adapter/plugin combinations.
55
+ #
56
+ # Finally, to speed up running specs and other tasks, it's recommended to run
57
+ #
58
+ # bundle lock
59
+ #
60
+ # after running 'bundle install' for the first time. This will make 'bundle exec' run
61
+ # a lot faster compared to the unlocked version. With an unlocked bundle you would
62
+ # typically just run 'bundle install' from time to time to fetch the latest sources from
63
+ # upstream. When you locked your bundle, you need to run
64
+ #
65
+ # bundle install --relock
66
+ #
67
+ # to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
68
+ # is added to the .gitignore file, so you don't need to worry about accidentally checking
69
+ # it into version control.
70
+
71
+ source 'http://rubygems.org'
72
+
73
+ DATAMAPPER = 'git://github.com/datamapper'
74
+ DM_VERSION = '~> <%= DMGen::DM_VERSION %>'
75
+
76
+ group :runtime do # Runtime dependencies (as in the gemspec)
77
+
78
+ if ENV['EXTLIB']
79
+ gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
80
+ else
81
+ gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
82
+ end
83
+
84
+ gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
85
+ gem 'dm-adjust', DM_VERSION, :git => "#{DATAMAPPER}/dm-adjust.git"
86
+ gem 'dm-transactions', DM_VERSION, :git => "#{DATAMAPPER}/dm-transactions.git"
87
+
88
+ end
89
+
90
+ group(:development) do # Development dependencies (as in the gemspec)
91
+
92
+ gem 'rake', '~> 0.8.7'
93
+ gem 'rspec', '~> 1.3'
94
+ gem 'jeweler', '~> 1.4'
95
+
96
+ end
97
+
98
+ group :quality do # These gems contain rake tasks that check the quality of the source code
99
+
100
+ gem 'metric_fu', '~> 1.3'
101
+ gem 'rcov', '~> 0.9.8'
102
+ gem 'reek', '~> 1.2.8'
103
+ gem 'roodi', '~> 2.1'
104
+ gem 'yard', '~> 0.5'
105
+ gem 'yardstick', '~> 0.1'
106
+
107
+ end
108
+
109
+ group :datamapper do # We need this because we want to pin these dependencies to their git master sources
110
+
111
+ adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
112
+ adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
113
+
114
+ unless adapters.empty?
115
+
116
+ DO_VERSION = '~> 0.10.3'
117
+ DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
118
+
119
+ gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
120
+
121
+ adapters.each do |adapter|
122
+ if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
123
+ adapter = 'sqlite3' if adapter == 'sqlite'
124
+ gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
125
+ end
126
+ end
127
+
128
+ gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
129
+
130
+ adapters.each do |adapter|
131
+ gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
132
+ end
133
+
134
+ end
135
+
136
+ plugins = ENV['PLUGINS'] || ENV['PLUGIN']
137
+ plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
138
+
139
+ plugins.each do |plugin|
140
+ gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
141
+ end
142
+
143
+ end