literal 1.7.0 → 1.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c4292f514f586e16d0d477cc57e9a8b1f38771a8124f9ed933b67aa167550a0
4
- data.tar.gz: 48dc63568c23368fb5c1577a57833720ca272c2aeca24dfc33e26271ed378497
3
+ metadata.gz: bfccfa4acf4ec640c3a47a2bab9d34aec7295a29abc387a20e81f6fb3beb085b
4
+ data.tar.gz: a5a029b15bfc36d930338fc5c2dd6b52abdab0ad1315d54725d2ad90e681bb97
5
5
  SHA512:
6
- metadata.gz: d79162f89f5088923b2a18ffb2d77214401e18f2d992d2535ab85a4f73b0adbf4430bf385dd846f860e7c0c984508bd6a4d48296a13883fefdb1eb8ef0ac51eb
7
- data.tar.gz: d0cbebd25520b382b6ea73d22b9b2120b15831d7b51d6b2deb99bfd2adaa1c53cfeadbf4b6c3f7af6e97ea634991c49fe5e49d559c2efcf228ec2e9fe942daf1
6
+ metadata.gz: 9207d8ba24e146a2d9400c640b6d4c5d6fa97694d95097cf86ac09ebedf16613daa7b1cd4b7946b447809d71aef2e3dca8cd805c59902e3744d00d5b10da37a1
7
+ data.tar.gz: f02700e76bd9a65ef3d3885f3c79984cec164ac47af50f153bb034026d71576926245bc7a481f728c46ea6410a984d45d97d217d16ed1b34b6bf72233179033b
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Literal::Rails
4
+ module ActiveRecordRelationPatch
5
+ def Relation(model)
6
+ RelationType.new(model)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Literal::Rails
4
+ class RelationType
5
+ def initialize(model_class)
6
+ unless Class === model_class && model_class < ActiveRecord::Base
7
+ raise Literal::TypeError.new(
8
+ context: Literal::TypeError::Context.new(
9
+ expected: ActiveRecord::Base, actual: model_class
10
+ )
11
+ )
12
+ end
13
+
14
+ @model_class = model_class
15
+ end
16
+
17
+ def inspect = "ActiveRecord::Relation(#{@model_class.name})"
18
+
19
+ def ===(value)
20
+ case value
21
+ when ActiveRecord::Relation, ActiveRecord::Associations::CollectionProxy, ActiveRecord::AssociationRelation
22
+ @model_class == value.model || value.model < @model_class
23
+ else
24
+ false
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,15 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module Literal::Rails
4
+ if defined?(::ActiveJob)
5
+ require_relative "rails/enum_serializer"
6
+ end
7
+
8
+ if defined?(::ActiveRecord::Relation)
9
+ require_relative "rails/relation_type"
10
+ require_relative "rails/active_record_relation_patch"
11
+ ::ActiveRecord.extend(ActiveRecordRelationPatch)
12
+ end
13
+ end
14
+
3
15
  class Literal::Railtie < Rails::Railtie
4
- initializer "literal.register_literal_enum_type" do
5
- [ActiveRecord::Type, ActiveModel::Type].each do |registry|
6
- registry.register(:literal_enum) do |name, type:|
16
+ if defined?(::ActiveModel::Type)
17
+ require_relative "rails/enum_type"
18
+ require_relative "rails/flags_type"
19
+
20
+ initializer "literal.register_active_model_types" do
21
+ ActiveModel::Type.register(:literal_enum) do |name, type:|
7
22
  Literal::Rails::EnumType.new(type)
8
23
  end
9
24
 
10
- registry.register(:literal_flags) do |name, type:|
25
+ ActiveModel::Type.register(:literal_flags) do |name, type:|
11
26
  Literal::Rails::FlagsType.new(type)
12
27
  end
13
28
  end
29
+
30
+ if defined?(::ActiveRecord::Type)
31
+ initializer "literal.register_active_record_types" do
32
+ ActiveRecord::Type.register(:literal_enum) do |name, type:|
33
+ Literal::Rails::EnumType.new(type)
34
+ end
35
+
36
+ ActiveRecord::Type.register(:literal_flags) do |name, type:|
37
+ Literal::Rails::FlagsType.new(type)
38
+ end
39
+ end
40
+ end
14
41
  end
15
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Literal
4
- VERSION = "1.7.0"
4
+ VERSION = "1.7.1"
5
5
  end
data/lib/literal.rb CHANGED
@@ -5,6 +5,9 @@ require_relative "literal/version"
5
5
 
6
6
  module Literal
7
7
  Loader = Zeitwerk::Loader.for_gem.tap do |loader|
8
+ loader.ignore("#{__dir__}/literal/rails")
9
+ loader.ignore("#{__dir__}/literal/railtie.rb")
10
+
8
11
  loader.inflector.inflect(
9
12
  "json_data_type" => "JSONDataType"
10
13
  )
@@ -123,4 +126,4 @@ module Literal
123
126
  end
124
127
  end
125
128
 
126
- require_relative "literal/rails" if defined?(Rails)
129
+ require_relative "literal/railtie" if defined?(Rails)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: literal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
@@ -54,11 +54,11 @@ files:
54
54
  - lib/literal/properties/data_schema.rb
55
55
  - lib/literal/properties/schema.rb
56
56
  - lib/literal/property.rb
57
- - lib/literal/rails.rb
57
+ - lib/literal/rails/active_record_relation_patch.rb
58
58
  - lib/literal/rails/enum_serializer.rb
59
59
  - lib/literal/rails/enum_type.rb
60
60
  - lib/literal/rails/flags_type.rb
61
- - lib/literal/rails/patches/active_record.rb
61
+ - lib/literal/rails/relation_type.rb
62
62
  - lib/literal/railtie.rb
63
63
  - lib/literal/result.rb
64
64
  - lib/literal/set.rb
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecord
4
- class RelationType
5
- def initialize(model_class)
6
- unless Class === model_class && model_class < ActiveRecord::Base
7
- raise Literal::TypeError.new(
8
- context: Literal::TypeError::Context.new(
9
- expected: ActiveRecord::Base, actual: model_class
10
- )
11
- )
12
- end
13
-
14
- @model_class = model_class
15
- end
16
-
17
- def inspect = "ActiveRecord::Relation(#{@model_class.name})"
18
-
19
- def ===(value)
20
- case value
21
- when ActiveRecord::Relation, ActiveRecord::Associations::CollectionProxy, ActiveRecord::AssociationRelation
22
- @model_class == value.model || value.model < @model_class
23
- else
24
- false
25
- end
26
- end
27
- end
28
-
29
- def self.Relation(model)
30
- RelationType.new(model)
31
- end
32
- end
data/lib/literal/rails.rb DELETED
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "railtie"
4
- require_relative "rails/patches/active_record"
5
-
6
- module Literal::Rails
7
- end