activerecord-ejection_seat 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/Gemfile +11 -3
  4. data/Gemfile.lock +99 -35
  5. data/README.md +4 -0
  6. data/Rakefile +14 -2
  7. data/lib/activerecord-ejection_seat/ejectable.rb +2 -1
  8. data/lib/activerecord-ejection_seat/props_builder.rb +44 -0
  9. data/lib/activerecord-ejection_seat/version.rb +2 -1
  10. data/lib/activerecord-ejection_seat.rb +3 -1
  11. data/sorbet/config +3 -0
  12. data/sorbet/rbi/annotations/activerecord.rbi +18 -0
  13. data/sorbet/rbi/annotations/activesupport.rbi +52 -0
  14. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  15. data/sorbet/rbi/gems/activemodel@7.0.4.rbi +8 -0
  16. data/sorbet/rbi/gems/activerecord@7.0.4.rbi +11 -0
  17. data/sorbet/rbi/gems/activesupport@7.0.4.rbi +93 -0
  18. data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
  19. data/sorbet/rbi/gems/concurrent-ruby@1.1.10.rbi +8 -0
  20. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1064 -0
  21. data/sorbet/rbi/gems/i18n@1.12.0.rbi +8 -0
  22. data/sorbet/rbi/gems/io-console@0.6.0.rbi +8 -0
  23. data/sorbet/rbi/gems/irb@1.6.2.rbi +342 -0
  24. data/sorbet/rbi/gems/json@2.6.3.rbi +1541 -0
  25. data/sorbet/rbi/gems/language_server-protocol@3.17.0.2.rbi +8 -0
  26. data/sorbet/rbi/gems/minitest@5.16.3.rbi +8 -0
  27. data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
  28. data/sorbet/rbi/gems/parallel@1.22.1.rbi +277 -0
  29. data/sorbet/rbi/gems/parser@3.1.3.0.rbi +6878 -0
  30. data/sorbet/rbi/gems/prettier_print@1.1.0.rbi +8 -0
  31. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +397 -0
  32. data/sorbet/rbi/gems/rake@13.0.6.rbi +2946 -0
  33. data/sorbet/rbi/gems/rbi@0.0.16.rbi +3008 -0
  34. data/sorbet/rbi/gems/regexp_parser@2.6.1.rbi +3126 -0
  35. data/sorbet/rbi/gems/reline@0.3.2.rbi +8 -0
  36. data/sorbet/rbi/gems/rexml@3.2.5.rbi +4660 -0
  37. data/sorbet/rbi/gems/rspec-core@3.12.0.rbi +10588 -0
  38. data/sorbet/rbi/gems/rspec-expectations@3.12.1.rbi +7817 -0
  39. data/sorbet/rbi/gems/rspec-mocks@3.12.1.rbi +4994 -0
  40. data/sorbet/rbi/gems/rspec-support@3.12.0.rbi +1477 -0
  41. data/sorbet/rbi/gems/rspec@3.12.0.rbi +10 -0
  42. data/sorbet/rbi/gems/rubocop-ast@1.24.0.rbi +6790 -0
  43. data/sorbet/rbi/gems/rubocop-rake@0.6.0.rbi +354 -0
  44. data/sorbet/rbi/gems/rubocop-rspec@2.16.0.rbi +7650 -0
  45. data/sorbet/rbi/gems/rubocop-sorbet@0.6.11.rbi +1014 -0
  46. data/sorbet/rbi/gems/rubocop@1.41.0.rbi +52148 -0
  47. data/sorbet/rbi/gems/ruby-lsp@0.3.7.rbi +13 -0
  48. data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +1212 -0
  49. data/sorbet/rbi/gems/sorbet-struct-comparable@1.3.0.rbi +16 -0
  50. data/sorbet/rbi/gems/spoom@1.1.15.rbi +2383 -0
  51. data/sorbet/rbi/gems/sqlite3@1.5.4.rbi +1600 -0
  52. data/sorbet/rbi/gems/syntax_tree@4.3.0.rbi +8 -0
  53. data/sorbet/rbi/gems/tapioca@0.10.4.rbi +3032 -0
  54. data/sorbet/rbi/gems/thor@1.2.1.rbi +3950 -0
  55. data/sorbet/rbi/gems/tzinfo@2.0.5.rbi +8 -0
  56. data/sorbet/rbi/gems/unicode-display_width@2.3.0.rbi +46 -0
  57. data/sorbet/rbi/gems/unparser@0.6.5.rbi +4265 -0
  58. data/sorbet/rbi/gems/webrick@1.7.0.rbi +2498 -0
  59. data/sorbet/rbi/gems/yard-sorbet@0.7.0.rbi +391 -0
  60. data/sorbet/rbi/gems/yard@0.9.28.rbi +17033 -0
  61. data/sorbet/rbi/todo.rbi +9 -0
  62. data/sorbet/tapioca/config.yml +2 -0
  63. data/sorbet/tapioca/require.rb +4 -0
  64. metadata +71 -4
  65. data/activerecord-ejection_seat.gemspec +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69a394852fa247c21ef30d77eb67ea89b0efed860b14ddabc2e08e82d4a2673f
