dm-gen 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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,2 @@
1
+ = <%= gem_name %>
2
+
@@ -1,30 +1,22 @@
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.email = 'EMAIL'
9
+ gem.homepage = 'http://github.com/USERNAME/<%= gem_name %>'
10
+ gem.authors = [ 'NAME' ]
9
11
 
10
- require ROOT + 'lib/<%= gem_name %>/is/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::Is::<%= class_name %>::VERSION
14
+ gem.add_development_dependency 'rspec', '~> 1.3'
15
+ end
15
16
 
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"]
17
+ Jeweler::GemcutterTasks.new
27
18
 
19
+ FileList['tasks/**/*.rake'].each { |task| import task }
20
+ rescue LoadError
21
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
28
22
  end
29
-
30
- Pathname.glob(ROOT.join('tasks/**/*.rb').to_s).each { |f| require f }
@@ -0,0 +1 @@
1
+ 1.0.0.rc2
@@ -1,8 +1 @@
1
- # Add all external dependencies for the plugin here
2
- # require 'dm-core' - this can probably be assumed.
3
-
4
- # Require plugin-files
5
- require '<%= gem_name %>/is/<%= snake_name %>.rb'
6
-
7
- # Include the plugin in DM models
8
- DataMapper::Model.append_extensions DataMapper::Is::<%= class_name %>
1
+ require '<%= gem_name %>/is/<%= name %>'
@@ -0,0 +1,30 @@
1
+ require 'dm-core'
2
+
3
+ module DataMapper
4
+ module Is
5
+ module <%= class_name %>
6
+
7
+ # method for making your model a <%= name %>
8
+ #
9
+ # @api public
10
+ def is_<%= name %>(options={})
11
+
12
+ extend DataMapper::Is::<%= class_name %>::ClassMethods
13
+ include DataMapper::Is::<%= class_name %>::InstanceMethods
14
+
15
+ # other setup goes here!
16
+
17
+
18
+ end # is_list
19
+
20
+ module ClassMethods
21
+ end
22
+
23
+ module InstanceMethods
24
+ end # InstanceMethods
25
+ end # <%= class_name %>
26
+ end # Is
27
+
28
+ Model.append_extensions(Is::<%= class_name %>)
29
+
30
+ end # DataMapper
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'DataMapper::Is::<%= class_name %>' do
4
+
5
+ supported_by :sqlite, :postgres, :mysql, :oracle, :sqlserver do
6
+
7
+ before :each do
8
+ DataMapper.auto_migrate!
9
+ end
10
+
11
+ it "needs somes specs"
12
+
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,6 @@
1
+ --exclude "spec"
2
+ --sort coverage
3
+ --callsites
4
+ --xrefs
5
+ --profile
6
+ --text-summary
@@ -1 +1,4 @@
1
1
  --colour
2
+ --loadby random
3
+ --format profile
4
+ --backtrace
@@ -1,26 +1,12 @@
1
- require 'pathname'
2
- require 'rubygems'
1
+ require 'dm-core/spec/setup'
2
+ require 'dm-core/spec/lib/adapter_helpers'
3
3
 
4
- gem 'rspec', '~>1.1.11'
5
- require 'spec'
4
+ require '<%= gem_name %>'
5
+ require 'dm-migrations'
6
6
 
7
- require Pathname(__FILE__).dirname.expand_path.parent + 'lib/<%= gem_name %>'
7
+ DataMapper::Spec.setup
8
8
 
9
- def load_driver(name, default_uri)
10
- return false if ENV['ADAPTER'] != name.to_s
11
9
 
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
10
+ Spec::Runner.configure do |config|
11
+ config.extend(DataMapper::Spec::Adapters::Helpers)
20
12
  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 @@
1
+ task :ci => [ :verify_measurements, 'metrics:all' ]
@@ -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,36 @@
1
+ begin
2
+ require 'metric_fu'
3
+ rescue LoadError
4
+ namespace :metrics do
5
+ task :all do
6
+ abort 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
7
+ end
8
+ end
9
+ end
10
+
11
+ begin
12
+ require 'reek/adapters/rake_task'
13
+
14
+ Reek::RakeTask.new do |t|
15
+ t.fail_on_error = true
16
+ t.verbose = false
17
+ t.source_files = 'lib/**/*.rb'
18
+ end
19
+ rescue LoadError
20
+ task :reek do
21
+ abort 'Reek is not available. In order to run reek, you must: gem install reek'
22
+ end
23
+ end
24
+
25
+ begin
26
+ require 'roodi'
27
+ require 'roodi_task'
28
+
29
+ RoodiTask.new do |t|
30
+ t.verbose = false
31
+ end
32
+ rescue LoadError
33
+ task :roodi do
34
+ abort 'Roodi is not available. In order to run roodi, you must: gem install roodi'
35
+ end
36
+ 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
@@ -3,10 +3,11 @@
3
3
  # A one file test to show ...
4
4
  require 'rubygems'
5
5
  require 'dm-core'
6
+ require 'dm-migrations'
6
7
 
7
8
 
8
9
  # setup the logger
9
- DataMapper::Logger.new(STDOUT, :debug)
10
+ DataMapper::Logger.new($stdout, :debug)
10
11
 
