Skip to content

Commit eba4a5c

Browse files
authored
Merge pull request #502 from Shopify/at-smart-properties-module
2 parents 114ceb5 + 82dc4f9 commit eba4a5c

File tree

4 files changed

+66
-33
lines changed

4 files changed

+66
-33
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ GEM
246246
connection_pool (>= 2.2.2)
247247
rack (~> 2.0)
248248
redis (>= 4.2.0)
249-
smart_properties (1.15.0)
249+
smart_properties (1.16.2)
250250
sorbet (0.5.9125)
251251
sorbet-static (= 0.5.9125)
252252
sorbet-runtime (0.5.9125)

lib/tapioca/compilers/dsl/smart_properties.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ def decorate(root, constant)
8484

8585
sig { override.returns(T::Enumerable[Module]) }
8686
def gather_constants
87-
all_classes.select do |c|
88-
c < ::SmartProperties
89-
end.reject do |c|
90-
name_of(c).nil? || c == ::SmartProperties::Validations::Ancestor
87+
all_modules.select do |c|
88+
name_of(c) &&
89+
c != ::SmartProperties::Validations::Ancestor &&
90+
c < ::SmartProperties && ::SmartProperties::ClassMethods === c
9191
end
9292
end
9393

sorbet/rbi/gems/smart_properties@1.15.0.rbi renamed to sorbet/rbi/gems/smart_properties@1.16.2.rbi

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# DO NOT EDIT MANUALLY
22
# This is an autogenerated file for types exported from the `smart_properties` gem.
3-
# Please instead update this file by running `tapioca sync`.
3+
# Please instead update this file by running `bin/tapioca gem smart_properties`.
44

55
# typed: true
66

77
module SmartProperties
8-
mixes_in_class_methods(::SmartProperties::ClassMethods)
8+
mixes_in_class_methods ::SmartProperties::ClassMethods
9+
mixes_in_class_methods ::SmartProperties::ModuleMethods
910

1011
def initialize(*args, &block); end
1112

1213
def [](name); end
1314
def []=(name, value); end
1415

1516
class << self
16-
1717
private
1818

1919
def included(base); end
@@ -24,9 +24,9 @@ class SmartProperties::AssignmentError < ::SmartProperties::Error
2424
def initialize(sender, property, message); end
2525

2626
def property; end
27-
def property=(_); end
27+
def property=(_arg0); end
2828
def sender; end
29-
def sender=(_); end
29+
def sender=(_arg0); end
3030
end
3131

3232
module SmartProperties::ClassMethods
@@ -38,28 +38,25 @@ module SmartProperties::ClassMethods
3838
def property!(name, options = T.unsafe(nil)); end
3939
end
4040

41-
class SmartProperties::ConfigurationError < ::SmartProperties::Error
42-
end
41+
class SmartProperties::ConfigurationError < ::SmartProperties::Error; end
4342

4443
class SmartProperties::ConstructorArgumentForwardingError < ::SmartProperties::Error
4544
def initialize(positional_arguments, keyword_arguments); end
4645

47-
4846
private
4947

5048
def generate_description(argument_type, argument_number); end
5149
end
5250

53-
class SmartProperties::Error < ::ArgumentError
54-
end
51+
class SmartProperties::Error < ::ArgumentError; end
5552

5653
class SmartProperties::InitializationError < ::SmartProperties::Error
5754
def initialize(sender, properties); end
5855

5956
def properties; end
60-
def properties=(_); end
57+
def properties=(_arg0); end
6158
def sender; end
62-
def sender=(_); end
59+
def sender=(_arg0); end
6360
def to_hash; end
6461
end
6562

@@ -68,7 +65,7 @@ class SmartProperties::InvalidValueError < ::SmartProperties::AssignmentError
6865

6966
def to_hash; end
7067
def value; end
71-
def value=(_); end
68+
def value=(_arg0); end
7269

7370
private
7471

@@ -81,6 +78,10 @@ class SmartProperties::MissingValueError < ::SmartProperties::AssignmentError
8178
def to_hash; end
8279
end
8380

81+
module SmartProperties::ModuleMethods
82+
def included(target); end
83+
end
84+
8485
class SmartProperties::Property
8586
def initialize(name, attrs = T.unsafe(nil)); end
8687

@@ -115,11 +116,10 @@ class SmartProperties::Property
115116
end
116117

117118
SmartProperties::Property::ALLOWED_DEFAULT_CLASSES = T.let(T.unsafe(nil), Array)
118-
119119
SmartProperties::Property::MODULE_REFERENCE = T.let(T.unsafe(nil), Symbol)
120120

121121
class SmartProperties::PropertyCollection
122-
include(::Enumerable)
122+
include ::Enumerable
123123

124124
def initialize; end
125125

@@ -136,11 +136,11 @@ class SmartProperties::PropertyCollection
136136
protected
137137

138138
def children; end
139-
def children=(_); end
139+
def children=(_arg0); end
140140
def collection; end
141-
def collection=(_); end
141+
def collection=(_arg0); end
142142
def collection_with_parent_collection; end
143-
def collection_with_parent_collection=(_); end
143+
def collection_with_parent_collection=(_arg0); end
144144
def notify_children; end
145145
def refresh(parent_collection); end
146146

@@ -150,19 +150,18 @@ class SmartProperties::PropertyCollection
150150
end
151151

152152
SmartProperties::VERSION = T.let(T.unsafe(nil), String)
153-
154-
module SmartProperties::Validations
155-
end
153+
module SmartProperties::Validations; end
156154

157155
class SmartProperties::Validations::Ancestor
158-
include(::SmartProperties)
159-
extend(::SmartProperties::ClassMethods)
156+
include ::SmartProperties
157+
extend ::SmartProperties::ClassMethods
158+
extend ::SmartProperties::ModuleMethods
160159

161160
def to_proc; end
162161
def to_s; end
163162
def validate(klass); end
164163

165164
class << self
166-
def must_be(*_); end
165+
def must_be(*_arg0); end
167166
end
168167
end

spec/tapioca/compilers/dsl/smart_properties_spec.rb

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Tapioca::Compilers::Dsl::SmartPropertiesSpec < DslSpec
99
assert_empty(gathered_constants)
1010
end
1111

12-
it("gathers only SmartProperty classes") do
12+
it("gathers only SmartProperty classes and modules") do
1313
add_ruby_file("content.rb", <<~RUBY)
1414
class Post
1515
include ::SmartProperties
@@ -21,16 +21,27 @@ class User
2121
2222
class Comment
2323
end
24+
25+
module Viewable
26+
include ::SmartProperties
27+
end
28+
29+
module Editable
30+
end
2431
RUBY
2532

26-
assert_equal(["Post", "User"], gathered_constants)
33+
assert_equal(["Post", "User", "Viewable"], gathered_constants)
2734
end
2835

29-
it("ignores SmartProperty classes without a name") do
36+
it("ignores SmartProperty classes and modules without a name") do
3037
add_ruby_file("content.rb", <<~RUBY)
3138
post = Class.new do
3239
include ::SmartProperties
3340
end
41+
42+
viewable = Module.new do
43+
include ::SmartProperties
44+
end
3445
RUBY
3546

3647
assert_empty(gathered_constants)
@@ -52,7 +63,7 @@ class Post
5263
assert_equal(expected, rbi_for(:Post))
5364
end
5465

55-
it("generates RBI file for simple smart property") do
66+
it("generates RBI file for simple smart property class") do
5667
add_ruby_file("post.rb", <<~RUBY)
5768
class Post
5869
include SmartProperties
@@ -75,6 +86,29 @@ def title=(title); end
7586
assert_equal(expected, rbi_for(:Post))
7687
end
7788

89+
it("generates RBI file for simple smart property module") do
90+
add_ruby_file("viewable.rb", <<~RUBY)
91+
module Viewable
92+
include SmartProperties
93+
property :title, accepts: String
94+
end
95+
RUBY
96+
97+
expected = <<~RBI
98+
# typed: strong
99+
100+
module Viewable
101+
sig { returns(T.nilable(::String)) }
102+
def title; end
103+
104+
sig { params(title: T.nilable(::String)).returns(T.nilable(::String)) }
105+
def title=(title); end
106+
end
107+
RBI
108+
109+
assert_equal(expected, rbi_for(:Viewable))
110+
end
111+
78112
it("generates RBI file for required smart property") do
79113
add_ruby_file("post.rb", <<~RUBY)
80114
class Post

0 commit comments

Comments
 (0)