tapioca 0.6.0 → 0.6.1

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: a99e7a4475e2991e305c461774e45e128d430632e96581fc541680b61275e4e1
4
- data.tar.gz: 8ee7b9b225dd752edf606a98aee1b8490687f351dae642b24060549740d2ab5a
3
+ metadata.gz: 4eea2d365ede4ba5398d65a2042c7dc86270ec7309cb0bc9747357f44ea1c675
4
+ data.tar.gz: 7f7252a0619b138664fe5d30acf0858fb09eb9403d513a06266cc58c464dd3b2
5
5
  SHA512:
6
- metadata.gz: 3ab85b1422fba3aa79de02fad9e164b2013cef3a388ad196e4c11f0c2c6dc142b6a540a430f4a4ace9f3ebe92da2f29fbe733e13ceb481277e7d7e2691db9f0c
7
- data.tar.gz: b9f2c2cca77916e08fcbb1ca021818b51bc5edd8d899b2f5e89dae3bfddd38dd8e403b16bacd8c8db37dc630448458d7d6f52e6445cb9ecb96c6bba16c4c20e7
6
+ metadata.gz: 1ac4530bd50af56e2acee0a630571dbc7452cf10e55ec89088ddb5ed8f9a350fae0b4031602fa13b5b319390172e55bdebe6a3d3b6a722e88fe7902aceb5bb61
7
+ data.tar.gz: 26a6365606966861c36ffcea2b247a7dfc5395925d04a9d89f35273ce6ae9c3f29ee3d94002c3dd49c46f05acda9e202025a79cf9e4dd0fbebe49ff542d575ae
data/Gemfile CHANGED
@@ -35,4 +35,5 @@ group(:development, :test) do
35
35
  gem("config", require: false)
36
36
  gem("aasm", require: false)
37
37
  gem("bcrypt", require: false)
38
+ gem("xpath", require: false)
38
39
  end
@@ -532,7 +532,7 @@ module Tapioca
532
532
  ],
533
533
  return_type: "T::Boolean"
534
534
  )
535
- when :find, :find_by!
535
+ when :find
536
536
  create_common_method(
537
537
  "find",
538
538
  parameters: [
@@ -548,6 +548,14 @@ module Tapioca
548
548
  ],
549
549
  return_type: "T.nilable(#{constant_name})"
550
550
  )
551
+ when :find_by!
552
+ create_common_method(
553
+ "find_by!",
554
+ parameters: [
555
+ create_rest_param("args", type: "T.untyped"),
556
+ ],
557
+ return_type: constant_name
558
+ )
551
559
  when :first, :last, :take
552
560
  create_common_method(
553
561
  method_name,
@@ -64,12 +64,12 @@ module Tapioca
64
64
 
65
65
  sig { override.returns(T::Enumerable[Module]) }
66
66
  def gather_constants
67
- all_modules.select do |const|
67
+ all_classes.select do |const|
68
68
  name = qualified_name_of(const)
69
69
 
70
70
  name &&
71
71
  !name.match?(BUILT_IN_MATCHER) &&
72
- const < ::Rails::Generators::Base
72
+ ::Rails::Generators::Base > const
73
73
  end
74
74
  end
75
75
 
@@ -71,14 +71,15 @@ module Tapioca
71
71
  )
72
72
  return if properties.keys.empty?
73
73
 
74
- instance_methods = constant.instance_methods(false).map(&:to_s).to_set
75
-
76
74
  root.create_path(constant) do |k|
77
- properties.values.each do |property|
78
- generate_methods_for_property(k, property) do |method_name|
79
- !instance_methods.include?(method_name.to_sym)
75
+ smart_properties_methods_name = "SmartPropertiesGeneratedMethods"
76
+ k.create_module(smart_properties_methods_name) do |mod|
77
+ properties.values.each do |property|
78
+ generate_methods_for_property(mod, property)
80
79
  end
81
80
  end
81
+
82
+ k.create_include(smart_properties_methods_name)
82
83
  end
83
84
  end
84
85
 
@@ -95,26 +96,21 @@ module Tapioca
95
96
 
96
97
  sig do
97
98
  params(
98
- klass: RBI::Scope,
99
- property: ::SmartProperties::Property,
100
- block: T.proc.params(arg: String).returns(T::Boolean)
99
+ mod: RBI::Scope,
100
+ property: ::SmartProperties::Property
101
101
  ).void
102
102
  end
103
- def generate_methods_for_property(klass, property, &block)
103
+ def generate_methods_for_property(mod, property)
104
104
  type = type_for(property)
105
105
 
106
106
  if property.writable?
107
107
  name = property.name.to_s
108
108
  method_name = "#{name}="
109
109
 
110
- klass.create_method(
111
- method_name,
112
- parameters: [create_param(name, type: type)],
113
- return_type: type
114
- ) if block.call(method_name)
110
+ mod.create_method(method_name, parameters: [create_param(name, type: type)], return_type: type)
115
111
  end
116
112
 
117
- klass.create_method(property.reader.to_s, return_type: type) if block.call(property.reader.to_s)
113
+ mod.create_method(property.reader.to_s, return_type: type)
118
114
  end
119
115
 
120
116
  BOOLEANS = T.let([
@@ -151,9 +151,14 @@ module Tapioca
151
151
 
152
152
  sig { params(mod: Module, helper: Module).returns(T::Boolean) }
153
153
  def includes_helper?(mod, helper)
154
- superclass_ancestors = mod.superclass&.ancestors if Class === mod
155
- superclass_ancestors ||= []
156
- (mod.ancestors - superclass_ancestors).include?(helper)
154
+ superclass_ancestors = []
155
+
156
+ if Class === mod
157
+ superclass = superclass_of(mod)
158
+ superclass_ancestors = ancestors_of(superclass) if superclass
159
+ end
160
+
161
+ (ancestors_of(mod) - superclass_ancestors).any? { |ancestor| helper == ancestor }
157
162
  end
158
163
  end
159
164
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.6.0"
5
+ VERSION = "0.6.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-12-17 00:00:00.000000000 Z
14
+ date: 2021-12-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler