protobuf-activerecord 2.1.0 → 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +6 -14
  2. data/Gemfile +0 -4
  3. data/lib/protobuf-activerecord.rb +26 -3
  4. data/lib/protobuf/active_record/attribute_methods.rb +35 -0
  5. data/lib/protobuf/active_record/columns.rb +74 -0
  6. data/lib/protobuf/active_record/config.rb +11 -0
  7. data/lib/protobuf/active_record/errors.rb +23 -0
  8. data/lib/protobuf/active_record/mass_assignment_security.rb +16 -0
  9. data/lib/protobuf/active_record/mass_assignment_security/persistence.rb +57 -0
  10. data/lib/protobuf/active_record/mass_assignment_security/transformation.rb +27 -0
  11. data/lib/protobuf/active_record/model.rb +32 -0
  12. data/lib/protobuf/active_record/persistence.rb +55 -0
  13. data/lib/protobuf/active_record/railtie.rb +11 -0
  14. data/lib/protobuf/active_record/scope.rb +121 -0
  15. data/lib/protobuf/active_record/serialization.rb +194 -0
  16. data/lib/protobuf/active_record/transformation.rb +155 -0
  17. data/lib/protobuf/active_record/validations.rb +43 -0
  18. data/lib/protobuf/{activerecord → active_record}/version.rb +1 -1
  19. data/protobuf-activerecord.gemspec +4 -5
  20. data/spec/{protoable → protobuf/active_record}/columns_spec.rb +2 -2
  21. data/spec/{protoable → protobuf/active_record}/persistence_spec.rb +1 -1
  22. data/spec/{protoable → protobuf/active_record}/scope_spec.rb +1 -8
  23. data/spec/{protoable → protobuf/active_record}/serialization_spec.rb +2 -2
  24. data/spec/{protoable → protobuf/active_record}/transformation_spec.rb +12 -12
  25. data/spec/support/models/user.rb +1 -1
  26. metadata +59 -68
  27. data/lib/protobuf/activerecord/protoable.rb +0 -19
  28. data/lib/protobuf/activerecord/protoable/columns.rb +0 -56
  29. data/lib/protobuf/activerecord/protoable/errors.rb +0 -22
  30. data/lib/protobuf/activerecord/protoable/persistence.rb +0 -56
  31. data/lib/protobuf/activerecord/protoable/scope.rb +0 -121
  32. data/lib/protobuf/activerecord/protoable/serialization.rb +0 -190
  33. data/lib/protobuf/activerecord/protoable/transformation.rb +0 -158
  34. data/lib/protobuf/activerecord/protoable/validations.rb +0 -39
  35. data/lib/protobuf/activerecord/protobuf_ext/message.rb +0 -16
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Protoable::Scope do
3
+ describe Protobuf::ActiveRecord::Scope do
4
4
  before do
5
5
  @field_parsers = User.instance_variable_get("@_searchable_field_parsers")
6
6
  @fields = User.instance_variable_get("@_searchable_fields")
@@ -48,13 +48,6 @@ describe Protoable::Scope do
48
48
  end
49
49
 
50
50
  describe ".field_scope" do
51
- context "when scope is passed in the old style" do
52
- it "defines the given field as searchable using the given scope" do
53
- User.field_scope :guid, :by_guid
54
- User.searchable_fields[:guid].should eq :by_guid
55
- end
56
- end
57
-
58
51
  context "when :scope is not defined" do
59
52
  it "defines the given field as searchable using the `by_[:field]` as the scope" do
60
53
  User.field_scope :guid
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Protoable::Serialization do
3
+ describe Protobuf::ActiveRecord::Serialization do
4
4
  let(:protobuf_message) { UserMessage }
5
5
 
6
6
  describe "._protobuf_convert_attributes_to_fields" do
@@ -71,7 +71,7 @@ describe Protoable::Serialization do
71
71
 
72
72
  context "when the given converter is not callable" do
73
73
  it "raises an exception" do
74
- expect { User.field_from_record :name, nil }.to raise_exception(Protoable::FieldTransformerError)
74
+ expect { User.field_from_record :name, nil }.to raise_exception(Protobuf::ActiveRecord::FieldTransformerError)
75
75
  end
76
76
  end
77
77
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Protoable::Transformation do
3
+ describe Protobuf::ActiveRecord::Transformation do
4
4
  let(:user) { User.new(user_attributes) }
5
5
  let(:user_attributes) { { :first_name => 'foo', :last_name => 'bar', :email => 'foo@test.co' } }
6
6
  let(:proto_hash) { { :name => 'foo bar', :email => 'foo@test.co' } }