4
- data.tar.gz: 40a97e34b9db820ff71daafd3161d6ee35249fde15d366dd4fc7957cf41fe2c6
3
+ metadata.gz: ec011864f722a24abd09c60e4dbfd8c53e1a41a2922ef6827a527f3992d5b941
4
+ data.tar.gz: ea35286dccfb37c99279b6ffe6403fd20ee72c8a488103bdaa4386e7f6c8b205
5
5
  SHA512:
6
- metadata.gz: 03e11c26d5afa8e43ff424d03a5eb5a47772fc13fa938068cf390c06c7b65869ffb1c3c84273a2f3d90ce1af06edd79ab8e5b48891a0016fe0b3527de11efc90
7
- data.tar.gz: da16079ff6cdcec598cf0205eb0ad448b08704658f403be35975573045b1855414540a83a3876da793790bac1c83b16ef3362a1f99bfca3a8596b13dced2f93a
6
+ metadata.gz: a2dfb9277f769f3e9296a5388459e02acfa98ae0697009e3e8587dbaed774d45ec059652a7ffdf61c5a2a36c62b309e32fa10b834f20a8e84d145fc3c6f78dda
7
+ data.tar.gz: b39ccda5b3aa68a6d63f9be7959f70daf7a8e262f67d0b4afbf9bd250c1f1cb42f25d28592b5223ccd46857548a2ce7936d061bc9f0b62030bbe870b03e7d5c3
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  require:
2
2
  - rubocop-rake
3
3
  - rubocop-rspec
4
+ - rubocop-sorbet
4
5
 
5
6
  AllCops:
6
7
  NewCops: enable
data/Gemfile CHANGED
@@ -6,15 +6,23 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  group :development do
9
- gem "rake", "~> 13.0"
10
- gem "rubocop", "~> 1.21"
9
+ gem "rake"
10
+ gem "rubocop"
11
11
  gem "rubocop-rake"
12
12
  gem "rubocop-rspec"
13
+ gem "rubocop-sorbet"
14
+ gem "sorbet"
15
+ gem "spoom", require: false
16
+ gem "tapioca", require: false
17
+
18
+ gem "ruby-lsp"
13
19
  end
14
20
 
15
21
  group :development, :test do
16
- gem "rspec", "~> 3.0"
22
+ gem "rspec"
17
23
  gem "sorbet-runtime"
18
24
  gem "sorbet-struct-comparable"
19
25
  gem "sqlite3"
26
+
27
+ gem "debug"
20
28
  end
data/Gemfile.lock CHANGED
@@ -3,86 +3,150 @@ PATH
3
3
  specs:
4
4
  activerecord-ejection_seat (0.1.0)
5
5
  activerecord (>= 5.2)
6
+ sorbet-runtime
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- activemodel (7.0.3.1)
11
- activesupport (= 7.0.3.1)
12
- activerecord (7.0.3.1)
13
- activemodel (= 7.0.3.1)
14
- activesupport (= 7.0.3.1)
15
- activesupport (7.0.3.1)
11
+ activemodel (7.0.4)
12
+ activesupport (= 7.0.4)
13
+ activerecord (7.0.4)
14
+ activemodel (= 7.0.4)
15
+ activesupport (= 7.0.4)
16
+ activesupport (7.0.4)
16
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
18
  i18n (>= 1.6, < 2)
18
19
  minitest (>= 5.1)
19
20
  tzinfo (~> 2.0)
20
21
  ast (2.4.2)
21
22
  concurrent-ruby (1.1.10)
23
+ debug (1.7.0)
24
+ irb (>= 1.5.0)
25
+ reline (>= 0.3.1)
22
26
  diff-lcs (1.5.0)
23
27
  i18n (1.12.0)
24
28
  concurrent-ruby (~> 1.0)
