rbs_draper 1.1.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf608d212ec0ad6d2d0f1ac28642e425b9f79afa6762973c302510b263c8fc7c
4
- data.tar.gz: 615f1b9983be7510189c0d3580f67e9981fd594af4bc39d2ab444c3bcafe8c94
3
+ metadata.gz: 1a1efc1d2112225133b3b99db9a211b5c81263b405a82d3b8a5220ccc27d576d
4
+ data.tar.gz: bcbce1a9c58ded2d80a2249b011cfe4156d195095290beeb9126f7696a8df6e1
5
5
  SHA512:
6
- metadata.gz: 6f70d4b49f6ff39a7bf429870e4b0a7d3dbfaf250d4c7e37742b6c2924d23533ff3c728989f220c8c80556c21eaa7e7f3952d0a3c4468ff34dd3f4411b1fbea5
7
- data.tar.gz: 8a45bc1635b081590d3b00994285a07bdf18503d9fd02466e61a385edc11795a0c5b9f6c88acbf0c07995d4a8cd32253298e3a95ef1b6f533c85bdf6ab6218cd
6
+ metadata.gz: ec2ab3d52271357bc59ef8e20830828335a9432f89537d77174448e3b4bc2d59ae542b33dd30d727dfb9015a438342f1089dcfc33bdbe2861566cca406e520a8
7
+ data.tar.gz: 90d77c75e649270d7fcf5e0f4c4ab553e961dcc98b51381be4729267c2d933a8ce694b16b74258d99628cbf871fe87e47e03bdcc3e4f803ba352713c87f78b46
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs_draper (1.1.3)
4
+ rbs_draper (1.3.0)
5
5
  activesupport
6
6
  draper
7
7
  fileutils
@@ -123,7 +123,7 @@ GEM
123
123
  diff-lcs (>= 1.2.0, < 2.0)
124
124
  rspec-support (~> 3.12.0)
125
125
  rspec-support (3.12.0)
126
- rubocop (1.56.2)
126
+ rubocop (1.56.3)
127
127
  base64 (~> 0.1.1)
128
128
  json (~> 2.3)
129
129
  language_server-protocol (>= 3.17.0)
data/README.md CHANGED
@@ -21,6 +21,21 @@ decorator names to model names in `lib/tasks/rbs_draper.rake`. For example:
21
21
  task.mapping = -> { { AdminUserDecorator => User } }
22
22
  end
23
23
 
24
+ ## Accessing Helpers
25
+
26
+ If your decorators access to the custom helpers via `#h` method, you need to define the types
27
+ for the custom helpers into `Draper::HelperProxy`:
28
+
29
+ ```ruby
30
+ module Draper
31
+ class HelperProxy
32
+ include MyCustomHelper
33
+
34
+ def my_custom_helper_method: (String, String) -> String
35
+ end
36
+ end
37
+ ```
38
+
24
39
  ## Usage
25
40
 
26
41
  1. Run `rbs:draper:clean` at first
@@ -24,6 +24,8 @@ module RbsDraper
24
24
 
25
25
  format <<~RBS
26
26
  #{header}
27
+ #{mixin_decls}
28
+ #{class_method_decls}
27
29
  #{object_method_decls}
28
30
 
29
31
  #{method_decls}
@@ -60,14 +62,25 @@ module RbsDraper
60
62
  end.join("\n")
61
63
  end
62
64
 
65
+ def mixin_decls
66
+ "extend Draper::Finders[#{decorated_class_name}]" if klass.singleton_class < Draper::Finders
67
+ end
68
+
69
+ def class_method_decls
70
+ "def self.decorate: (#{decorated_class_name} object, **untyped options) -> self"
71
+ end
72
+
63
73
  def object_method_decls
