ignorable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +6 -0
- data/lib/ignorable.rb +15 -13
- metadata +15 -50
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7901bf8b68b27166b0643cee147e4c13b1831648
|
4
|
+
data.tar.gz: 8464d803ab68abe2327c412271072503133c455e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1bdc48b499ca3de7c04c2f89ec81e6a36fe1403f71f920868f2d138145551f11a3fde75cd98c288fbe25609d1b914364a216626329ae319f919c33796a3cfb5
|
7
|
+
data.tar.gz: 142e290145dcd6047cede93bdd55a420bdb282281066f2de3e559080d86e5f3463678345d2e1960a7e1212ffe35f741c10a6413867eef37445e6f22844033409
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[Donate to charity: water via Gittip](https://www.gittip.com/nthj/)
|
2
|
+
|
1
3
|
ignorable
|
2
4
|
=========
|
3
5
|
|
@@ -17,3 +19,7 @@ Usage
|
|
17
19
|
ignore_columns :attributes, :class, :meta_column_used_by_another_app
|
18
20
|
end
|
19
21
|
|
22
|
+
Rails Versions
|
23
|
+
==============
|
24
|
+
|
25
|
+
Tested on Rails 3.2, Rails 4.1.0.
|
data/lib/ignorable.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'active_record'
|
2
|
+
require 'active_support/core_ext/class/attribute'
|
2
3
|
|
3
4
|
module Ignorable
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module InstanceMethods
|
6
|
+
def attribute_names # :nodoc:
|
7
|
+
super.reject{|col| self.class.ignored_column?(col)}
|
8
|
+
end
|
8
9
|
end
|
9
10
|
|
10
11
|
module ClassMethods
|
@@ -12,8 +13,6 @@ module Ignorable
|
|
12
13
|
@columns ||= super.reject{|col| ignored_column?(col)}
|
13
14
|
end
|
14
15
|
|
15
|
-
attr_reader :ignored_columns
|
16
|
-
|
17
16
|
# Prevent Rails from loading a table column.
|
18
17
|
# Useful for legacy database schemas with problematic column names,
|
19
18
|
# like 'class' or 'attributes'.
|
@@ -24,10 +23,11 @@ module Ignorable
|
|
24
23
|
#
|
25
24
|
# Topic.new.respond_to?(:attributes) => false
|
26
25
|
def ignore_columns(*columns)
|
27
|
-
|
28
|
-
|
26
|
+
self.ignored_columns ||= []
|
27
|
+
self.ignored_columns += columns.map(&:to_s)
|
29
28
|
reset_column_information
|
30
|
-
|
29
|
+
descendants.each(&:reset_column_information)
|
30
|
+
self.ignored_columns.tap(&:uniq!)
|
31
31
|
end
|
32
32
|
alias ignore_column ignore_columns
|
33
33
|
|
@@ -35,18 +35,20 @@ module Ignorable
|
|
35
35
|
# Accepts both ActiveRecord::ConnectionAdapter::Column objects,
|
36
36
|
# and actual column names ('title')
|
37
37
|
def ignored_column?(column)
|
38
|
-
ignored_columns.present? && ignored_columns.include?(
|
38
|
+
self.ignored_columns.present? && self.ignored_columns.include?(
|
39
39
|
column.respond_to?(:name) ? column.name : column.to_s
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
43
43
|
def reset_ignored_columns
|
44
|
-
|
44
|
+
self.ignored_columns = []
|
45
45
|
reset_column_information
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
ActiveRecord::Base.send :include, Ignorable
|
50
|
+
unless ActiveRecord::Base.include?(Ignorable::InstanceMethods)
|
51
|
+
ActiveRecord::Base.send :include, Ignorable::InstanceMethods
|
52
|
+
ActiveRecord::Base.send :extend, Ignorable::ClassMethods
|
53
|
+
ActiveRecord::Base.send :class_attribute, :ignored_columns
|
52
54
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ignorable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nathaniel Jones
|
@@ -10,89 +9,55 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: activerecord
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '3'
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '3'
|
31
|
-
- !ruby/object:Gem::Dependency
|
32
|
-
name: sqlite3
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
|
-
requirements:
|
36
|
-
- - ! '>='
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: '0'
|
39
|
-
type: :development
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ! '>='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rspec
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ! '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.0.0
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ! '>='
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 2.0.0
|
63
28
|
description: Ignore problematic column names (like 'attributes' or 'class') in ActiveRecord
|
64
29
|
models for legacy database schemas
|
65
30
|
email:
|
66
|
-
-
|
31
|
+
- nj@third.io
|
67
32
|
- ''
|
68
33
|
executables: []
|
69
34
|
extensions: []
|
70
35
|
extra_rdoc_files: []
|
71
36
|
files:
|
72
|
-
- lib/ignorable.rb
|
73
37
|
- README.md
|
38
|
+
- lib/ignorable.rb
|
74
39
|
homepage: http://github.com/nthj/ignorable
|
75
|
-
licenses:
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
76
43
|
post_install_message:
|
77
44
|
rdoc_options: []
|
78
45
|
require_paths:
|
79
46
|
- lib
|
80
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
48
|
requirements:
|
83
|
-
- -
|
49
|
+
- - ">="
|
84
50
|
- !ruby/object:Gem::Version
|
85
51
|
version: '0'
|
86
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
53
|
requirements:
|
89
|
-
- -
|
54
|
+
- - ">="
|
90
55
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
56
|
+
version: '0'
|
92
57
|
requirements: []
|
93
|
-
rubyforge_project:
|
94
|
-
rubygems_version:
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.4.5
|
95
60
|
signing_key:
|
96
|
-
specification_version:
|
61
|
+
specification_version: 4
|
97
62
|
summary: Ignore columns in ActiveRecord models
|
98
63
|
test_files: []
|