phil_columns-activerecord 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/lib/phil_columns-activerecord.rb +1 -0
- data/lib/phil_columns/activerecord.rb +16 -0
- data/lib/phil_columns/activerecord/archivist.rb +46 -0
- data/lib/phil_columns/activerecord/migrator.rb +94 -0
- data/lib/phil_columns/activerecord/schema_seed.rb +9 -0
- data/lib/phil_columns/activerecord/silence_streams.rb +17 -0
- data/lib/phil_columns/activerecord/version.rb +5 -0
- data/phil_columns-activerecord.gemspec +25 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e73a66ad89c5068896ea6b20a2184ef958d6677
|
4
|
+
data.tar.gz: 14a25558716baff69eebb8c2fa7c92232ac70b72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d62b79978befdf09c3d7749ecd4195a2202613a176b2fc8d7759a3c030431e44532ac179a237c000861195f72fbc929852114238e183cf90477da6680dc22c76
|
7
|
+
data.tar.gz: b934d7a6c503ec3d35cdb3df58cec956c4b760f5c4cad59a3b46d5e1e146b71ab7b566c8293ed6eaf0867062a56a43f65de8735c0370d1e131e7bc55d7905eff
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
phil_columns
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jason Harrelson
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# PhilColumns::Activerecord
|
2
|
+
|
3
|
+
Phil_columns adapter for activerecord.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'phil_columns-activerecord'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install phil_columns-activerecord
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
See [phil_columns](https://github.com/midas/phil_columns) gem.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
require "phil_columns/activerecord"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "phil_columns/activerecord/version"
|
2
|
+
require "active_record"
|
3
|
+
|
4
|
+
module PhilColumns
|
5
|
+
module Activerecord
|
6
|
+
|
7
|
+
autoload :Archivist, 'phil_columns/activerecord/archivist'
|
8
|
+
autoload :Migrator, 'phil_columns/activerecord/migrator'
|
9
|
+
autoload :SchemaSeed, 'phil_columns/activerecord/schema_seed'
|
10
|
+
autoload :SilenceStreams, 'phil_columns/activerecord/silence_streams'
|
11
|
+
|
12
|
+
PhilColumns::archivist_klass = PhilColumns::Activerecord::Archivist
|
13
|
+
PhilColumns::migrator_klass = PhilColumns::Activerecord::Migrator
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module PhilColumns
|
2
|
+
module Activerecord
|
3
|
+
class Archivist
|
4
|
+
|
5
|
+
include SilenceStreams
|
6
|
+
|
7
|
+
def record_seed( version )
|
8
|
+
ensure_schema_seeds_table!
|
9
|
+
return if seed_already_executed?( version )
|
10
|
+
|
11
|
+
SchemaSeed.new.tap do |schema_seed|
|
12
|
+
schema_seed.version = version
|
13
|
+
schema_seed.save!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove_seed( version )
|
18
|
+
ensure_schema_seeds_table!
|
19
|
+
|
20
|
+
SchemaSeed.where( version: version ).delete_all #first.tap do |schema_seed|
|
21
|
+
end
|
22
|
+
|
23
|
+
def clear_seeds
|
24
|
+
SchemaSeed.delete_all
|
25
|
+
end
|
26
|
+
|
27
|
+
def seed_already_executed?( version )
|
28
|
+
ensure_schema_seeds_table!
|
29
|
+
SchemaSeed.where( version: version ).exists?
|
30
|
+
end
|
31
|
+
|
32
|
+
def ensure_schema_seeds_table!
|
33
|
+
return if ActiveRecord::Base.connection.table_exists?( :schema_seeds )
|
34
|
+
|
35
|
+
silence_streams do
|
36
|
+
ActiveRecord::Schema.define do
|
37
|
+
create_table :schema_seeds, id: false do |t|
|
38
|
+
t.column :version, :string, limit: 20, null: false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module PhilColumns
|
4
|
+
module Activerecord
|
5
|
+
class Migrator
|
6
|
+
|
7
|
+
include SilenceStreams
|
8
|
+
|
9
|
+
def down( version=0 )
|
10
|
+
silence_streams do
|
11
|
+
ActiveRecord::Migrator.down( ActiveRecord::Migrator.migrations_path, version )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def up( version=nil )
|
16
|
+
silence_streams do
|
17
|
+
ActiveRecord::Migrator.up( ActiveRecord::Migrator.migrations_path, version )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear_migrations_table
|
22
|
+
case connection_config[:adapter]
|
23
|
+
when 'sqlite', 'sqlite3'
|
24
|
+
connection.execute("DELETE FROM #{table_name}")
|
25
|
+
connection.execute("DELETE FROM sqlite_sequence where name='#{table_name}'")
|
26
|
+
else
|
27
|
+
ActiveRecord::Base.connection.execute( "TRUNCATE #{schema_migrations_table_name}" )
|
28
|
+
end
|
29
|
+
|
30
|
+
connection.execute( 'VACUUM' ) if connection_config[:adapter] == 'sqlite3'
|
31
|
+
end
|
32
|
+
|
33
|
+
def latest_version
|
34
|
+
ActiveRecord::Migrator.get_all_versions.sort.last
|
35
|
+
end
|
36
|
+
|
37
|
+
def connection
|
38
|
+
ActiveRecord::Base::connection
|
39
|
+
end
|
40
|
+
|
41
|
+
def connection_config
|
42
|
+
connection.instance_variable_get( '@config' )
|
43
|
+
end
|
44
|
+
|
45
|
+
def drop_tables
|
46
|
+
tables.each do |table|
|
47
|
+
drop_table( table )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def drop_table( table )
|
52
|
+
silence_streams do
|
53
|
+
if ActiveRecord::Migration.table_exists?( table )
|
54
|
+
ActiveRecord::Migration.drop_table( table )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def load_schema
|
60
|
+
silence_streams do
|
61
|
+
if schema_filepath.exist?
|
62
|
+
load( schema_filepath.expand_path )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def migrations_path
|
68
|
+
ActiveRecord::Migrator.migrations_path
|
69
|
+
end
|
70
|
+
|
71
|
+
def schema_filepath
|
72
|
+
Pathname.new( migrations_path.gsub( 'migrate', 'schema.rb' ))
|
73
|
+
end
|
74
|
+
|
75
|
+
def tables
|
76
|
+
ActiveRecord::Base::connection.
|
77
|
+
tables.
|
78
|
+
reject { |t| exclude_tables.include?( t ) }
|
79
|
+
end
|
80
|
+
|
81
|
+
def exclude_tables
|
82
|
+
[
|
83
|
+
schema_migrations_table_name,
|
84
|
+
'schema_seeds'
|
85
|
+
]
|
86
|
+
end
|
87
|
+
|
88
|
+
def schema_migrations_table_name
|
89
|
+
ActiveRecord::Migrator.schema_migrations_table_name
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'phil_columns/activerecord/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "phil_columns-activerecord"
|
8
|
+
spec.version = PhilColumns::Activerecord::VERSION
|
9
|
+
spec.authors = ["C. Jason Harrelson (midas)"]
|
10
|
+
spec.email = ["jason@lookforwardenterprises.com"]
|
11
|
+
spec.summary = %q{Phil_columns adapter for activerecord.}
|
12
|
+
spec.description = %q{Phil_columns adapter for activerecord. See README for more details.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "activerecord"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phil_columns-activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- C. Jason Harrelson (midas)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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: :development
|
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: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Phil_columns adapter for activerecord. See README for more details.
|
56
|
+
email:
|
57
|
+
- jason@lookforwardenterprises.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-gemset"
|
64
|
+
- ".ruby-version"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/phil_columns-activerecord.rb
|
70
|
+
- lib/phil_columns/activerecord.rb
|
71
|
+
- lib/phil_columns/activerecord/archivist.rb
|
72
|
+
- lib/phil_columns/activerecord/migrator.rb
|
73
|
+
- lib/phil_columns/activerecord/schema_seed.rb
|
74
|
+
- lib/phil_columns/activerecord/silence_streams.rb
|
75
|
+
- lib/phil_columns/activerecord/version.rb
|
76
|
+
- phil_columns-activerecord.gemspec
|
77
|
+
homepage: ''
|
78
|
+
licenses:
|
79
|
+
- MIT
|
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.2.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Phil_columns adapter for activerecord.
|
101
|
+
test_files: []
|