11
12
  # connect to the DB
12
13
  DataMapper.setup(:default, 'sqlite3::memory:')
@@ -21,7 +22,7 @@ class <%= model_name %>
21
22
  <% end %>
22
23
  end
23
24
 
24
- DataMapper.auto_migrate!
25
+ DataMapper.finalize.auto_migrate!
25
26
 
26
27
  # put the code here!
27
28
 
@@ -4,7 +4,7 @@ require 'templater'
4
4
  module DMGen
5
5
  extend Templater::Manifold
6
6
 
7
- DM_VERSION = '0.10.0'
7
+ DM_VERSION = '1.0'
8
8
 
9
9
  desc <<-eos
10
10
  Generates files for the DataMapper ORM.
@@ -5,95 +5,77 @@ describe "DMGen::Adapter" do
5
5
  @generator = DMGen::Adapter.new('/tmp', {}, 'awesome')
6
6
  end
7
7
 
8
+
9
+ describe "renders all templates without errors" do
10
+ DMGen::Adapter.new('/tmp', {}, 'awesome').templates.each do |template|
11
+ it "should render '#{template.name}' without raising" do
12
+ lambda { template.render }.should.not.raise(Exception)
13
+ end
14
+ end
15
+ end
16
+
8
17
  # basic file creation.
9
18
  it "creates a Rakefile" do
10
19
  @generator.should create('/tmp/dm-awesome-adapter/Rakefile')
11
20
  end
12
21
  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')
22
+ @generator.should create('/tmp/dm-awesome-adapter/lib/dm-awesome-adapter.rb')
23
+ @generator.should create('/tmp/dm-awesome-adapter/lib/dm-awesome-adapter/adapter.rb')
24
+ @generator.should create('/tmp/dm-awesome-adapter/lib/dm-awesome-adapter/spec/setup.rb')
15
25
  end
16
26
  it "creates the spec folder layout" do
17
- @generator.should create('/tmp/dm-awesome-adapter/spec/integration/awesome_adapter_spec.rb')
27
+ @generator.should create('/tmp/dm-awesome-adapter/spec/adapter_spec.rb')
18
28
  @generator.should create('/tmp/dm-awesome-adapter/spec/spec.opts')
29
+ @generator.should create('/tmp/dm-awesome-adapter/spec/rcov.opts')
19
30
  @generator.should create('/tmp/dm-awesome-adapter/spec/spec_helper.rb')
20
31
  end
21
32
  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')
33
+ @generator.should create('/tmp/dm-awesome-adapter/README.rdoc')
26
34
  end
27
35
  it "creates a LICENSE" do
28
36
  @generator.should create('/tmp/dm-awesome-adapter/LICENSE')
29
37
  end
30
- it "creates a Manifest for Hoe" do
31
- @generator.should create('/tmp/dm-awesome-adapter/Manifest.txt')
38
+ it "creates a Gemfile" do
39
+ @generator.should create('/tmp/dm-awesome-adapter/Gemfile')
32
40
  end
33
- it "creates a TODO list" do
34
- @generator.should create('/tmp/dm-awesome-adapter/TODO')
41
+ it "creates a .gitignore" do
42
+ @generator.should create('/tmp/dm-awesome-adapter/.gitignore')
35
43
  end
36
44
  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')
45
+ @generator.should create('/tmp/dm-awesome-adapter/tasks/local_gemfile.rake')
46
+ @generator.should create('/tmp/dm-awesome-adapter/tasks/spec.rake')
47
+ @generator.should create('/tmp/dm-awesome-adapter/tasks/yard.rake')
48
+ @generator.should create('/tmp/dm-awesome-adapter/tasks/yardstick.rake')
39
49
  end
40
50
 
41
- describe "Manifest.txt" do
51
+ describe "spec/spec_helper.rb" do
42
52
  before do
43
- @template = @generator.template(:manifest_txt)
53
+ @template = @generator.template(:spec_spec_helper_rb)
44
54
  @result = @template.render
45
55
  end
46
56
 
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
57
  end
55
58
 
56
- describe "version.rb" do
59
+ describe "Rakefile" do
57
60
  before do
58
- @template = @generator.template(:lib_adapter_file_version_rb)
59
- @result = @template.render
61
+ @template = @generator.template(:rakefile)
62
+ @result = @template.render
60
63
  end
61
64
 
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
65
+ it "includes an approriate dependency on dm-core" do
66
+ @result.should.include("gem.add_dependency 'dm-core', '~> #{DMGen::DM_VERSION}'")
70
67
  end
71
68
  end
72
69
 
73
- describe "spec/spec_helper.rb" do
70
+ describe "LICENSE" do
74
71
  before do
75
- @template = @generator.template(:spec_spec_helper_rb)
72
+ @template = @generator.template(:license)
76
73
  @result = @template.render
77
74
  end
78
75
 
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
76
+ it "has the correct copyright declaration" do
77
+ @result.should.include("Copyright (c) #{Time.now.year} NAME")
93
78
  end
94
79
 
95
- it "requires the version file" do
96
- @result.should.include(%q{require ROOT + 'lib/awesome_adapter/version'})
97
- end
98
80
  end
99
81
  end