25
- json (2.6.2)
26
- minitest (5.16.2)
29
+ io-console (0.6.0)
30
+ irb (1.6.2)
31
+ reline (>= 0.3.0)
32
+ json (2.6.3)
33
+ language_server-protocol (3.17.0.2)
34
+ minitest (5.16.3)
35
+ netrc (0.11.0)
27
36
  parallel (1.22.1)
28
- parser (3.1.2.0)
37
+ parser (3.1.3.0)
29
38
  ast (~> 2.4.1)
39
+ prettier_print (1.1.0)
30
40
  rainbow (3.1.1)
31
41
  rake (13.0.6)
32
- regexp_parser (2.5.0)
42
+ rbi (0.0.16)
43
+ ast
44
+ parser (>= 2.6.4.0)
45
+ sorbet-runtime (>= 0.5.9204)
46
+ unparser
47
+ regexp_parser (2.6.1)
48
+ reline (0.3.2)
49
+ io-console (~> 0.5)
33
50
  rexml (3.2.5)
34
- rspec (3.11.0)
35
- rspec-core (~> 3.11.0)
36
- rspec-expectations (~> 3.11.0)
37
- rspec-mocks (~> 3.11.0)
38
- rspec-core (3.11.0)
39
- rspec-support (~> 3.11.0)
40
- rspec-expectations (3.11.0)
51
+ rspec (3.12.0)
52
+ rspec-core (~> 3.12.0)
53
+ rspec-expectations (~> 3.12.0)
54
+ rspec-mocks (~> 3.12.0)
55
+ rspec-core (3.12.0)
56
+ rspec-support (~> 3.12.0)
57
+ rspec-expectations (3.12.1)
41
58
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.11.0)
43
- rspec-mocks (3.11.1)
59
+ rspec-support (~> 3.12.0)
60
+ rspec-mocks (3.12.1)
44
61
  diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.11.0)
46
- rspec-support (3.11.0)
47
- rubocop (1.31.2)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-support (3.12.0)
64
+ rubocop (1.41.0)
48
65
  json (~> 2.3)
49
66
  parallel (~> 1.10)
50
- parser (>= 3.1.0.0)
67
+ parser (>= 3.1.2.1)
51
68
  rainbow (>= 2.2.2, < 4.0)
52
69
  regexp_parser (>= 1.8, < 3.0)
53
70
  rexml (>= 3.2.5, < 4.0)
54
- rubocop-ast (>= 1.18.0, < 2.0)
71
+ rubocop-ast (>= 1.23.0, < 2.0)
55
72
  ruby-progressbar (~> 1.7)
56
73
  unicode-display_width (>= 1.4.0, < 3.0)
57
- rubocop-ast (1.19.1)
74
+ rubocop-ast (1.24.0)
58
75
  parser (>= 3.1.1.0)
59
76
  rubocop-rake (0.6.0)
60
77
  rubocop (~> 1.0)
61
- rubocop-rspec (2.12.1)
62
- rubocop (~> 1.31)
78
+ rubocop-rspec (2.16.0)
79
+ rubocop (~> 1.33)
80
+ rubocop-sorbet (0.6.11)
81
+ rubocop (>= 0.90.0)
82
+ ruby-lsp (0.3.7)
83
+ language_server-protocol (~> 3.17.0)
84
+ sorbet-runtime
85
+ syntax_tree (>= 4.0.2, < 5.0.0)
63
86
  ruby-progressbar (1.11.0)
64
- sorbet-runtime (0.5.10187)
87
+ sorbet (0.5.10597)
88
+ sorbet-static (= 0.5.10597)
89
+ sorbet-runtime (0.5.10597)
90
+ sorbet-static (0.5.10597-universal-darwin-21)
91
+ sorbet-static (0.5.10597-universal-darwin-22)
92
+ sorbet-static (0.5.10597-x86_64-linux)
93
+ sorbet-static-and-runtime (0.5.10597)
94
+ sorbet (= 0.5.10597)
95
+ sorbet-runtime (= 0.5.10597)
65
96
  sorbet-struct-comparable (1.3.0)
66
97
  sorbet-runtime (>= 0.5)
67
- sqlite3 (1.4.4)
68
- tzinfo (2.0.4)
98
+ spoom (1.1.15)
99
+ sorbet (>= 0.5.10187)
100
+ sorbet-runtime (>= 0.5.9204)
101
+ thor (>= 0.19.2)
102
+ sqlite3 (1.5.4-arm64-darwin)
103
+ sqlite3 (1.5.4-x86_64-linux)
104
+ syntax_tree (4.3.0)
105
+ prettier_print (>= 1.0.2)
106
+ tapioca (0.10.4)
107
+ bundler (>= 1.17.3)
108
+ netrc (>= 0.11.0)
109
+ parallel (>= 1.21.0)
110
+ rbi (~> 0.0.0, >= 0.0.16)
111
+ sorbet-static-and-runtime (>= 0.5.10187)
112
+ spoom (~> 1.1.0, >= 1.1.11)
113
+ thor (>= 1.2.0)
114
+ yard-sorbet
115
+ thor (1.2.1)
116
+ tzinfo (2.0.5)
69
117
  concurrent-ruby (~> 1.0)
