tapioca 0.4.10 → 0.4.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/lib/tapioca/compilers/dsl/action_controller_helpers.rb +38 -39
- data/lib/tapioca/compilers/dsl/action_mailer.rb +4 -4
- data/lib/tapioca/compilers/dsl/active_record_associations.rb +80 -48
- data/lib/tapioca/compilers/dsl/active_record_columns.rb +60 -65
- data/lib/tapioca/compilers/dsl/active_record_enum.rb +27 -23
- data/lib/tapioca/compilers/dsl/active_record_scope.rb +18 -17
- data/lib/tapioca/compilers/dsl/active_record_typed_store.rb +8 -7
- data/lib/tapioca/compilers/dsl/active_resource.rb +5 -4
- data/lib/tapioca/compilers/dsl/active_support_current_attributes.rb +6 -7
- data/lib/tapioca/compilers/dsl/base.rb +1 -1
- data/lib/tapioca/compilers/dsl/frozen_record.rb +25 -25
- data/lib/tapioca/compilers/dsl/{active_record_identity_cache.rb → identity_cache.rb} +11 -10
- data/lib/tapioca/compilers/dsl/protobuf.rb +1 -1
- data/lib/tapioca/compilers/dsl/sidekiq_worker.rb +83 -0
- data/lib/tapioca/compilers/dsl/smart_properties.rb +1 -1
- data/lib/tapioca/compilers/dsl/state_machines.rb +75 -73
- data/lib/tapioca/compilers/dsl/url_helpers.rb +9 -5
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +69 -40
- data/lib/tapioca/gemfile.rb +30 -22
- data/lib/tapioca/generator.rb +4 -0
- data/lib/tapioca/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41fd25f2497122191c01ef7e9376d6d56e070e9ec5e7626fd1ace153a1b01fd5
|
4
|
+
data.tar.gz: 390bdd0023f086be720f722d530c00cee4eafd603052259331a353c4fa0d3a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f25290fb6e4544329b79b7eb20191126cddf1e9707f1aeb98b60d1dd24ea1f9c7df525ccfb5fd2b50fb12929b773b9adf9143b98da859903c29cdf3125484f6
|
7
|
+
data.tar.gz: 8c7adbe3d3881118487945b46638d5b0bdd29d732424f071c7efb39048db80c7cdd9601bc51e306742aaeae02b002661204e5c18eeb8162c138507269a794c01
|
data/Gemfile
CHANGED
@@ -10,12 +10,10 @@ group(:deployment, :development) do
|
|
10
10
|
gem("rake")
|
11
11
|
end
|
12
12
|
|
13
|
-
gem("bundler", "~> 1.17")
|
14
13
|
gem("yard", "~> 0.9.25")
|
15
14
|
gem("pry-byebug")
|
16
15
|
gem("minitest")
|
17
16
|
gem("minitest-hooks")
|
18
|
-
gem("minitest-fork_executor")
|
19
17
|
gem("minitest-reporters")
|
20
18
|
gem("sorbet")
|
21
19
|
|
@@ -33,6 +31,9 @@ group(:development, :test) do
|
|
33
31
|
gem("activemodel-serializers-xml", "~> 1.0", require: false)
|
34
32
|
gem("activeresource", "~> 5.1", require: false)
|
35
33
|
gem("google-protobuf", "~>3.12.0", require: false)
|
34
|
+
# Fix version to 0.14.1 since it is the last version to support Ruby 2.4
|
35
|
+
gem("shopify-money", "= 0.14.1", require: false)
|
36
|
+
gem("sidekiq", "~>5.0", require: false) # Version 6 dropped support for Ruby 2.4
|
36
37
|
end
|
37
38
|
|
38
39
|
gem "rubocop-sorbet", ">= 0.4.1"
|
@@ -13,8 +13,7 @@ module Tapioca
|
|
13
13
|
module Compilers
|
14
14
|
module Dsl
|
15
15
|
# `Tapioca::Compilers::Dsl::ActionControllerHelpers` decorates RBI files for all
|
16
|
-
# subclasses of
|
17
|
-
# to add helper methods (see https://api.rubyonrails.org/classes/ActionController/Helpers.html).
|
16
|
+
# subclasses of [`ActionController::Base`](https://api.rubyonrails.org/classes/ActionController/Helpers.html).
|
18
17
|
#
|
19
18
|
# For example, with the following `MyHelper` module:
|
20
19
|
#
|
@@ -50,22 +49,22 @@ module Tapioca
|
|
50
49
|
# # user_controller.rbi
|
51
50
|
# # typed: strong
|
52
51
|
# class UserController
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# end
|
52
|
+
# module HelperMethods
|
53
|
+
# include MyHelper
|
56
54
|
#
|
57
|
-
#
|
58
|
-
#
|
55
|
+
# sig { params(user: T.untyped).returns(T.untyped) }
|
56
|
+
# def age(user); end
|
59
57
|
#
|
60
|
-
#
|
61
|
-
#
|
58
|
+
# sig { returns(T.untyped) }
|
59
|
+
# def current_user_name; end
|
60
|
+
# end
|
62
61
|
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
62
|
+
# class HelperProxy < ::ActionView::Base
|
63
|
+
# include HelperMethods
|
64
|
+
# end
|
66
65
|
#
|
67
|
-
#
|
68
|
-
#
|
66
|
+
# sig { returns(HelperProxy) }
|
67
|
+
# def helpers; end
|
69
68
|
# end
|
70
69
|
# ~~~
|
71
70
|
class ActionControllerHelpers < Base
|
@@ -77,42 +76,42 @@ module Tapioca
|
|
77
76
|
.void
|
78
77
|
end
|
79
78
|
def decorate(root, constant)
|
80
|
-
helper_proxy_name = "
|
81
|
-
helper_methods_name = "
|
79
|
+
helper_proxy_name = "HelperProxy"
|
80
|
+
helper_methods_name = "HelperMethods"
|
82
81
|
proxied_helper_methods = constant._helper_methods.map(&:to_s).map(&:to_sym)
|
83
82
|
|
84
|
-
#
|
85
|
-
root.
|
86
|
-
|
83
|
+
# Define the helpers method
|
84
|
+
root.path(constant) do |controller|
|
85
|
+
create_method(controller, 'helpers', return_type: helper_proxy_name)
|
87
86
|
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
# Create helper method module
|
88
|
+
controller.create_module(helper_methods_name) do |helper_methods|
|
89
|
+
helpers_module = constant._helpers
|
91
90
|
|
92
|
-
|
93
|
-
|
94
|
-
constant.instance_method(method_name)
|
95
|
-
else
|
96
|
-
helpers_module.instance_method(method_name)
|
91
|
+
gather_includes(helpers_module).each do |ancestor|
|
92
|
+
helper_methods.create_include(ancestor)
|
97
93
|
end
|
98
|
-
create_method_from_def(helper_methods, method)
|
99
|
-
end
|
100
|
-
end
|
101
94
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
95
|
+
helpers_module.instance_methods(false).each do |method_name|
|
96
|
+
method = if proxied_helper_methods.include?(method_name)
|
97
|
+
constant.instance_method(method_name)
|
98
|
+
else
|
99
|
+
helpers_module.instance_method(method_name)
|
100
|
+
end
|
101
|
+
create_method_from_def(helper_methods, method)
|
102
|
+
end
|
103
|
+
end
|
106
104
|
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
# Create helper proxy class
|
106
|
+
controller.create_class(helper_proxy_name, superclass: "::ActionView::Base") do |proxy|
|
107
|
+
proxy.create_include(helper_methods_name)
|
108
|
+
end
|
110
109
|
end
|
111
110
|
end
|
112
111
|
|
113
112
|
sig { override.returns(T::Enumerable[Module]) }
|
114
113
|
def gather_constants
|
115
|
-
::ActionController::Base.descendants.reject(&:abstract?)
|
114
|
+
::ActionController::Base.descendants.reject(&:abstract?).select(&:name)
|
116
115
|
end
|
117
116
|
|
118
117
|
private
|
@@ -121,7 +120,7 @@ module Tapioca
|
|
121
120
|
def gather_includes(mod)
|
122
121
|
mod.ancestors
|
123
122
|
.reject { |ancestor| ancestor.is_a?(Class) || ancestor == mod || ancestor.name.nil? }
|
124
|
-
.map { |ancestor|
|
123
|
+
.map { |ancestor| "::#{ancestor.name}" }
|
125
124
|
.reverse
|
126
125
|
end
|
127
126
|
end
|
@@ -12,8 +12,8 @@ end
|
|
12
12
|
module Tapioca
|
13
13
|
module Compilers
|
14
14
|
module Dsl
|
15
|
-
# `Tapioca::Compilers::Dsl::ActionMailer` generates RBI files for subclasses of
|
16
|
-
# (
|
15
|
+
# `Tapioca::Compilers::Dsl::ActionMailer` generates RBI files for subclasses of
|
16
|
+
# [`ActionMailer::Base`](https://api.rubyonrails.org/classes/ActionMailer/Base.html).
|
17
17
|
#
|
18
18
|
# For example, with the following `ActionMailer` subclass:
|
19
19
|
#
|
@@ -40,12 +40,12 @@ module Tapioca
|
|
40
40
|
|
41
41
|
sig { override.params(root: Parlour::RbiGenerator::Namespace, constant: T.class_of(::ActionMailer::Base)).void }
|
42
42
|
def decorate(root, constant)
|
43
|
-
root.path(constant) do |
|
43
|
+
root.path(constant) do |mailer|
|
44
44
|
constant.action_methods.to_a.each do |mailer_method|
|
45
45
|
method_def = constant.instance_method(mailer_method)
|
46
46
|
parameters = compile_method_parameters_to_parlour(method_def)
|
47
47
|
create_method(
|
48
|
-
|
48
|
+
mailer,
|
49
49
|
mailer_method,
|
50
50
|
parameters: parameters,
|
51
51
|
return_type: '::ActionMailer::MessageDelivery',
|
@@ -12,9 +12,9 @@ end
|
|
12
12
|
module Tapioca
|
13
13
|
module Compilers
|
14
14
|
module Dsl
|
15
|
-
# `Tapioca::Compilers::Dsl::ActiveRecordAssociations` refines RBI files for subclasses of
|
16
|
-
# (
|
17
|
-
# responsible for defining the methods that would be created for the
|
15
|
+
# `Tapioca::Compilers::Dsl::ActiveRecordAssociations` refines RBI files for subclasses of
|
16
|
+
# [`ActiveRecord::Base`](https://api.rubyonrails.org/classes/ActiveRecord/Base.html).
|
17
|
+
# This generator is only responsible for defining the methods that would be created for the associations that
|
18
18
|
# are defined in the Active Record model.
|
19
19
|
#
|
20
20
|
# For example, with the following model class:
|
@@ -24,6 +24,8 @@ module Tapioca
|
|
24
24
|
# belongs_to :category
|
25
25
|
# has_many :comments
|
26
26
|
# has_one :author, class_name: "User"
|
27
|
+
#
|
28
|
+
# accepts_nested_attributes_for :category, :comments, :author
|
27
29
|
# end
|
28
30
|
# ~~~
|
29
31
|
#
|
@@ -36,56 +38,65 @@ module Tapioca
|
|
36
38
|
#
|
37
39
|
# class Post
|
38
40
|
# include Post::GeneratedAssociationMethods
|
39
|
-
# end
|
40
41
|
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
42
|
+
# module Post::GeneratedAssociationMethods
|
43
|
+
# sig { returns(T.nilable(::User)) }
|
44
|
+
# def author; end
|
45
|
+
#
|
46
|
+
# sig { params(value: T.nilable(::User)).void }
|
47
|
+
# def author=(value); end
|
48
|
+
#
|
49
|
+
# sig { params(attributes: T.untyped).returns(T.untyped) }
|
50
|
+
# def author_attributes=(attributes); end
|
51
|
+
#
|
52
|
+
# sig { params(args: T.untyped, blk: T.untyped).returns(::User) }
|
53
|
+
# def build_author(*args, &blk); end
|
44
54
|
#
|
45
|
-
#
|
46
|
-
#
|
55
|
+
# sig { params(args: T.untyped, blk: T.untyped).returns(::Category) }
|
56
|
+
# def build_category(*args, &blk); end
|
47
57
|
#
|
48
|
-
#
|
49
|
-
#
|
58
|
+
# sig { returns(T.nilable(::Category)) }
|
59
|
+
# def category; end
|
50
60
|
#
|
51
|
-
#
|
52
|
-
#
|
61
|
+
# sig { params(value: T.nilable(::Category)).void }
|
62
|
+
# def category=(value); end
|
53
63
|
#
|
54
|
-
#
|
55
|
-
#
|
64
|
+
# sig { params(attributes: T.untyped).returns(T.untyped) }
|
65
|
+
# def category_attributes=(attributes); end
|
56
66
|
#
|
57
|
-
#
|
58
|
-
#
|
67
|
+
# sig { returns(T::Array[T.untyped]) }
|
68
|
+
# def comment_ids; end
|
59
69
|
#
|
60
|
-
#
|
61
|
-
#
|
70
|
+
# sig { params(ids: T::Array[T.untyped]).returns(T::Array[T.untyped]) }
|
71
|
+
# def comment_ids=(ids); end
|
62
72
|
#
|
63
|
-
#
|
64
|
-
#
|
73
|
+
# sig { returns(::ActiveRecord::Associations::CollectionProxy[Comment]) }
|
74
|
+
# def comments; end
|
65
75
|
#
|
66
|
-
#
|
67
|
-
#
|
76
|
+
# sig { params(value: T::Enumerable[::Comment]).void }
|
77
|
+
# def comments=(value); end
|
68
78
|
#
|
69
|
-
#
|
70
|
-
#
|
79
|
+
# sig { params(attributes: T.untyped).returns(T.untyped) }
|
80
|
+
# def comments_attributes=(attributes); end
|
71
81
|
#
|
72
|
-
#
|
73
|
-
#
|
82
|
+
# sig { params(args: T.untyped, blk: T.untyped).returns(::User) }
|
83
|
+
# def create_author(*args, &blk); end
|
74
84
|
#
|
75
|
-
#
|
76
|
-
#
|
85
|
+
# sig { params(args: T.untyped, blk: T.untyped).returns(::User) }
|
86
|
+
# def create_author!(*args, &blk); end
|
77
87
|
#
|
78
|
-
#
|
79
|
-
#
|
88
|
+
# sig { params(args: T.untyped, blk: T.untyped).returns(::Category) }
|
89
|
+
# def create_category(*args, &blk); end
|
80
90
|
#
|
81
|
-
#
|
82
|
-
#
|
91
|
+
# sig { params(args: T.untyped, blk: T.untyped).returns(::Category) }
|
92
|
+
# def create_category!(*args, &blk); end
|
83
93
|
#
|
84
|
-
#
|
85
|
-
#
|
94
|
+
# sig { returns(T.nilable(::User)) }
|
95
|
+
# def reload_author; end
|
86
96
|
#
|
87
|
-
#
|
88
|
-
#
|
97
|
+
# sig { returns(T.nilable(::Category)) }
|
98
|
+
# def reload_category; end
|
99
|
+
# end
|
89
100
|
# end
|
90
101
|
# ~~~
|
91
102
|
class ActiveRecordAssociations < Base
|
@@ -99,19 +110,15 @@ module Tapioca
|
|
99
110
|
def decorate(root, constant)
|
100
111
|
return if constant.reflections.empty?
|
101
112
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
populate_single_assoc_getter_setter(mod, constant, association_name, reflection)
|
109
|
-
end
|
113
|
+
root.path(constant) do |model|
|
114
|
+
module_name = "GeneratedAssociationMethods"
|
115
|
+
|
116
|
+
model.create_module(module_name) do |mod|
|
117
|
+
populate_nested_attribute_writers(mod, constant)
|
118
|
+
populate_associations(mod, constant)
|
110
119
|
end
|
111
|
-
end
|
112
120
|
|
113
|
-
|
114
|
-
klass.create_include(module_name)
|
121
|
+
model.create_include(module_name)
|
115
122
|
end
|
116
123
|
end
|
117
124
|
|
@@ -122,6 +129,31 @@ module Tapioca
|
|
122
129
|
|
123
130
|
private
|
124
131
|
|
132
|
+
sig { params(mod: Parlour::RbiGenerator::Namespace, constant: T.class_of(ActiveRecord::Base)).void }
|
133
|
+
def populate_nested_attribute_writers(mod, constant)
|
134
|
+
constant.nested_attributes_options.keys.each do |association_name|
|
135
|
+
create_method(
|
136
|
+
mod,
|
137
|
+
"#{association_name}_attributes=",
|
138
|
+
parameters: [
|
139
|
+
Parlour::RbiGenerator::Parameter.new("attributes", type: "T.untyped"),
|
140
|
+
],
|
141
|
+
return_type: "T.untyped"
|
142
|
+
)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
sig { params(mod: Parlour::RbiGenerator::Namespace, constant: T.class_of(ActiveRecord::Base)).void }
|
147
|
+
def populate_associations(mod, constant)
|
148
|
+
constant.reflections.each do |association_name, reflection|
|
149
|
+
if reflection.collection?
|
150
|
+
populate_collection_assoc_getter_setter(mod, constant, association_name, reflection)
|
151
|
+
else
|
152
|
+
populate_single_assoc_getter_setter(mod, constant, association_name, reflection)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
125
157
|
sig do
|
126
158
|
params(
|
127
159
|
klass: Parlour::RbiGenerator::Namespace,
|
@@ -12,24 +12,12 @@ end
|
|
12
12
|
module Tapioca
|
13
13
|
module Compilers
|
14
14
|
module Dsl
|
15
|
-
# `Tapioca::Compilers::Dsl::ActiveRecordColumns` refines RBI files for subclasses of
|
16
|
-
# (
|
17
|
-
# responsible for defining the attribute methods that would be
|
18
|
-
# are defined in the Active Record model.
|
19
|
-
#
|
20
|
-
# **Note:** This generator, by default, generates weak signatures for column methods and treats each
|
21
|
-
# column to be `T.untyped`. This is done on purpose to ensure that the nilability of Active Record
|
22
|
-
# columns do not make it hard for existing code to adopt gradual typing. It is possible, however, to
|
23
|
-
# generate stricter type signatures for your ActiveRecord column types. If your ActiveRecord model extends
|
24
|
-
# a module with name `StrongTypeGeneration`, this generator will generate stricter signatures that follow
|
25
|
-
# closely with the types defined in the schema.
|
26
|
-
#
|
27
|
-
# The `StrongTypeGeneration` module you define in your application should add an `after_initialize` callback
|
28
|
-
# to the model and ensure that all the non-nilable attributes of the model are actually initialized with non-`nil`
|
29
|
-
# values.
|
15
|
+
# `Tapioca::Compilers::Dsl::ActiveRecordColumns` refines RBI files for subclasses of
|
16
|
+
# [`ActiveRecord::Base`](https://api.rubyonrails.org/classes/ActiveRecord/Base.html).
|
17
|
+
# This generator is only responsible for defining the attribute methods that would be
|
18
|
+
# created for the columns that are defined in the Active Record model.
|
30
19
|
#
|
31
20
|
# For example, with the following model class:
|
32
|
-
#
|
33
21
|
# ~~~rb
|
34
22
|
# class Post < ActiveRecord::Base
|
35
23
|
# end
|
@@ -54,54 +42,58 @@ module Tapioca
|
|
54
42
|
# # post.rbi
|
55
43
|
# # typed: true
|
56
44
|
# class Post
|
57
|
-
#
|
58
|
-
#
|
45
|
+
# include GeneratedAttributeMethods
|
46
|
+
#
|
47
|
+
# module GeneratedAttributeMethods
|
48
|
+
# sig { returns(T.nilable(::String)) }
|
49
|
+
# def body; end
|
59
50
|
#
|
60
|
-
#
|
61
|
-
#
|
51
|
+
# sig { params(value: T.nilable(::String)).returns(T.nilable(::String)) }
|
52
|
+
# def body=; end
|
62
53
|
#
|
63
|
-
#
|
64
|
-
#
|
54
|
+
# sig { returns(T::Boolean) }
|
55
|
+
# def body?; end
|
65
56
|
#
|
66
|
-
#
|
67
|
-
#
|
57
|
+
# sig { returns(T.nilable(::ActiveSupport::TimeWithZone)) }
|
58
|
+
# def created_at; end
|
68
59
|
#
|
69
|
-
#
|
70
|
-
#
|
60
|
+
# sig { params(value: ::ActiveSupport::TimeWithZone).returns(::ActiveSupport::TimeWithZone) }
|
61
|
+
# def created_at=; end
|
71
62
|
#
|
72
|
-
#
|
73
|
-
#
|
63
|
+
# sig { returns(T::Boolean) }
|
64
|
+
# def created_at?; end
|
74
65
|
#
|
75
|
-
#
|
76
|
-
#
|
66
|
+
# sig { returns(T.nilable(T::Boolean)) }
|
67
|
+
# def published; end
|
77
68
|
#
|
78
|
-
#
|
79
|
-
#
|
69
|
+
# sig { params(value: T::Boolean).returns(T::Boolean) }
|
70
|
+
# def published=; end
|
80
71
|
#
|
81
|
-
#
|
82
|
-
#
|
72
|
+
# sig { returns(T::Boolean) }
|
73
|
+
# def published?; end
|
83
74
|
#
|
84
|
-
#
|
85
|
-
#
|
75
|
+
# sig { returns(::String) }
|
76
|
+
# def title; end
|
86
77
|
#
|
87
|
-
#
|
88
|
-
#
|
78
|
+
# sig { params(value: ::String).returns(::String) }
|
79
|
+
# def title=(value); end
|
89
80
|
#
|
90
|
-
#
|
91
|
-
#
|
81
|
+
# sig { returns(T::Boolean) }
|
82
|
+
# def title?; end
|
92
83
|
#
|
93
|
-
#
|
94
|
-
#
|
84
|
+
# sig { returns(T.nilable(::ActiveSupport::TimeWithZone)) }
|
85
|
+
# def updated_at; end
|
95
86
|
#
|
96
|
-
#
|
97
|
-
#
|
87
|
+
# sig { params(value: ::ActiveSupport::TimeWithZone).returns(::ActiveSupport::TimeWithZone) }
|
88
|
+
# def updated_at=; end
|
98
89
|
#
|
99
|
-
#
|
100
|
-
#
|
90
|
+
# sig { returns(T::Boolean) }
|
91
|
+
# def updated_at?; end
|
101
92
|
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
93
|
+
# ## Also the methods added by https://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/Dirty.html
|
94
|
+
# ## Also the methods added by https://api.rubyonrails.org/classes/ActiveModel/Dirty.html
|
95
|
+
# ## Also the methods added by https://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/BeforeTypeCast.html
|
96
|
+
# end
|
105
97
|
# end
|
106
98
|
# ~~~
|
107
99
|
class ActiveRecordColumns < Base
|
@@ -111,26 +103,27 @@ module Tapioca
|
|
111
103
|
def decorate(root, constant)
|
112
104
|
return unless constant.table_exists?
|
113
105
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
106
|
+
root.path(constant) do |model|
|
107
|
+
module_name = "GeneratedAttributeMethods"
|
108
|
+
|
109
|
+
model.create_module(module_name) do |mod|
|
110
|
+
constant.columns_hash.each_key do |column_name|
|
111
|
+
column_name = column_name.to_s
|
112
|
+
add_methods_for_attribute(mod, constant, column_name)
|
113
|
+
end
|
120
114
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
115
|
+
constant.attribute_aliases.each do |attribute_name, column_name|
|
116
|
+
attribute_name = attribute_name.to_s
|
117
|
+
column_name = column_name.to_s
|
118
|
+
new_method_names = constant.attribute_method_matchers.map { |m| m.method_name(attribute_name) }
|
119
|
+
old_method_names = constant.attribute_method_matchers.map { |m| m.method_name(column_name) }
|
120
|
+
methods_to_add = new_method_names - old_method_names
|
127
121
|
|
128
|
-
|
122
|
+
add_methods_for_attribute(mod, constant, column_name, attribute_name, methods_to_add)
|
123
|
+
end
|
129
124
|
end
|
130
|
-
end
|
131
125
|
|
132
|
-
|
133
|
-
klass.create_include(module_name)
|
126
|
+
model.create_include(module_name)
|
134
127
|
end
|
135
128
|
end
|
136
129
|
|
@@ -318,6 +311,8 @@ module Tapioca
|
|
318
311
|
|
319
312
|
getter_type =
|
320
313
|
case column_type
|
314
|
+
when defined?(MoneyColumn) && MoneyColumn::ActiveRecordType
|
315
|
+
"::Money"
|
321
316
|
when ActiveRecord::Type::Integer
|
322
317
|
"::Integer"
|
323
318
|
when ActiveRecord::Type::String
|