rbs_draper 1.2.0 → 1.3.0

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: 44e80ca97ef57836af3ef885d059d9e1d1a2a9d6ba4dab80adf6d30f01556f9c
4
- data.tar.gz: 5926448a80b1f772f38044e562779ffda88c1336f262456df6d6d63b0be32453
3
+ metadata.gz: 1a1efc1d2112225133b3b99db9a211b5c81263b405a82d3b8a5220ccc27d576d
4
+ data.tar.gz: bcbce1a9c58ded2d80a2249b011cfe4156d195095290beeb9126f7696a8df6e1
5
5
  SHA512:
6
- metadata.gz: b3375123ce9db9a5fa0815f390b4212cdfbdc60496223fa3797a5f0d2bd087230a44e4cbe980e963f7d3741c49351bf0a69c20847d0d049c26f6087cbdd87f4f
7
- data.tar.gz: 2a8d79b1e174b7dec3e818c65acf2e9005fbdf5e3a6096a22b4b5fffdb00fa5626c306d7ed40526ff900cdb27b790e2eedbee2eb6753fc913f76393faaa73c0b
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.2.0)
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)
@@ -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
 
@@ -5,10 +5,20 @@ module Draper
5
5
 
6
6
  def self.delegate_all: () -> void
7
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
8
11
  def decorated?: () -> bool
9
12
  def decorated_with?: (untyped decorator_class) -> bool
10
13
  end
11
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
+
12
22
  class HelperProxy
13
23
  # Note: HelperProxy behaves like ActiveView::Base via method_missing.
14
24
  # To support it, this type includes the sub-modules of ActiveView instead of method_missing.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbsDraper
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -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.2.0
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-11 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