@@ -24,7 +24,7 @@ describe Protoable::Transformation do
24
24
  end
25
25
  end
26
26
 
27
- describe "._protobuf_convert_fields_to_columns" do
27
+ describe "._protobuf_convert_fields_to_attributes" do
28
28
  context "when the given field's corresponding column type is :date" do
29
29
  let(:date) { Date.current }
30
30
  let(:value) { date.to_time.to_i }
@@ -32,7 +32,7 @@ describe Protoable::Transformation do
32
32
  before { User.stub(:_protobuf_date_column?).and_return(true) }
33
33
 
34
34
  it "converts the given value to a Date object" do
35
- User._protobuf_convert_fields_to_columns(:foo_date, value).should eq date
35
+ User._protobuf_convert_fields_to_attributes(:foo_date, value).should eq date
36
36
  end
37
37
  end
38
38
 
@@ -43,11 +43,11 @@ describe Protoable::Transformation do
43
43
  before { User.stub(:_protobuf_datetime_column?).and_return(true) }
44
44
 
45
45
  it "converts the given value to a DateTime object" do
46
- User._protobuf_convert_fields_to_columns(:foo_datetime, value).should be_a(DateTime)
46
+ User._protobuf_convert_fields_to_attributes(:foo_datetime, value).should be_a(DateTime)
47
47
  end
48
48
 
49
49
  it "converts the given value to a DateTime object of the same value" do
50
- User._protobuf_convert_fields_to_columns(:foo_datetime, value).should be_within(1).of(datetime)
50
+ User._protobuf_convert_fields_to_attributes(:foo_datetime, value).should be_within(1).of(datetime)
51
51
  end
52
52
  end
53
53
 
@@ -58,11 +58,11 @@ describe Protoable::Transformation do
58
58
  before { User.stub(:_protobuf_time_column?).and_return(true) }
59
59
 
60
60
  it "converts the given value to a Time object" do
61
- User._protobuf_convert_fields_to_columns(:foo_time, value).should be_a(Time)
61
+ User._protobuf_convert_fields_to_attributes(:foo_time, value).should be_a(Time)
62
62
  end
63
63
 
64
64
  it "converts the given value to a Time object of the same value" do
65
- User._protobuf_convert_fields_to_columns(:foo_time, value).should be_within(1).of(time)
65
+ User._protobuf_convert_fields_to_attributes(:foo_time, value).should be_within(1).of(time)
66
66
  end
67
67
  end
68
68
 
@@ -73,11 +73,11 @@ describe Protoable::Transformation do
73
73
  before { User.stub(:_protobuf_timestamp_column?).and_return(true) }
74
74
 
75
75
  it "converts the given value to a Time object" do
76
- User._protobuf_convert_fields_to_columns(:foo_time, value).should be_a(Time)
76
+ User._protobuf_convert_fields_to_attributes(:foo_time, value).should be_a(Time)
77
77
  end
78
78
 
79
79
  it "converts the given value to a Time object of the same value" do
80
- User._protobuf_convert_fields_to_columns(:foo_timestamp, value).should be_within(1).of(time)
80
+ User._protobuf_convert_fields_to_attributes(:foo_timestamp, value).should be_within(1).of(time)
81
81
  end
82
82
  end
83
83
 
@@ -85,7 +85,7 @@ describe Protoable::Transformation do
85
85
  let(:value) { "Foo" }
86
86
 
87
87
  it "returns the given value" do
88
- User._protobuf_convert_fields_to_columns(:foo, value).should eq value
88
+ User._protobuf_convert_fields_to_attributes(:foo, value).should eq value
89
89
  end
90
90
  end
91
91
  end
@@ -128,7 +128,7 @@ describe Protoable::Transformation do
128
128
 
129
129
  context "when a transformer is not defined for the attribute" do
130
130
  before {
131
- User.stub(:_protobuf_convert_fields_to_columns) do |key, value|
131
+ User.stub(:_protobuf_convert_fields_to_attributes) do |key, value|
132
132
  value
133
133
  end
134
134
  }
@@ -154,7 +154,7 @@ describe Protoable::Transformation do
154
154
 
155
155
  context "when the given transformer is not callable" do
156
156
  it "raises an exception" do
157
- expect { User.attribute_from_proto :name, nil }.to raise_exception(Protoable::AttributeTransformerError)
157
+ expect { User.attribute_from_proto :name, nil }.to raise_exception(Protobuf::ActiveRecord::AttributeTransformerError)
158
158
  end
159
159
  end
160
160
 
@@ -1,5 +1,5 @@
1
1
  class User < ActiveRecord::Base
