ignorable 0.1.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.
Files changed (3) hide show
  1. data/README.md +19 -0
  2. data/lib/ignorable.rb +46 -0
  3. metadata +66 -0
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ ignorable
2
+ =========
3
+
4
+ Ignore columns in ActiveRecord
5
+
6
+ Installation
7
+ ============
8
+
9
+ Add this to your Gemfile:
10
+
11
+ gem 'ignorable'
12
+
13
+ Usage
14
+ =====
15
+
16
+ class Topic < ActiveRecord::Base
17
+ ignore_columns :attributes, :class, :meta_column_used_by_another_app
18
+ end
19
+
data/lib/ignorable.rb ADDED
@@ -0,0 +1,46 @@
1
+ module Ignorable
2
+ def columns
3
+ @columns ||= super.reject do |col|
4
+ self.ignored_column?(col)
5
+ end
6
+ end
7
+
8
+ attr_reader :ignored_columns
9
+
10
+ # Prevent Rails from loading a table column.
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
26
+
27
+ # Has a column been ignored?
28
+ # Accepts both ActiveRecord::ConnectionAdapter::Column objects,
29
+ # and actual column names ('title')
30
+ def ignored_column? column
31
+ ignored_columns.present? && ignored_columns.include?(
32
+ column.respond_to?(:name) ? column.name : column.to_s
33
+ )
34
+ end
35
+
36
+ def reset_ignored_columns
37
+ @ignored_columns = []
38
+ reset_column_information
39
+ end
40
+ end
41
+
42
+ require 'rails'
43
+
44
+ if defined?(ActiveRecord::Base)
45
+ ActiveRecord::Base.send :extend, Ignorable
46
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ignorable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathaniel Jones
9
+ - Mando Escamilla
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-08-22 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '3'
31
+ description: Ignore problematic column names (like 'attributes' or 'class') in ActiveRecord
32
+ models for legacy database schemas
33
+ email:
34
+ - hello@nthj.me
35
+ - ''
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - lib/ignorable.rb
41
+ - README.md
42
+ homepage: http://github.com/nthj/ignorable
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: 1.3.6
60
+ requirements: []
61
+ rubyforge_project: ignorable
62
+ rubygems_version: 1.8.24
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ignore columns in ActiveRecord models
66
+ test_files: []