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.
- checksums.yaml +6 -14
- data/Gemfile +0 -4
- data/lib/protobuf-activerecord.rb +26 -3
- data/lib/protobuf/active_record/attribute_methods.rb +35 -0
- data/lib/protobuf/active_record/columns.rb +74 -0
- data/lib/protobuf/active_record/config.rb +11 -0
- data/lib/protobuf/active_record/errors.rb +23 -0
- data/lib/protobuf/active_record/mass_assignment_security.rb +16 -0
- data/lib/protobuf/active_record/mass_assignment_security/persistence.rb +57 -0
- data/lib/protobuf/active_record/mass_assignment_security/transformation.rb +27 -0
- data/lib/protobuf/active_record/model.rb +32 -0
- data/lib/protobuf/active_record/persistence.rb +55 -0
- data/lib/protobuf/active_record/railtie.rb +11 -0
- data/lib/protobuf/active_record/scope.rb +121 -0
- data/lib/protobuf/active_record/serialization.rb +194 -0
- data/lib/protobuf/active_record/transformation.rb +155 -0
- data/lib/protobuf/active_record/validations.rb +43 -0
- data/lib/protobuf/{activerecord → active_record}/version.rb +1 -1
- data/protobuf-activerecord.gemspec +4 -5
- data/spec/{protoable → protobuf/active_record}/columns_spec.rb +2 -2
- data/spec/{protoable → protobuf/active_record}/persistence_spec.rb +1 -1
- data/spec/{protoable → protobuf/active_record}/scope_spec.rb +1 -8
- data/spec/{protoable → protobuf/active_record}/serialization_spec.rb +2 -2
- data/spec/{protoable → protobuf/active_record}/transformation_spec.rb +12 -12
- data/spec/support/models/user.rb +1 -1
- metadata +59 -68
- data/lib/protobuf/activerecord/protoable.rb +0 -19
- data/lib/protobuf/activerecord/protoable/columns.rb +0 -56
- data/lib/protobuf/activerecord/protoable/errors.rb +0 -22
- data/lib/protobuf/activerecord/protoable/persistence.rb +0 -56
- data/lib/protobuf/activerecord/protoable/scope.rb +0 -121
- data/lib/protobuf/activerecord/protoable/serialization.rb +0 -190
- data/lib/protobuf/activerecord/protoable/transformation.rb +0 -158
- data/lib/protobuf/activerecord/protoable/validations.rb +0 -39
- data/lib/protobuf/activerecord/protobuf_ext/message.rb +0 -16
@@ -1,39 +0,0 @@
|
|
1
|
-
module Protoable
|
2
|
-
module Validations
|
3
|
-
extend ::ActiveSupport::Concern
|
4
|
-
|
5
|
-
module ClassMethods
|
6
|
-
# Validates whether the value of the specified attribute is available in
|
7
|
-
# the given Protobuf Enum. The enumeration should be passed as a class
|
8
|
-
# that defines the enumeration:
|
9
|
-
#
|
10
|
-
# ```
|
11
|
-
# class User < ActiveRecord::Base
|
12
|
-
# include ::Protoable
|
13
|
-
#
|
14
|
-
# validates_enumeration_of :role_type, :with => RoleType, :allow_nil => true
|
15
|
-
# end
|
16
|
-
# ```
|
17
|
-
#
|
18
|
-
# In this example, RoleType is a defined as a protobuf enum.
|
19
|
-
#
|
20
|
-
# It accepts the same options as `validates_inclusion_of` (the :in option
|
21
|
-
# is automatically set and will be overwritten).
|
22
|
-
#
|
23
|
-
def validates_enumeration_of(*args)
|
24
|
-
options = args.extract_options!
|
25
|
-
enumerable = options.delete(:with)
|
26
|
-
|
27
|
-
raise ArgumentError, ":with must be specified" if enumerable.nil?
|
28
|
-
|
29
|
-
if enumerable < ::Protobuf::Enum
|
30
|
-
options[:in] = enumerable.values.values.map(&:value)
|
31
|
-
end
|
32
|
-
|
33
|
-
args << options
|
34
|
-
|
35
|
-
validates_inclusion_of(*args)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'protobuf'
|
2
|
-
|
3
|
-
class Protobuf::Message
|
4
|
-
unless method_defined?(:respond_to_and_has?)
|
5
|
-
def respond_to_and_has?(key)
|
6
|
-
self.respond_to?(key) && self.has_field?(key)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
unless method_defined?(:respond_to_and_has_and_present?)
|
11
|
-
def respond_to_and_has_and_present?(key)
|
12
|
-
self.respond_to_and_has?(key) &&
|
13
|
-
(self.__send__(key).present? || [true, false].include?(self.__send__(key)))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|