2
- include Protoable
2
+ include Protobuf::ActiveRecord::Model
3
3
 
4
4
  scope :by_guid, lambda { |*guids| where(:guid => guids) }
5
5
  scope :by_email, lambda { |*emails| where(:email => emails) }
metadata CHANGED
@@ -1,181 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hutchison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-27 00:00:00.000000000 Z
11
+ date: 2013-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '3.1'
33
+ version: 3.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '3.1'
40
+ version: 3.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: heredity
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: protobuf
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.1.3
61
+ version: 2.2.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.1.3
68
+ version: 2.2.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: geminabox
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ! '>='
80
+ - - '>='
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rspec
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ! '>='
87
+ - - '>='
102
88
  - !ruby/object:Gem::Version
103
89
  version: '0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ! '>='
94
+ - - '>='
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: rspec-pride
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
- - - ! '>='
108
+ - - '>='
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: pry-nav
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
- - - ! '>='
115
+ - - '>='
130
116
  - !ruby/object:Gem::Version
131
117
  version: '0'
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
- - - ! '>='
122
+ - - '>='
137
123
  - !ruby/object:Gem::Version
138
124
  version: '0'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: simplecov
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
- - - ! '>='
129
+ - - '>='
144
130
  - !ruby/object:Gem::Version
145
131
  version: '0'
146
132
  type: :development
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
- - - ! '>='
136
+ - - '>='
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: sqlite3
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - ! '>='
143
+ - - '>='
158
144
  - !ruby/object:Gem::Version
159
145
  version: '0'
160
146
  type: :development
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
- - - ! '>='
150
+ - - '>='
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: timecop
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
- - - ! '>='
157
+ - - '>='
172
158
  - !ruby/object:Gem::Version
173
159
  version: '0'
174
160
  type: :development
175
161
  prerelease: false
176
162
  version_requirements: !ruby/object:Gem::Requirement
177
163
  requirements:
178
- - - ! '>='
164
+ - - '>='
179
165
  - !ruby/object:Gem::Version
180
166
  version: '0'
181
167
  description: Provides the ability to create Active Record objects from Protocol Buffer
@@ -193,22 +179,27 @@ files:
193
179
  - README.md
194
180
  - Rakefile
195
181
  - lib/protobuf-activerecord.rb
196
- - lib/protobuf/activerecord/protoable.rb
197
- - lib/protobuf/activerecord/protoable/columns.rb
198
- - lib/protobuf/activerecord/protoable/errors.rb
199
- - lib/protobuf/activerecord/protoable/persistence.rb
200
- - lib/protobuf/activerecord/protoable/scope.rb
201
- - lib/protobuf/activerecord/protoable/serialization.rb
202
- - lib/protobuf/activerecord/protoable/transformation.rb
203
- - lib/protobuf/activerecord/protoable/validations.rb
204
- - lib/protobuf/activerecord/protobuf_ext/message.rb
205
- - lib/protobuf/activerecord/version.rb
182
+ - lib/protobuf/active_record/attribute_methods.rb
183
+ - lib/protobuf/active_record/columns.rb
184
+ - lib/protobuf/active_record/config.rb
185
+ - lib/protobuf/active_record/errors.rb
186
+ - lib/protobuf/active_record/mass_assignment_security.rb
187
+ - lib/protobuf/active_record/mass_assignment_security/persistence.rb
188
+ - lib/protobuf/active_record/mass_assignment_security/transformation.rb
189
+ - lib/protobuf/active_record/model.rb
190
+ - lib/protobuf/active_record/persistence.rb
191
+ - lib/protobuf/active_record/railtie.rb
192
+ - lib/protobuf/active_record/scope.rb
193
+ - lib/protobuf/active_record/serialization.rb
194
+ - lib/protobuf/active_record/transformation.rb
195
+ - lib/protobuf/active_record/validations.rb
196
+ - lib/protobuf/active_record/version.rb
206
197
  - protobuf-activerecord.gemspec
207
- - spec/protoable/columns_spec.rb
208
- - spec/protoable/persistence_spec.rb
209
- - spec/protoable/scope_spec.rb
210
- - spec/protoable/serialization_spec.rb
211
- - spec/protoable/transformation_spec.rb
198
+ - spec/protobuf/active_record/columns_spec.rb
199
+ - spec/protobuf/active_record/persistence_spec.rb
200
+ - spec/protobuf/active_record/scope_spec.rb
201
+ - spec/protobuf/active_record/serialization_spec.rb
202
+ - spec/protobuf/active_record/transformation_spec.rb
212
203
  - spec/spec_helper.rb
213
204
  - spec/support/db.rb
214
205
  - spec/support/db/setup.rb
