ignorable 0.1.0 → 0.2.0
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.
- data/lib/ignorable.rb +42 -36
- metadata +36 -4
data/lib/ignorable.rb
CHANGED
@@ -1,46 +1,52 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
1
3
|
module Ignorable
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def attribute_names # :nodoc:
|
7
|
+
super.reject{|col| self.class.ignored_column?(col)}
|
6
8
|
end
|
7
9
|
|
8
|
-
|
10
|
+
module ClassMethods
|
11
|
+
def columns # :nodoc:
|
12
|
+
@columns ||= super.reject{|col| ignored_column?(col)}
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
# Useful for legacy database schemas with problematic column names,
|
12
|
-
# like 'class' or 'attributes'.
|
13
|
-
#
|
14
|
-
# class Topic < ActiveRecord::Base
|
15
|
-
# ignore_columns :attributes, :class
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# Topic.new.respond_to?(:attributes) => false
|
19
|
-
def ignore_columns *columns
|
20
|
-
@ignored_columns ||= []
|
21
|
-
@ignored_columns += columns.map(&:to_s)
|
22
|
-
reset_column_information
|
23
|
-
@ignored_columns.tap(&:uniq!)
|
24
|
-
end
|
25
|
-
alias ignore_column ignore_columns
|
15
|
+
attr_reader :ignored_columns
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
17
|
+
# Prevent Rails from loading a table column.
|
18
|
+
# Useful for legacy database schemas with problematic column names,
|
19
|
+
# like 'class' or 'attributes'.
|
20
|
+
#
|
21
|
+
# class Topic < ActiveRecord::Base
|
22
|
+
# ignore_columns :attributes, :class
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Topic.new.respond_to?(:attributes) => false
|
26
|
+
def ignore_columns(*columns)
|
27
|
+
@ignored_columns ||= []
|
28
|
+
@ignored_columns += columns.map(&:to_s)
|
29
|
+
reset_column_information
|
30
|
+
@ignored_columns.tap(&:uniq!)
|
31
|
+
end
|
32
|
+
alias ignore_column ignore_columns
|
33
|
+
|
34
|
+
# Has a column been ignored?
|
35
|
+
# Accepts both ActiveRecord::ConnectionAdapter::Column objects,
|
36
|
+
# and actual column names ('title')
|
37
|
+
def ignored_column?(column)
|
38
|
+
ignored_columns.present? && ignored_columns.include?(
|
39
|
+
column.respond_to?(:name) ? column.name : column.to_s
|
40
|
+
)
|
41
|
+
end
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
def reset_ignored_columns
|
44
|
+
@ignored_columns = []
|
45
|
+
reset_column_information
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
|
-
|
43
|
-
|
44
|
-
if defined?(ActiveRecord::Base)
|
45
|
-
ActiveRecord::Base.send :extend, Ignorable
|
50
|
+
if defined?(ActiveRecord::Base) && !ActiveRecord::Base.include?(Ignorable)
|
51
|
+
ActiveRecord::Base.send :include, Ignorable
|
46
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ignorable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,10 +10,10 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: activerecord
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
@@ -28,6 +28,38 @@ dependencies:
|
|
28
28
|
- - ! '>='
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
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
|
31
63
|
description: Ignore problematic column names (like 'attributes' or 'class') in ActiveRecord
|
32
64
|
models for legacy database schemas
|
33
65
|
email:
|
@@ -59,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
91
|
version: 1.3.6
|
60
92
|
requirements: []
|
61
93
|
rubyforge_project: ignorable
|
62
|
-
rubygems_version: 1.8.
|
94
|
+
rubygems_version: 1.8.25
|
63
95
|
signing_key:
|
64
96
|
specification_version: 3
|
65
97
|
summary: Ignore columns in ActiveRecord models
|