inheritance_integer_type 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # InheritanceIntegerType
2
2
 
3
- Easy for to set the 'type' fields in the DB to be an int (or tinyint) instead of a string. Much better for HD space and Ram, especially if they column in indexed
3
+ This gem makes it easy to have int (or tinyint) 'type' fields in your Rails database, instead of strings. It makes much more efficient use of disk space and RAM, especially if the column is indexed.
4
4
 
5
- The example provided by the docs shows something like this
5
+ The example provided by the Rails documentation shows something like this:
6
6
  ```ruby
7
7
  class Company < ActiveRecord::Base; end
8
8
  class Firm < Company; end
@@ -12,9 +12,9 @@ class PriorityClient < Client; end
12
12
 
13
13
  With a migration that looks something like:
14
14
  ```ruby
15
- class CreatePictures < ActiveRecord::Migration
15
+ class CreateCompanies < ActiveRecord::Migration
16
16
  def change
17
- create_table :pictures do |t|
17
+ create_table :companies do |t|
18
18
  t.string :name
19
19
  t.string :type
20
20
  end
@@ -42,17 +42,17 @@ Or install it yourself as:
42
42
 
43
43
  The gem is pretty straightforward to use.
44
44
 
45
- First, set the integer_inheritance value on each of the subclasses.
45
+ First, set the `integer_inheritance` value on each of the subclasses.
46
46
  ```ruby
47
- class Firm < ActiveRecord::Base
47
+ class Firm < Company
48
48
  self.integer_inheritance = 1
49
49
  end
50
50
 
51
- class Client < ActiveRecord::Base
51
+ class Client < Company
52
52
  self.integer_inheritance = 2
53
53
  end
54
54
 
55
- class PriorityClient < ActiveRecord::Base
55
+ class PriorityClient < Client
56
56
  self.integer_inheritance = 3
57
57
  end
58
58
  ```
@@ -62,7 +62,7 @@ Note: The mapping here can start from whatever integer you wish, but I would adv
62
62
 
63
63
  If you want to convert a polymorphic association that is already a string, you'll need to set up a migration. (Assuming SQL for the time being, but this should be pretty straightforward.)
64
64
  ```ruby
65
- class PictureToPolymorphicIntegerType < ActiveRecord::Migration
65
+ class CompanyToIntegerType < ActiveRecord::Migration
66
66
 
67
67
  def up
68
68
  change_table :companies do |t|
@@ -23,6 +23,14 @@ module InheritanceIntegerType
23
23
  included do
24
24
  class_eval {
25
25
  cattr_accessor :_inheritance_mapping
26
+
27
+ def self.merge_mapping!(mapping)
28
+ conflicts = _inheritance_mapping.keys & mapping.keys
29
+ raise ArgumentError.new("Duplicate mapping detected for keys: #{conflicts}") if conflicts.any?
30
+
31
+ _inheritance_mapping.merge!(mapping)
32
+ end
33
+
26
34
  self._inheritance_mapping = {}
27
35
  class << self
28
36
  alias_method_chain :sti_name, :integer_types
@@ -1,3 +1,3 @@
1
1
  module InheritanceIntegerType
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inheritance_integer_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Kyle d'Oliveira
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
12
+ date: 2015-03-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: activerecord
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - '='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - '='
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: mysql
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - '='
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - '='
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: debugger
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ! '>='
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ! '>='
95
108
  - !ruby/object:Gem::Version
@@ -129,26 +142,27 @@ files:
129
142
  homepage: ''
130
143
  licenses:
131
144
  - MIT
132
- metadata: {}
133
145
  post_install_message:
134
146
  rdoc_options: []
135
147
  require_paths:
136
148
  - lib
137
149
  required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
138
151
  requirements:
139
152
  - - ! '>='
140
153
  - !ruby/object:Gem::Version
141
154
  version: '0'
142
155
  required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
143
157
  requirements:
144
158
  - - ! '>='
145
159
  - !ruby/object:Gem::Version
146
160
  version: '0'
147
161
  requirements: []
148
162
  rubyforge_project:
149
- rubygems_version: 2.2.2
163
+ rubygems_version: 1.8.23
150
164
  signing_key:
151
- specification_version: 4
165
+ specification_version: 3
152
166
  summary: Allow the type field in teh DB to be an integer rather than a string
153
167
  test_files:
154
168
  - spec/inheritance_integer_type_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDJkZTE1NmZlZjFkMDgwMDIxM2VmZjA4MWZlZWZlYTA1MTA4NzU0NQ==
5
- data.tar.gz: !binary |-
6
- MzI5Y2M0Nzc3MTUzMWRiYjE3MDA4ZTVkNWY4Zjk1Y2FhM2RlYzI4ZQ==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- NWE1YjE5ODZlOWUxNzY1NzllNTc2NTdlMWFlZDAzMDE0ZGI0ZWQxODhjYWRl
10
- ZmZhOTkwN2UwMTdmYmU1Nzc2MjhmYTc1NmRjMjdhODAzNjVhNjVhZGU5ZTdm
11
- OTk0MTA4ODZjNDU2MmQzZDE4ZTA3NDA3NjQ0NDViMzhhZTY0ZTQ=
12
- data.tar.gz: !binary |-
13
- OGY3NDBjZDRjZWI5NzQ5NmQ1NDEzMjFjNDZlNDdmYjZlY2FiMTY0Zjc1YTMz
14
- NjE3MmUwY2Q5OTg2NjBkNjJiNzIxNDUzZTRmOGRkY2Q0NGJlMzA1NGNkODU4
15
- NWQ3MDAwNGE3OTIwZmEzMzMwMjdiMmE1MzU3ZDUzZWNhNDAyMDE=