@@ -226,26 +217,26 @@ require_paths:
226
217
  - lib
227
218
  required_ruby_version: !ruby/object:Gem::Requirement
228
219
  requirements:
229
- - - ! '>='
220
+ - - '>='
230
221
  - !ruby/object:Gem::Version
231
222
  version: '0'
232
223
  required_rubygems_version: !ruby/object:Gem::Requirement
233
224
  requirements:
234
- - - ! '>='
225
+ - - '>'
235
226
  - !ruby/object:Gem::Version
236
- version: '0'
227
+ version: 1.3.1
237
228
  requirements: []
238
229
  rubyforge_project:
239
- rubygems_version: 2.0.5
230
+ rubygems_version: 2.0.6
240
231
  signing_key:
241
232
  specification_version: 4
242
233
  summary: Google Protocol Buffers integration for Active Record
243
234
  test_files:
244
- - spec/protoable/columns_spec.rb
245
- - spec/protoable/persistence_spec.rb
246
- - spec/protoable/scope_spec.rb
247
- - spec/protoable/serialization_spec.rb
248
- - spec/protoable/transformation_spec.rb
235
+ - spec/protobuf/active_record/columns_spec.rb
236
+ - spec/protobuf/active_record/persistence_spec.rb
237
+ - spec/protobuf/active_record/scope_spec.rb
238
+ - spec/protobuf/active_record/serialization_spec.rb
239
+ - spec/protobuf/active_record/transformation_spec.rb
249
240
  - spec/spec_helper.rb
250
241
  - spec/support/db.rb
251
242
  - spec/support/db/setup.rb
@@ -1,19 +0,0 @@
1
- require 'protobuf/activerecord/protoable/columns'
2
- require 'protobuf/activerecord/protoable/errors'
3
- require 'protobuf/activerecord/protoable/persistence'
4
- require 'protobuf/activerecord/protoable/scope'
5
- require 'protobuf/activerecord/protoable/serialization'
6
- require 'protobuf/activerecord/protoable/transformation'
7
- require 'protobuf/activerecord/protoable/validations'
8
-
9
- module Protoable
10
- def self.included(klass)
11
- klass.extend Protoable::Scope
12
-
13
- klass.__send__(:include, Protoable::Columns)
14
- klass.__send__(:include, Protoable::Persistence)
15
- klass.__send__(:include, Protoable::Serialization)
16
- klass.__send__(:include, Protoable::Transformation)
17
- klass.__send__(:include, Protoable::Validations)
18
- end
19
- end
@@ -1,56 +0,0 @@
1
- require 'heredity/inheritable_class_instance_variables'
2
-
3
- module Protoable
4
- module Columns
5
- def self.included(klass)
6
- klass.extend Protoable::Columns::ClassMethods
7
- klass.__send__(:include, ::Heredity::InheritableClassInstanceVariables)
8
-
9
- klass.class_eval do
10
- class << self
11
- attr_accessor :_protobuf_columns, :_protobuf_column_types
12
- end
13
-
14
- @_protobuf_columns = {}
15
- @_protobuf_column_types = Hash.new { |h,k| h[k] = [] }
16
-
17
- # NOTE: Make sure each inherited object has the database layout
18
- inheritable_attributes :_protobuf_columns, :_protobuf_column_types
19
- end
20
-
21
- _protobuf_map_columns(klass)
22
- end
23
-
24
- # Map out the columns for future reference on type conversion
25
- #
26
- def self._protobuf_map_columns(klass)
27
- return unless klass.table_exists?
28
- klass.columns.map do |column|
29
- klass._protobuf_columns[column.name.to_sym] = column
30
- klass._protobuf_column_types[column.type.to_sym] << column.name.to_sym
31
- end
32
- end
33
-
34
- module ClassMethods
35
- # :nodoc:
36
- def _protobuf_date_column?(key)
37
- _protobuf_column_types.fetch(:date, false) && _protobuf_column_types[:date].include?(key)
38
- end
39
-
40
- # :nodoc:
41
- def _protobuf_datetime_column?(key)
42
- _protobuf_column_types.fetch(:datetime, false) && _protobuf_column_types[:datetime].include?(key)
43
- end
44
-
45
- # :nodoc:
46
- def _protobuf_time_column?(key)
47
- _protobuf_column_types.fetch(:time, false) && _protobuf_column_types[:time].include?(key)
48
- end
49
-
50
- # :nodoc:
51
- def _protobuf_timestamp_column?(key)
52
- _protobuf_column_types.fetch(:timestamp, false) && _protobuf_column_types[:timestamp].include?(key)
53
- end
54
- end
55
- end
56
- end