70
- unicode-display_width (2.2.0)
118
+ unicode-display_width (2.3.0)
119
+ unparser (0.6.5)
120
+ diff-lcs (~> 1.3)
121
+ parser (>= 3.1.0)
122
+ webrick (1.7.0)
123
+ yard (0.9.28)
124
+ webrick (~> 1.7.0)
125
+ yard-sorbet (0.7.0)
126
+ sorbet-runtime (>= 0.5)
127
+ yard (>= 0.9)
71
128
 
72
129
  PLATFORMS
73
130
  arm64-darwin-21
131
+ arm64-darwin-22
74
132
  x86_64-linux
75
133
 
76
134
  DEPENDENCIES
77
135
  activerecord-ejection_seat!
78
- rake (~> 13.0)
79
- rspec (~> 3.0)
80
- rubocop (~> 1.21)
136
+ debug
137
+ rake
138
+ rspec
139
+ rubocop
81
140
  rubocop-rake
82
141
  rubocop-rspec
142
+ rubocop-sorbet
143
+ ruby-lsp
144
+ sorbet
83
145
  sorbet-runtime
84
146
  sorbet-struct-comparable
147
+ spoom
85
148
  sqlite3
149
+ tapioca
86
150
 
87
151
  BUNDLED WITH
88
- 2.3.16
152
+ 2.3.26
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # ActiveRecord::EjectionSeat
2
2
 
