chassis-datamapper 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ [DataMapper](http://datamapper.org) is a fast, thread-safe and feature rich Ruby ORM. The chassis-datamapper gem adds DataMapper gems, config, templates, and Rake tasks to Chassis.
2
+
3
+ ## Requirements
4
+
5
+ - [sinatra-chassis](http://jarrodtaylor.github.io/sinatra-chassis/) v1.1+
6
+ - Experience with [DataMapper](http://datamapper.org).
7
+
8
+ ## Installation
9
+
10
+ Add the chassis-datamapper extension to your gemfile:
11
+
12
+ gem 'chassis-datamapper'
13
+
14
+ Then run ```bundle install``` again.
15
+
16
+ ## Setup
17
+
18
+ Using DataMapper requires a bit of setup. Running ```rake datamapper:setup``` gets the process started:
19
+
20
+ - The data_mapper gem is added to your Gemfile.
21
+ - The dm-sqlite-adapter, dm-mysql-adapter, and dm-postgres-adapter adapters are added to your Gemfile.
22
+ - Make sure to uncomment and group your development and production gems. Typically, the resulting Gemfile will include something like this:
23
+
24
+ ```
25
+ gem 'data_mapper', '~> 1.2.0'
26
+ gem 'dm-sqlite-adapter', '~> 1.2.0', group: :development
27
+ gem 'dm-postgres-adapter', '~> 1.2.0', group: :production
28
+ ```
29
+
30
+ - DataMapper.setup is used in /settings/datamapper.rb to set database connection strings.
31
+ - DataMapper.finalize is added to the end of app.rb to initialize all your models.
32
+
33
+ After adding DataMapper to the Gemfile, you'll need to run ```bundle install``` again.
34
+
35
+ ## Models and Auto Upgrading
36
+
37
+ > This examples create a User model.
38
+
39
+ Models and tests can be added with the task ```rake dm:add:model[user]```.
40
+
41
+ Instead of running a migration, DataMapper can use the auto_upgrade! method to non-destructively bring your database up to date with your models by running ```rake dm:upgrade[User]```.
42
+
43
+ Leaving out the [model] argument will upgrade your database to match all your models: ```rake dm:upgrade```.
44
+
45
+ ## Migrations
46
+
47
+ The task ```rake dm:migrate[User]``` is similar to dm:upgrade[model], only it's destructive.
48
+
49
+ Again, like dm:upgrade[model], leaving off the [model] argument will auto migrate your database to match all your models.
50
+
51
+ To add a custom migration, use the task ```rake dm:add:migration[add_users]```. The name argument is required to name your migration.
52
+
53
+ The new migration includes timestamp, which is used for migrating up or down to a specific migration: ```rake dm:migrate:up[20130130013853]``` or ```rake dm:migrate:down[20130130013853]```.
54
+
55
+ ## Seed Data
56
+
57
+ > This example adds a list of states as seed data.
58
+
59
+ If your database needs seed data to run, use the task ```rake dm:add:seed[add_list_of_states]```.
60
+
61
+ After filling out the seed script, run it with the rake task dm:seed[add_list_of_states].
62
+
63
+ Leaving out the [file] argument will run all the scripts in /data/seeds.
64
+
65
+ ## Release Notes
66
+
67
+ ##### v1.0.0 (June 16, 2013)
68
+
69
+ - First!
70
+
71
+ ## License
72
+
73
+ Copyright (C) 2013 Jarrod Taylor.
74
+
75
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
76
+
77
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
78
+
79
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+
6
+ s.name = 'chassis-datamapper'
7
+ s.version = '1.0.0'
8
+ s.author = 'Jarrod Taylor'
9
+ s.email = 'jarrodtaylor@icloud.com'
10
+ s.homepage = 'https://github.com/jarrodtaylor/chassis-datamapper'
11
+ s.summary = 'Adds DataMapper gems, config, templates, and Rake tasks to Chassis.'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ s.required_ruby_version = ">= 1.9.2"
19
+
20
+ s.add_dependency 'sinatra-chassis', '>= 1.1.0'
21
+
22
+ end
@@ -0,0 +1 @@
1
+ # Code here will be available to apps using your extension.
@@ -0,0 +1,110 @@
1
+ namespace :dm do
2
+
3
+ def create_dm_path
4
+ if DataMapper.repository.adapter.options[:path].include? 'sqlite'
5
+ db = DataMapper.repository.adapter.options[:path].split('/').last
6
+ create_directory DataMapper.repository.adapter.options[:path].gsub(db, '')
7
+ end
8
+ end
9
+
10
+ desc 'Set up DataMapper'
11
+ task :setup do
12
+ create_directory './settings'
13
+ append_to_file './Gemfile', "\ngem 'data_mapper', '~> 1.2.0'"
14
+ append_to_file './Gemfile', "\n# gem 'dm-sqlite-adapter', '~> 1.2.0'"
15
+ append_to_file './Gemfile', "\n# gem 'dm-mysql-adapter', '~> 1.2.0'"
16
+ append_to_file './Gemfile', "\n# gem 'dm-postgres-adapter', '~> 1.2.0'\n"
17
+ system 'bundle install'
18
+ append_to_file './app.rb', "\nDataMapper.finalize\n"
19
+ copy_file "#{File.dirname(__FILE__)}/../templates/settings.rb",
20
+ "./settings/datamapper.rb"
21
+ end
22
+
23
+ namespace :add do
24
+
25
+ desc 'Add a data migration' if defined? DataMapper
26
+ task :migration, :name do |t, args|
27
+ if args.name == nil
28
+ puts 'You must define a migration name.'
29
+ puts 'Example: rake add:migration[my_migration]'
30
+ exit
31
+ end
32
+ create_directory './data', './data/migrations'
33
+ t = Time.now.strftime("%Y%m%d%H%M%S")
34
+ copy_template "#{File.dirname(__FILE__)}/../templates/migration.rb",
35
+ "./data/migrations/#{t}_#{args.name}.rb",
36
+ { t: t, migration: args.name }
37
+ end
38
+
39
+ desc 'Add a model' if defined? DataMapper
40
+ task :model, :name do |t, args|
41
+ if args.name == nil
42
+ puts 'You must define a model name.'
43
+ puts 'Example: rake add:model[my_model]'
44
+ exit
45
+ end
46
+ create_directory './models', './tests', './tests/models'
47
+ copy_template "#{File.dirname(__FILE__)}/../templates/model.rb",
48
+ "./models/#{args.name}.rb",
49
+ { model: args.name }
50
+ copy_template "#{File.dirname(__FILE__)}/../templates/test.rb",
51
+ "./tests/models/#{args.name}_tests.rb",
52
+ { model: args.name }
53
+ end
54
+
55
+ desc 'Add a seed data script' if defined? DataMapper
56
+ task :seed, :name do |t, args|
57
+ if args.name == nil
58
+ puts 'You must define a seed file name.'
59
+ puts 'Example: rake add:seed[my_seed_script]'
60
+ exit
61
+ end
62
+ create_directory './data', './data/seeds'
63
+ copy_template "#{File.dirname(__FILE__)}/../templates/seed.rb",
64
+ "./data/seeds/#{args.name}.rb"
65
+ end
66
+
67
+ end
68
+
69
+ desc 'Auto upgrade one or all models' if defined? DataMapper
70
+ task :upgrade, :model do |t, args|
71
+ create_dm_path
72
+ args.model == nil ? DataMapper.auto_upgrade! : args.model.constantize.auto_upgrade!
73
+ end
74
+
75
+ desc 'Auto migrate one or all models' if defined? DataMapper
76
+ task :migrate, :model do |t, args|
77
+ create_dm_path
78
+ args.model == nil ? DataMapper.auto_migrate! : args.model.constantize.auto_migrate!
79
+ end
80
+
81
+ namespace :migrate do
82
+
83
+ desc 'Migrate up to a specific migration number' if defined? DataMapper
84
+ task :up, :number do |t, args|
85
+ create_dm_path
86
+ require 'dm-migrations/migration_runner'
87
+ Dir['./data/migrations/*.rb'].each { |m| require m }
88
+ args.number == nil ? migrate_up! : migrate_up!(args.number)
89
+ end
90
+
91
+ desc 'Migrate down to a specific migration number' if defined? DataMapper
92
+ task :down, :number do |t, args|
93
+ create_dm_path
94
+ require 'dm-migrations/migration_runner'
95
+ Dir['./data/migrations/*.rb'].each { |m| require m }
96
+ args.number == nil ? migrate_down! : migrate_down!(args.number)
97
+ end
98
+
99
+ end
100
+
101
+ desc 'Run one or all /data/seeds scripts' if defined? DataMapper
102
+ task :seed, :file do |t, args|
103
+ if args.file == nil
104
+ Dir["./data/seeds/**/*.rb"].each { |file| require file }
105
+ else
106
+ require "./data/seeds/#{args.file}"
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,13 @@
1
+ migration <%= locals[:t] %>, :<%= locals[:migration] %> do
2
+
3
+ up do
4
+ # create_table :widgets do
5
+ # column :id, Integer, serial: true
6
+ # end
7
+ end
8
+
9
+ down do
10
+ # drop_table :widgets
11
+ end
12
+
13
+ end
@@ -0,0 +1,8 @@
1
+ class <%= locals[:model].capitalize %>
2
+ include DataMapper::Resource
3
+
4
+ timestamps :at, :on
5
+ property :deleted_at, ParanoidDateTime
6
+ property :id, Serial
7
+
8
+ end
@@ -0,0 +1 @@
1
+ # User.first_or_create(email: 'johndoe@example.com')
@@ -0,0 +1,16 @@
1
+ configure :development do
2
+ DataMapper::Logger.new $stdout, :debug
3
+ # DataMapper.setup :default, 'sqlite::memory:'
4
+ DataMapper.setup :default, "sqlite://#{Dir.pwd}/data/development.sqlite3"
5
+ # DataMapper.setup :default, 'mysql://username:password@host_url:3306/database_name'
6
+ # DataMapper.setup :default, 'postgres://username:password@host_url:5432/database_name'
7
+ end
8
+
9
+ configure :production do
10
+ # DataMapper::Logger.new $stdout, :debug
11
+ # DataMapper.setup :default, 'sqlite::memory:'
12
+ # DataMapper.setup :default, "sqlite://#{Dir.pwd}/data/production.sqlite3"
13
+ # DataMapper.setup :default, 'mysql://username:password@host_url:3306/database_name'
14
+ # DataMapper.setup :default, 'postgres://username:password@host_url:5432/database_name'
15
+ # DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'minitest/autorun'
2
+ require 'rack/test'
3
+ require './app'
4
+
5
+ class <%= locals[:model].capitalize %>Tests < MiniTest::Unit::TestCase
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ Sinatra::Application
10
+ end
11
+
12
+ # def test_made_by
13
+ # <%= locals[:model] %> = <%= locals[:model].capitalize %>.new
14
+ # assert_equal <%= locals[:model] %>.made_by, 'Acme Corp.'
15
+ # end
16
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chassis-datamapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jarrod Taylor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra-chassis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ description:
31
+ email: jarrodtaylor@icloud.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - README.md
39
+ - Rakefile
40
+ - chassis-datamapper.gemspec
41
+ - lib/chassis-datamapper.rb
42
+ - lib/chassis/tasks/chassis-datamapper.rake
43
+ - lib/chassis/templates/migration.rb
44
+ - lib/chassis/templates/model.rb
45
+ - lib/chassis/templates/seed.rb
46
+ - lib/chassis/templates/settings.rb
47
+ - lib/chassis/templates/test.rb
48
+ homepage: https://github.com/jarrodtaylor/chassis-datamapper
49
+ licenses:
50
+ - MIT
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 1.9.2
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.25
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Adds DataMapper gems, config, templates, and Rake tasks to Chassis.
73
+ test_files: []
74
+ has_rdoc: