protobuf-activerecord 2.1.0 → 3.0.0.pre

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 (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,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