3
+ [![IMAGE ALT TEXT](https://img.youtube.com/vi/HfCY-bkVJKM/0.jpg)](http://www.youtube.com/watch?v=HfCY-bkVJKM "Introduction to activerecord-ejection_seat")
4
+
3
5
  ## ActiveRecord <=> T::Struct
4
6
 
5
7
  Sometimes, you want to convert from an `ActiveRecord` model to something more akin to a simple data class. Enter [Sorbet's `T::Struct`](https://sorbet.org/docs/tstruct). This gem helps to eject out of bulky `ActiveRecord` models (or buckle into them) and work with simple `T::Struct`'s in the rest of your app.
6
8
 
9
+ For more information about the "why" behind this gem, check out [this post](https://maxveld.ink/ejecting-out-of-an-orm/).
10
+
7
11
  ## Installation
8
12
 
9
13
  Install the gem and add to the application's Gemfile by executing:
data/Rakefile CHANGED
@@ -7,6 +7,18 @@ RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  require "rubocop/rake_task"
9
9
 
10
- RuboCop::RakeTask.new
10
+ RuboCop::RakeTask.new do |t|
11
+ t.options = ["-A"]
12
+ end
11
13
 
12
- task default: %i[rubocop spec]
14
+ desc "Run tapioca compilers"
15
+ task :tapioca do
16
+ sh "bin/tapioca gem"
17
+ end
18
+
19
+ desc "Run Sorbet typechecker"
20
+ task :sorbet do
21
+ sh "bundle exec srb tc"
22
+ end
23
+
24
+ task default: %i[rubocop sorbet spec]
@@ -1,3 +1,4 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require "active_record"
@@ -18,7 +19,7 @@ module ActiveRecord
18
19
  attrs = attributes.deep_symbolize_keys
19
20
  attribute_props = klass.props.keys & attrs.keys
20
21
 
21
- klass.new(attrs.slice(*attribute_props))
22
+ klass.new(PropsBuilder.new(attrs.slice(*attribute_props), klass.props).build)
22
23
  end
23
24
 
24
25
  alias_method :to_struct, :eject
@@ -0,0 +1,44 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "sorbet-runtime"
5
+
6
+ # Creates initialization payload for targeted T::Struct
7
+ class PropsBuilder
8
+ extend T::Sig
9
+
10
+ Attributes = T.type_alias { T::Hash[Symbol, T.untyped] }
11
+
12
+ sig do
13
+ params(
14
+ attributes_from_model: Attributes,
15
+ target_props: Attributes
16
+ ).void
17
+ end
18
+ def initialize(attributes_from_model, target_props)
19
+ @attributes_from_model = attributes_from_model
20
+ @target_props = target_props
21
+ end
22
+
23
+ sig { returns(Attributes) }
24
+ def build
25
+ built_props = {}
26
+
27
+ attributes_from_model.each do |k, v|
28
+ prop_type = target_props.dig(k, :type)
29
+
30
+ built_props[k] = if prop_type < T::Enum
31
+ prop_type.deserialize(v)
32
+ else
33
+ v
34
+ end
35
+ end
36
+
37
+ built_props
38
+ end
39
+
40
+ private
41
+
42
+ sig { returns(Attributes) }
43
+ attr_reader :attributes_from_model, :target_props
44
+ end
@@ -1,7 +1,8 @@
1
+ # typed: false
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module ActiveRecord
4
5
  module EjectionSeat
5
- VERSION = "0.1.0"
6
+ VERSION = "0.2.0"
6
7
  end
7
8
  end
@@ -1,11 +1,13 @@
1
1
  # rubocop:disable Naming/FileName
2
+ # rubocop:enable Naming/FileName
3
+ # typed: false
2
4
  # frozen_string_literal: true
3
5
 
4
6
  require_relative "activerecord-ejection_seat/version"
7
+ require_relative "activerecord-ejection_seat/props_builder"
5
8
 
6
9
  require "active_support/lazy_load_hooks"
7
10
 
8
11
  ActiveSupport.on_load(:active_record) do
9
12
  require "activerecord-ejection_seat/ejectable"
10
13
  end
11
- # rubocop:enable Naming/FileName
data/sorbet/config ADDED
@@ -0,0 +1,3 @@
1
+ --dir
2
+ .
3
+ --ignore=vendor/
@@ -0,0 +1,18 @@
1
+ # typed: strict
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This file was pulled from a central RBI files repository.
5
+ # Please run `bin/tapioca annotations` to update it.
6
+
7
+ class ActiveRecord::Schema
8
+ sig { params(info: T::Hash[T.untyped, T.untyped], blk: T.proc.bind(ActiveRecord::Schema).void).void }
9
+ def self.define(info = nil, &blk); end
10
+ end
11
+
12
+ class ActiveRecord::Migration
13
+ # @shim: Methods on migration are delegated to `SchemaStatements` using `method_missing`
14
+ include ActiveRecord::ConnectionAdapters::SchemaStatements
15
+
16
+ # @shim: Methods on migration are delegated to `DatabaseaStatements` using `method_missing`
17
+ include ActiveRecord::ConnectionAdapters::DatabaseStatements
18
+ end
@@ -0,0 +1,52 @@
1
+ # typed: strict
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This file was pulled from a central RBI files repository.
5
+ # Please run `bin/tapioca annotations` to update it.
6
+
7
+ module ActiveSupport::Testing::Declarative
8
+ sig { params(name: String, block: T.proc.bind(T.untyped).void).void }
9
+ def test(name, &block); end
10
+ end
11
+
12
+ class ActiveSupport::EnvironmentInquirer
13
+ sig { returns(T::Boolean) }
14
+ def development?; end
15
+
16
+ sig { returns(T::Boolean) }
17
+ def production?; end
18
+
19
+ sig { returns(T::Boolean) }
20
+ def test?; end
21
+
22
+ # @method_missing: delegated to String through ActiveSupport::StringInquirer
23
+ sig { returns(T::Boolean) }
24
+ def staging?; end
25
+ end
26
+
27
+ module ActiveSupport::Testing::SetupAndTeardown::ClassMethods
28
+ sig { params(args: T.untyped, block: T.nilable(T.proc.bind(T.untyped).void)).void }
29
+ def setup(*args, &block); end
30
+
31
+ sig { params(args: T.untyped, block: T.nilable(T.proc.bind(T.untyped).void)).void }
32
+ def teardown(*args, &block); end
33
+ end
34
+
35
+ class ActiveSupport::TestCase
36
+ sig { params(args: T.untyped, block: T.nilable(T.proc.bind(T.attached_class).void)).void }
37
+ def self.setup(*args, &block); end
38
+
39
+ sig { params(args: T.untyped, block: T.nilable(T.proc.bind(T.attached_class).void)).void }
40
+ def self.teardown(*args, &block); end
41
+
42
+ sig { params(name: String, block: T.proc.bind(T.attached_class).void).void }
43
+ def self.test(name, &block); end
44
+ end
45
+
46
+ class Object
47
+ sig { returns(T::Boolean) }
48
+ def blank?; end
49
+
50
+ sig { returns(T::Boolean) }
51
+ def present?; end
52
+ end