64
- object_name = decorated_class&.name || klass.name.to_s.sub(/Decorator$/, "")
65
- if object_name.include?("::")
66
- "def object: () -> #{object_name}"
74
+ if decorated_class_name.include?("::")
75
+ <<~RBS
76
+ def initialize: (#{decorated_class_name} object, **untyped options) -> void
77
+ def object: () -> #{decorated_class_name}
78
+ RBS
67
79
  else
68
80
  <<~RBS
69
- def object: () -> #{object_name}
70
- def #{object_name.underscore}: () -> #{object_name}
81
+ def initialize: (#{decorated_class_name} object, **untyped options) -> void
82
+ def object: () -> #{decorated_class_name}
83
+ def #{decorated_class_name.underscore}: () -> #{decorated_class_name}
71
84
  RBS
72
85
  end
73
86
  end
@@ -91,13 +104,16 @@ module RbsDraper
91
104
  end
92
105
 
93
106
  def decorated_class_def
94
- class_name = decorated_class&.name || klass.name.to_s.sub(/Decorator$/, "")
95
- type_name = RBS::TypeName(class_name).absolute!
107
+ type_name = RBS::TypeName(decorated_class_name).absolute!
96
108
  @decorated_class_def ||= rbs_builder.build_instance(type_name)
97
109
  rescue StandardError
98
110
  nil
99
111
  end
100
112
 
113
+ def decorated_class_name
114
+ @decorated_class_name = decorated_class&.name || klass.object_class.name.to_s
115
+ end
116
+
101
117
  def delegated_methods
102
118
  return [] unless klass.ancestors.include? ::Draper::AutomaticDelegation
103
119
 
@@ -1,8 +1,44 @@
1
1
  module Draper
2
2
  class Decorator
3
+ include Draper::ViewHelpers
4
+ extend Draper::ViewHelpers::ClassMethods
5
+
3
6
  def self.delegate_all: () -> void
4
7
  def self.decorates_association: (Symbol association, **untyped options) -> void
8
+ def self.decorates_finders: () -> void
9
+ def self.object_class: () -> singleton(Class)
10
+ def self.object_class?: () -> bool
5
11
  def decorated?: () -> bool
6
12
  def decorated_with?: (untyped decorator_class) -> bool
7
13
  end
14
+
15
+ module Finders[T]
16
+ def find: (untyped id, **untyped options) -> T
17
+ def all: (**untyped options) -> untyped
18
+ def first: (**untyped options) -> T
19
+ def last: (**untyped options) -> T
20
+ end
21
+
22
+ class HelperProxy
23
+ # Note: HelperProxy behaves like ActiveView::Base via method_missing.
24
+ # To support it, this type includes the sub-modules of ActiveView instead of method_missing.
25
+
26
+ include ActionView::Helpers
27
+ include ERB::Util
28
+ include ActionView::Context
29
+ end
30
+
31
+ module ViewHelpers
32
+ module ClassMethods
33
+ def helpers: () -> HelperProxy
34
+
35
+ alias h helpers
36
+ end
37
+
38
+ def helpers: () -> HelperProxy
39
+ def localize: (*untyped) -> String
40
+
41
+ alias h helpers
42
+ alias l localize
43
+ end
8
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbsDraper
4
- VERSION = "1.1.3"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -2,7 +2,7 @@
2
2
  sources:
3
3
  - type: git
4
4
  name: ruby/gem_rbs_collection
5
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
5
+ revision: 248499a924c3cb331d40ca667d40528814043788
6
6
  remote: https://github.com/ruby/gem_rbs_collection.git
7
7
  repo_dir: gems
8
8
  path: ".gem_rbs_collection"
@@ -16,7 +16,7 @@ gems:
16
16
  source:
17
17
  type: git
18
18
  name: ruby/gem_rbs_collection
19
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
19
+ revision: 248499a924c3cb331d40ca667d40528814043788
20
20
  remote: https://github.com/ruby/gem_rbs_collection.git
21
21
  repo_dir: gems
22
22
  - name: actionview
@@ -24,7 +24,7 @@ gems:
24
24
  source:
25
25
  type: git
26
26
  name: ruby/gem_rbs_collection
27
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
27
+ revision: 248499a924c3cb331d40ca667d40528814043788
28
28
  remote: https://github.com/ruby/gem_rbs_collection.git
29
29
  repo_dir: gems
30
30
  - name: activemodel
@@ -32,7 +32,7 @@ gems:
32
32
  source:
33
33
  type: git
34
34
  name: ruby/gem_rbs_collection
35
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
35
+ revision: 248499a924c3cb331d40ca667d40528814043788
36
36
  remote: https://github.com/ruby/gem_rbs_collection.git
37
37
  repo_dir: gems
38
38
  - name: activerecord
@@ -40,7 +40,7 @@ gems:
40
40
  source:
41
41
  type: git
42
42
  name: ruby/gem_rbs_collection
43
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
43
+ revision: 248499a924c3cb331d40ca667d40528814043788
44
44
  remote: https://github.com/ruby/gem_rbs_collection.git
45
45
  repo_dir: gems
46
46
  - name: activesupport
@@ -48,7 +48,7 @@ gems:
48
48
  source:
49
49
  type: git
50
50
  name: ruby/gem_rbs_collection
51
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
51
+ revision: 248499a924c3cb331d40ca667d40528814043788
52
52
  remote: https://github.com/ruby/gem_rbs_collection.git
53
53
  repo_dir: gems
54
54
  - name: ast
@@ -56,7 +56,7 @@ gems:
56
56
  source:
57
57
  type: git
58
58
  name: ruby/gem_rbs_collection
59
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
59
+ revision: 248499a924c3cb331d40ca667d40528814043788
60
60
  remote: https://github.com/ruby/gem_rbs_collection.git
61
61
  repo_dir: gems
62
62
  - name: base64
@@ -72,7 +72,7 @@ gems:
72
72
  source:
73
73
  type: git
74
74
  name: ruby/gem_rbs_collection
75
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
75
+ revision: 248499a924c3cb331d40ca667d40528814043788
76
76
  remote: https://github.com/ruby/gem_rbs_collection.git
77
77
  repo_dir: gems
78
78
  - name: date
@@ -92,7 +92,7 @@ gems:
92
92
  source:
93
93
  type: git
94
94
  name: ruby/gem_rbs_collection
95
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
95
+ revision: 248499a924c3cb331d40ca667d40528814043788
96
96
  remote: https://github.com/ruby/gem_rbs_collection.git
97
97
  repo_dir: gems
98
98
  - name: json
@@ -120,7 +120,7 @@ gems:
120
120
  source:
121
121
  type: git
122
122
  name: ruby/gem_rbs_collection
123
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
123
+ revision: 248499a924c3cb331d40ca667d40528814043788
124
124
  remote: https://github.com/ruby/gem_rbs_collection.git
125
125
  repo_dir: gems
126
126
  - name: optparse
@@ -132,7 +132,7 @@ gems:
132
132
  source:
133
133
  type: git
134
134
  name: ruby/gem_rbs_collection
135
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
135
+ revision: 248499a924c3cb331d40ca667d40528814043788
136
136
  remote: https://github.com/ruby/gem_rbs_collection.git
137
137
  repo_dir: gems
138
138
  - name: pathname
@@ -144,7 +144,7 @@ gems:
144
144
  source:
145
145
  type: git
146
146
  name: ruby/gem_rbs_collection
147
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
147
+ revision: 248499a924c3cb331d40ca667d40528814043788
148
148
  remote: https://github.com/ruby/gem_rbs_collection.git
149
149
  repo_dir: gems
150
150
  - name: rails-dom-testing
@@ -152,7 +152,7 @@ gems:
152
152
  source:
153
153
  type: git
154
154
  name: ruby/gem_rbs_collection
155
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
155
+ revision: 248499a924c3cb331d40ca667d40528814043788
156
156
  remote: https://github.com/ruby/gem_rbs_collection.git
157
157
  repo_dir: gems
158
158
  - name: railties
@@ -160,7 +160,7 @@ gems:
160
160
  source:
161
161
  type: git
162
162
  name: ruby/gem_rbs_collection
163
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
163
+ revision: 248499a924c3cb331d40ca667d40528814043788
164
164
  remote: https://github.com/ruby/gem_rbs_collection.git
165
165
  repo_dir: gems
166
166
  - name: rainbow
@@ -168,7 +168,7 @@ gems:
168
168
  source:
169
169
  type: git
170
170
  name: ruby/gem_rbs_collection
171
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
171
+ revision: 248499a924c3cb331d40ca667d40528814043788
172
172
  remote: https://github.com/ruby/gem_rbs_collection.git
173
173
  repo_dir: gems
174
174
  - name: rbs
@@ -184,7 +184,7 @@ gems:
184
184
  source:
185
185
  type: git
186
186
  name: ruby/gem_rbs_collection
187
- revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
187
+ revision: 248499a924c3cb331d40ca667d40528814043788
188
188
  remote: https://github.com/ruby/gem_rbs_collection.git
189
189
  repo_dir: gems
190
190
  - name: securerandom
@@ -9,6 +9,7 @@ module RbsDraper
9
9
  attr_reader decorated_class: singleton(Class)?
10
10
 
11
11
  @decorated_class_def: RBS::Definition
12
+ @decorated_class_name: String
12
13
  @user_defined_class: RBS::Definition
13
14
 
14
15
  def initialize: (singleton(Draper::Decorator) klass, RBS::DefinitionBuilder rbs_builder, ?decorated_class: singleton(Class)?) -> void
@@ -18,10 +19,13 @@ module RbsDraper
18
19
 
19
20
  def format: (String rbs) -> String
20
21
  def header: () -> String
22
+ def mixin_decls: () -> String?
23
+ def class_method_decls: () -> String?
21
24
  def object_method_decls: () -> String
22
25
  def method_decls: () -> String?
23
26
  def footer: () -> String
24
27
  def module_names: () -> Array[String]
28
+ def decorated_class_name: () -> String
25
29
  def decorated_class_def: () -> RBS::Definition?
26
30
  def delegated_methods: () -> Array[[Symbol, RBS::Definition::Method]]
27
31
  def user_defined_class: () -> RBS::Definition?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_draper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takeshi KOMIYA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-08 00:00:00.000000000 Z
11
+ date: 2023-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport