portugal 0.0.3

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDkxZjlkYTE4MTZiMDA5NzdmZDBiZGQ5YjNjZDhkNTJlNWJhMzRmMA==
5
+ data.tar.gz: !binary |-
6
+ NDY0ODgyNjdkZjNlZDY4NDJjZGZlOGM5MWZhYjFmNDE3NmYxNTgxOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NzI5ODQ1YmEzNDIwMDdjMTA1NDE4ZjVmZDE1NWI0ZjhkMWUxNTE0NDk0YTE3
10
+ Y2FmM2Y0NzkyYTIzNWI3M2ViMmExMTFiNDU3ZmZkZWM2MGIzOWY5MzczNmM5
11
+ NjY4ZWJlYWEzODhhMjQ2MzUxYTdmY2NlYTE5OGI2MmMzMmQxMDI=
12
+ data.tar.gz: !binary |-
13
+ YzFiOTQyMDM2OTZhYjlmNTAxZjEyNTg1MTQ5NDk0NWZiMmIwZmI0Yzc0YzEx
14
+ YjZiYmY2YmFlNzQ1ODRlZDlkMDIwZGVlNmY0OTI0YTIxODhjYjNiOTBmNmJi
15
+ NjA3NTdlYmIzYjQzODI4NDdlYWJkNTkyYWM3ZTkyMjMwYWY3MzQ=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format progress
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Rémi Prévost
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # Portugal
2
+
3
+ Use ActiveRecord migrations, but not in Rails.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'portugal'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ $ bundle install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ In your `Rakefile`:
22
+
23
+ ```ruby
24
+ require 'portugal/tasks'
25
+ Portugal.configure do |config|
26
+ config.migrations_path = File.expand_path("../config/migrations", __FILE__)
27
+ end
28
+
29
+ # This task is called before Portugal executes its tasks.
30
+ # It should require ActiveRecord somehow and establish the database connection
31
+ #
32
+ # Change it so it works for your application
33
+ task :environment do
34
+ require 'bundler'
35
+ Bundle.require
36
+ ActiveRecord::Base.establish_connection({})
37
+ end
38
+ ```
39
+
40
+ Then, in your shell:
41
+
42
+ ```shell
43
+ $ bundle exec rake -T | grep 'db:'
44
+ rake db:migrate # Migrate the database
45
+ rake db:new_migration # Create a new migration file (specify name w/ NAME=do_something)
46
+ rake db:rollback # Rolls the database back to the previous version (specify steps w/ STEP=n).
47
+ ```
48
+
49
+ Yay!
50
+
51
+ ## Inspiration
52
+
53
+ _**Gob**: Portugal? Well, gonna live it up in ol’ South America, aren’t we, Michael?_
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run all specs in spec directory"
5
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,20 @@
1
+ require 'portugal/version'
2
+ require 'erb'
3
+ require 'ostruct'
4
+
5
+ require 'active_record'
6
+ require 'active_support/inflector'
7
+
8
+ require 'portugal/migrator'
9
+ require 'portugal/migration'
10
+
11
+ module Portugal
12
+ def self.configure(&blk)
13
+ @config = self.config
14
+ blk.yield(@config)
15
+ end
16
+
17
+ def self.config
18
+ @config || OpenStruct.new(:verbose => true)
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module Portugal
2
+ class Migration
3
+ def initialize(name)
4
+ raise ArgumentError, "You must pass a migration name (eg. rake db:new_migration NAME=do_something)" unless name
5
+
6
+ name = name.gsub(/\s/, '_')
7
+
8
+ filename = File.join(Portugal.config.migrations_path, "#{"%03d" % Migration.next_migration_number}_#{name.underscore}.rb")
9
+ content = Migration.generate_content(binding)
10
+
11
+ File.open(filename, 'w+') { |data| data << content }
12
+
13
+ puts "Generated #{filename}" if Portugal.config.verbose
14
+ end
15
+
16
+ def self.generate_content(binding)
17
+ @template ||= ERB.new(File.read(File.expand_path("../templates/new_migration.rb", __FILE__)))
18
+ @template.result(binding)
19
+ end
20
+
21
+ def self.next_migration_number
22
+ migration_number = Dir[File.join(Portugal.config.migrations_path, '*.rb')].inject(1) do |memo, item|
23
+ filename = File.basename(item, File.extname(item))
24
+ number = filename.gsub(/\A(\d+)_.*\Z/, '\1').to_i + 1
25
+ number > memo ? number : memo
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Portugal
2
+ class Migrator
3
+ def self.migrate!
4
+ ActiveRecord::Migration.verbose = Portugal.config.verbose
5
+ ActiveRecord::Migrator.migrate Portugal.config.migrations_path
6
+ end
7
+
8
+ def self.rollback!(step)
9
+ ActiveRecord::Migration.verbose = Portugal.config.verbose
10
+ ActiveRecord::Migrator.rollback Portugal.config.migrations_path, step
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require 'portugal'
2
+
3
+ namespace :db do
4
+ desc "Migrate the database"
5
+ task :migrate => :environment do
6
+ Portugal::Migrator.migrate!
7
+ end
8
+
9
+ desc "Rolls the database back to the previous version (specify steps w/ STEP=n)."
10
+ task :rollback => :environment do
11
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
12
+ Portugal::Migrator.rollback!(step)
13
+ end
14
+
15
+ desc "Create a new migration file (specify name w/ NAME=do_something)"
16
+ task :new_migration => :environment do
17
+ Portugal::Migration.new(ENV["NAME"])
18
+ end
19
+ end
20
+
@@ -0,0 +1,10 @@
1
+ class <%= name.camelize %> < ActiveRecord::Migration
2
+ def up
3
+ end
4
+
5
+ def down
6
+ end
7
+
8
+ # def change
9
+ # end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Portugal
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'portugal/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "portugal"
8
+ gem.version = Portugal::VERSION
9
+ gem.authors = ["Rémi Prévost"]
10
+ gem.email = ["remi@exomel.com"]
11
+ gem.description = %q{ActiveRecord migrations without Rails}
12
+ gem.summary = %q{ActiveRecord migrations without Rails}
13
+ gem.homepage = "https://github.com/remiprev/portugal"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "activerecord", ">= 3.0.0"
21
+ gem.add_runtime_dependency "rake"
22
+
23
+ gem.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Portugal::Migration do
4
+ describe :initialize do
5
+ let(:create_migration!) { Portugal::Migration.new("foo_bar") }
6
+
7
+ context "without existing migrations" do
8
+ before do
9
+ File.should_receive(:open).with(File.join(Portugal.config.migrations_path, "001_foo_bar.rb"), 'w+')
10
+ end
11
+
12
+ it("creates the first migration file") { create_migration! }
13
+ end
14
+
15
+ context "with existing migrations" do
16
+ before do
17
+ Portugal::Migration.should_receive(:next_migration_number).and_return(2)
18
+ File.should_receive(:open).with(File.join(Portugal.config.migrations_path, "002_foo_bar.rb"), 'w+')
19
+ end
20
+
21
+ it("creates a new file while incrementing the migraton number") { create_migration! }
22
+ end
23
+
24
+ context "with empty name argument" do
25
+ it "raises an exception" do
26
+ expect { Portugal::Migration.new }.to raise_error(ArgumentError)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Portugal::Migrator do
4
+ describe :migrate! do
5
+ before { ActiveRecord::Migrator.should_receive(:migrate).with(Portugal.config.migrations_path) }
6
+ it("calls ActiveRecord::Migrator.migrate") { Portugal::Migrator.migrate! }
7
+ end
8
+
9
+ describe :rollback! do
10
+ before { ActiveRecord::Migrator.should_receive(:rollback).with(Portugal.config.migrations_path, 2) }
11
+ it("calls ActiveRecord::Migrator.rollback") { Portugal::Migrator.rollback!(2) }
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require "rspec"
4
+ require "portugal"
5
+
6
+ RSpec.configure do |config|
7
+ config.before :each do
8
+ Portugal.configure do |config|
9
+ config.migrations_path = File.expand_path(__FILE__)
10
+ config.verbose = false
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: portugal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Rémi Prévost
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ActiveRecord migrations without Rails
56
+ email:
57
+ - remi@exomel.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/portugal.rb
69
+ - lib/portugal/migration.rb
70
+ - lib/portugal/migrator.rb
71
+ - lib/portugal/tasks.rb
72
+ - lib/portugal/templates/new_migration.rb
73
+ - lib/portugal/version.rb
74
+ - portugal.gemspec
75
+ - spec/migration_spec.rb
76
+ - spec/migrator_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/remiprev/portugal
79
+ licenses: []
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.0
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: ActiveRecord migrations without Rails
101
+ test_files:
102
+ - spec/migration_spec.rb
103
+ - spec/migrator_spec.rb
104
+ - spec/spec_helper.rb