acts-as-messageable 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +8 -0
  3. data/.github/workflows/test.yml +152 -0
  4. data/.rubocop.yml +14 -1
  5. data/.rubocop_todo.yml +49 -7
  6. data/.ruby-version +1 -0
  7. data/Appraisals +11 -0
  8. data/Dockerfile +2 -1
  9. data/Gemfile +19 -13
  10. data/Gemfile.lock +186 -97
  11. data/README.md +2 -3
  12. data/Rakefile +6 -1
  13. data/VERSION +1 -1
  14. data/acts-as-messageable.gemspec +193 -40
  15. data/bin/tapioca +29 -0
  16. data/docker-compose.yml +82 -71
  17. data/gemfiles/rails_3.2.gemfile +14 -9
  18. data/gemfiles/rails_4.2.gemfile +14 -9
  19. data/gemfiles/rails_5.2.gemfile +14 -9
  20. data/gemfiles/rails_6.0.gemfile +14 -9
  21. data/gemfiles/rails_7.0.gemfile +29 -0
  22. data/gemfiles/rails_master.gemfile +15 -9
  23. data/lib/acts-as-messageable.rb +1 -0
  24. data/lib/acts_as_messageable/message.rb +62 -5
  25. data/lib/acts_as_messageable/model.rb +71 -20
  26. data/lib/acts_as_messageable/rails3.rb +27 -2
  27. data/lib/acts_as_messageable/rails4.rb +31 -4
  28. data/lib/acts_as_messageable/rails6.rb +34 -2
  29. data/lib/acts_as_messageable/railtie.rb +1 -0
  30. data/lib/acts_as_messageable/relation.rb +18 -2
  31. data/lib/acts_as_messageable/scopes.rb +11 -0
  32. data/lib/acts_as_messageable.rb +18 -0
  33. data/lib/generators/acts_as_messageable/migration/migration_generator.rb +4 -0
  34. data/lib/generators/acts_as_messageable/migration/templates/migration.rb +1 -0
  35. data/lib/generators/acts_as_messageable/migration/templates/migration_indexes.rb +1 -0
  36. data/lib/generators/acts_as_messageable/migration/templates/migration_opened_as_datetime.rb +1 -0
  37. data/lib/generators/acts_as_messageable/migration/templates/migration_permanent.rb +1 -0
  38. data/sorbet/config +4 -0
  39. data/sorbet/rbi/annotations/actionpack.rbi +428 -0
  40. data/sorbet/rbi/annotations/actionview.rbi +77 -0
  41. data/sorbet/rbi/annotations/activerecord.rbi +18 -0
  42. data/sorbet/rbi/annotations/activesupport.rbi +52 -0
  43. data/sorbet/rbi/annotations/faraday.rbi +17 -0
  44. data/sorbet/rbi/annotations/railties.rbi +58 -0
  45. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  46. data/sorbet/rbi/dsl/abstract_controller/caching/fragments.rbi +23 -0
  47. data/sorbet/rbi/dsl/abstract_controller/caching.rbi +30 -0
  48. data/sorbet/rbi/dsl/abstract_controller/callbacks.rbi +23 -0
  49. data/sorbet/rbi/dsl/abstract_controller/helpers.rbi +23 -0
  50. data/sorbet/rbi/dsl/abstract_controller/rendering.rbi +9 -0
  51. data/sorbet/rbi/dsl/abstract_controller/url_for.rbi +23 -0
  52. data/sorbet/rbi/dsl/action_controller/caching.rbi +29 -0
  53. data/sorbet/rbi/dsl/action_controller/conditional_get.rbi +23 -0
  54. data/sorbet/rbi/dsl/action_controller/content_security_policy.rbi +31 -0
  55. data/sorbet/rbi/dsl/action_controller/data_streaming.rbi +9 -0
  56. data/sorbet/rbi/dsl/action_controller/etag_with_flash.rbi +24 -0
  57. data/sorbet/rbi/dsl/action_controller/etag_with_template_digest.rbi +30 -0
  58. data/sorbet/rbi/dsl/action_controller/flash.rbi +19 -0
  59. data/sorbet/rbi/dsl/action_controller/form_builder.rbi +19 -0
  60. data/sorbet/rbi/dsl/action_controller/helpers.rbi +36 -0
  61. data/sorbet/rbi/dsl/action_controller/params_wrapper.rbi +23 -0
  62. data/sorbet/rbi/dsl/action_controller/redirecting.rbi +24 -0
  63. data/sorbet/rbi/dsl/action_controller/renderers/all.rbi +24 -0
  64. data/sorbet/rbi/dsl/action_controller/renderers.rbi +23 -0
  65. data/sorbet/rbi/dsl/action_controller/request_forgery_protection.rbi +31 -0
  66. data/sorbet/rbi/dsl/action_controller/rescue.rbi +24 -0
  67. data/sorbet/rbi/dsl/action_controller/test_case/behavior.rbi +24 -0
  68. data/sorbet/rbi/dsl/action_controller/url_for.rbi +24 -0
  69. data/sorbet/rbi/dsl/action_dispatch/routing/url_for.rbi +23 -0
  70. data/sorbet/rbi/dsl/action_view/helpers/form_helper.rbi +10 -0
  71. data/sorbet/rbi/dsl/action_view/helpers/form_tag_helper.rbi +10 -0
  72. data/sorbet/rbi/dsl/action_view/helpers/text_helper.rbi +9 -0
  73. data/sorbet/rbi/dsl/action_view/helpers.rbi +10 -0
  74. data/sorbet/rbi/dsl/action_view/layouts.rbi +24 -0
  75. data/sorbet/rbi/dsl/action_view/rendering.rbi +9 -0
  76. data/sorbet/rbi/dsl/active_model/attribute_methods.rbi +27 -0
  77. data/sorbet/rbi/dsl/active_model/attributes.rbi +34 -0
  78. data/sorbet/rbi/dsl/active_model/dirty.rbi +28 -0
  79. data/sorbet/rbi/dsl/active_model/serializers/json.rbi +22 -0
  80. data/sorbet/rbi/dsl/active_model/validations/callbacks.rbi +22 -0
  81. data/sorbet/rbi/dsl/active_model/validations.rbi +27 -0
  82. data/sorbet/rbi/dsl/active_record/attribute_methods/dirty.rbi +38 -0
  83. data/sorbet/rbi/dsl/active_record/attribute_methods/time_zone_conversion.rbi +32 -0
  84. data/sorbet/rbi/dsl/active_record/attribute_methods.rbi +53 -0
  85. data/sorbet/rbi/dsl/active_record/attributes.rbi +19 -0
  86. data/sorbet/rbi/dsl/active_record/callbacks.rbi +22 -0
  87. data/sorbet/rbi/dsl/active_record/core.rbi +55 -0
  88. data/sorbet/rbi/dsl/active_record/encryption/encryptable_record.rbi +23 -0
  89. data/sorbet/rbi/dsl/active_record/inheritance.rbi +27 -0
  90. data/sorbet/rbi/dsl/active_record/integration.rbi +32 -0
  91. data/sorbet/rbi/dsl/active_record/locking/optimistic.rbi +22 -0
  92. data/sorbet/rbi/dsl/active_record/model_schema.rbi +52 -0
  93. data/sorbet/rbi/dsl/active_record/nested_attributes.rbi +22 -0
  94. data/sorbet/rbi/dsl/active_record/readonly_attributes.rbi +19 -0
  95. data/sorbet/rbi/dsl/active_record/reflection.rbi +32 -0
  96. data/sorbet/rbi/dsl/active_record/scoping/default.rbi +23 -0
  97. data/sorbet/rbi/dsl/active_record/scoping.rbi +23 -0
  98. data/sorbet/rbi/dsl/active_record/serialization.rbi +22 -0
  99. data/sorbet/rbi/dsl/active_record/signed_id.rbi +22 -0
  100. data/sorbet/rbi/dsl/active_record/test_fixtures.rbi +58 -0
  101. data/sorbet/rbi/dsl/active_record/timestamp.rbi +23 -0
  102. data/sorbet/rbi/dsl/active_record/validations.rbi +28 -0
  103. data/sorbet/rbi/dsl/active_support/actionable_error.rbi +23 -0
  104. data/sorbet/rbi/dsl/active_support/callbacks.rbi +22 -0
  105. data/sorbet/rbi/dsl/active_support/rescuable.rbi +23 -0
  106. data/sorbet/rbi/dsl/active_support/testing/file_fixtures.rbi +22 -0
  107. data/sorbet/rbi/gems/actionpack@7.0.4.3.rbi +19265 -0
  108. data/sorbet/rbi/gems/actionview@7.0.4.3.rbi +15482 -0
  109. data/sorbet/rbi/gems/activemodel@7.0.4.3.rbi +6025 -0
  110. data/sorbet/rbi/gems/activerecord@7.0.4.3.rbi +37852 -0
  111. data/sorbet/rbi/gems/activesupport@7.0.4.3.rbi +18788 -0
  112. data/sorbet/rbi/gems/addressable@2.4.0.rbi +8 -0
  113. data/sorbet/rbi/gems/appraisal@2.4.1.rbi +584 -0
  114. data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
  115. data/sorbet/rbi/gems/builder@3.2.4.rbi +8 -0
  116. data/sorbet/rbi/gems/coderay@1.1.3.rbi +3426 -0
  117. data/sorbet/rbi/gems/commander@4.6.0.rbi +8 -0
  118. data/sorbet/rbi/gems/concurrent-ruby@1.2.2.rbi +11545 -0
  119. data/sorbet/rbi/gems/coveralls_reborn@0.27.0.rbi +8 -0
  120. data/sorbet/rbi/gems/crass@1.0.6.rbi +622 -0
  121. data/sorbet/rbi/gems/descendants_tracker@0.0.4.rbi +8 -0
  122. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1079 -0
  123. data/sorbet/rbi/gems/docile@1.4.0.rbi +8 -0
  124. data/sorbet/rbi/gems/erubi@1.12.0.rbi +146 -0
  125. data/sorbet/rbi/gems/faraday@0.9.2.rbi +964 -0
  126. data/sorbet/rbi/gems/git@1.11.0.rbi +2700 -0
  127. data/sorbet/rbi/gems/github_api@0.16.0.rbi +8 -0
  128. data/sorbet/rbi/gems/hashie@5.0.0.rbi +8 -0
  129. data/sorbet/rbi/gems/highline@2.0.3.rbi +8 -0
  130. data/sorbet/rbi/gems/i18n@1.12.0.rbi +2296 -0
  131. data/sorbet/rbi/gems/jeweler@2.3.9.rbi +1591 -0
  132. data/sorbet/rbi/gems/json@2.6.3.rbi +1541 -0
  133. data/sorbet/rbi/gems/jwt@2.5.0.rbi +8 -0
  134. data/sorbet/rbi/gems/loofah@2.19.1.rbi +904 -0
  135. data/sorbet/rbi/gems/method_source@1.0.0.rbi +272 -0
  136. data/sorbet/rbi/gems/mime-types@2.99.3.rbi +8 -0
  137. data/sorbet/rbi/gems/minitest@5.18.0.rbi +1491 -0
  138. data/sorbet/rbi/gems/multi_json@1.15.0.rbi +8 -0
  139. data/sorbet/rbi/gems/multi_xml@0.6.0.rbi +8 -0
  140. data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +8 -0
  141. data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
  142. data/sorbet/rbi/gems/nokogiri@1.14.2.rbi +7244 -0
  143. data/sorbet/rbi/gems/oauth2@1.4.8.rbi +8 -0
  144. data/sorbet/rbi/gems/parallel@1.22.1.rbi +277 -0
  145. data/sorbet/rbi/gems/pg@1.4.6.rbi +2574 -0
  146. data/sorbet/rbi/gems/polyfill@1.9.0.rbi +8 -0
  147. data/sorbet/rbi/gems/pry@0.14.2.rbi +10081 -0
  148. data/sorbet/rbi/gems/psych@4.0.6.rbi +1819 -0
  149. data/sorbet/rbi/gems/racc@1.6.2.rbi +155 -0
  150. data/sorbet/rbi/gems/rack-test@2.0.2.rbi +943 -0
  151. data/sorbet/rbi/gems/rack@2.2.6.4.rbi +5659 -0
  152. data/sorbet/rbi/gems/rails-dom-testing@2.0.3.rbi +455 -0
  153. data/sorbet/rbi/gems/rails-html-sanitizer@1.5.0.rbi +685 -0
  154. data/sorbet/rbi/gems/railties@7.0.4.3.rbi +4553 -0
  155. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +8 -0
  156. data/sorbet/rbi/gems/rake@13.0.6.rbi +2959 -0
  157. data/sorbet/rbi/gems/rbi@0.0.16.rbi +3008 -0
  158. data/sorbet/rbi/gems/rbs@2.8.0.rbi +8 -0
  159. data/sorbet/rbi/gems/rchardet@1.8.0.rbi +1078 -0
  160. data/sorbet/rbi/gems/rdoc@6.5.0.rbi +12441 -0
  161. data/sorbet/rbi/gems/regexp_parser@2.7.0.rbi +8 -0
  162. data/sorbet/rbi/gems/rexml@3.2.5.rbi +8 -0
  163. data/sorbet/rbi/gems/rspec-core@3.12.0.rbi +10798 -0
  164. data/sorbet/rbi/gems/rspec-expectations@3.12.0.rbi +8090 -0
  165. data/sorbet/rbi/gems/rspec-mocks@3.12.0.rbi +5296 -0
  166. data/sorbet/rbi/gems/rspec-support@3.12.0.rbi +1617 -0
  167. data/sorbet/rbi/gems/rspec@3.12.0.rbi +88 -0
  168. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +8 -0
  169. data/sorbet/rbi/gems/safe_type@1.1.1.rbi +8 -0
  170. data/sorbet/rbi/gems/semver2@3.4.2.rbi +8 -0
  171. data/sorbet/rbi/gems/simplecov-html@0.12.3.rbi +8 -0
  172. data/sorbet/rbi/gems/simplecov@0.22.0.rbi +8 -0
  173. data/sorbet/rbi/gems/simplecov_json_formatter@0.1.4.rbi +8 -0
  174. data/sorbet/rbi/gems/sorbet-coerce@0.7.0.rbi +8 -0
  175. data/sorbet/rbi/gems/stringio@3.0.2.rbi +8 -0
  176. data/sorbet/rbi/gems/sync@0.5.0.rbi +8 -0
  177. data/sorbet/rbi/gems/term-ansicolor@1.7.1.rbi +8 -0
  178. data/sorbet/rbi/gems/thor@1.2.1.rbi +3956 -0
  179. data/sorbet/rbi/gems/thread_safe@0.3.6.rbi +8 -0
  180. data/sorbet/rbi/gems/timecop@0.9.6.rbi +361 -0
  181. data/sorbet/rbi/gems/tins@1.32.1.rbi +8 -0
  182. data/sorbet/rbi/gems/tzinfo@2.0.6.rbi +5917 -0
  183. data/sorbet/rbi/gems/unicode-display_width@2.4.2.rbi +8 -0
  184. data/sorbet/rbi/gems/unparser@0.6.7.rbi +4515 -0
  185. data/sorbet/rbi/gems/webrick@1.7.0.rbi +2553 -0
  186. data/sorbet/rbi/gems/yard@0.9.28.rbi +17954 -0
  187. data/sorbet/rbi/gems/zeitwerk@2.6.7.rbi +966 -0
  188. data/sorbet/rbi/models/acts-as-messageable/message.rbi +668 -0
  189. data/sorbet/rbi/models/acts-as-messageable/user.rbi +343 -0
  190. data/sorbet/rbi/rails-rbi/active_record_base.rbi +119 -0
  191. data/sorbet/rbi/rails-rbi/active_record_relation.rbi +180 -0
  192. data/sorbet/rbi/shims/activerecord.rbi +4 -0
  193. data/sorbet/rbi/shims/model.rbi +9 -0
  194. data/sorbet/tapioca/config.yml +10 -0
  195. data/sorbet/tapioca/pre_require.rb +5 -0
  196. data/sorbet/tapioca/require.rb +10 -0
  197. data/spec/acts_as_messageable_spec.rb +7 -4
  198. data/spec/custom_class_spec.rb +1 -0
  199. data/spec/custom_required_spec.rb +8 -4
  200. data/spec/group_messages_spec.rb +1 -0
  201. data/spec/migrations_spec.rb +2 -1
  202. data/spec/spec_helper.rb +19 -9
  203. data/spec/support/admin.rb +3 -0
  204. data/spec/support/custom_message.rb +3 -0
  205. data/spec/support/custom_message_uuid.rb +1 -0
  206. data/spec/support/custom_search_user.rb +3 -0
  207. data/spec/support/men.rb +1 -0
  208. data/spec/support/send_message.rb +8 -1
  209. data/spec/support/table_schema.rb +7 -6
  210. data/spec/support/user.rb +3 -0
  211. data/spec/support/uuid_user.rb +3 -0
  212. data/tasks/types.rake +46 -0
  213. metadata +261 -11
  214. data/.travis.yml +0 -55
@@ -0,0 +1,584 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `ast` gem.
5
+ # Please instead update this file by running `bin/tapioca gem ast`.
6
+
7
+ # {AST} is a library for manipulating abstract syntax trees.
8
+ #
9
+ # It embraces immutability; each AST node is inherently frozen at
10
+ # creation, and updating a child node requires recreating that node
11
+ # and its every parent, recursively.
12
+ # This is a design choice. It does create some pressure on
13
+ # garbage collector, but completely eliminates all concurrency
14
+ # and aliasing problems.
15
+ #
16
+ # See also {AST::Node}, {AST::Processor::Mixin} and {AST::Sexp} for
17
+ # additional recommendations and design patterns.
18
+ #
19
+ # source://ast//lib/ast.rb#13
20
+ module AST; end
21
+
22
+ # Node is an immutable class, instances of which represent abstract
23
+ # syntax tree nodes. It combines semantic information (i.e. anything
24
+ # that affects the algorithmic properties of a program) with
25
+ # meta-information (line numbers or compiler intermediates).
26
+ #
27
+ # Notes on inheritance
28
+ # ====================
29
+ #
30
+ # The distinction between semantics and metadata is important. Complete
31
+ # semantic information should be contained within just the {#type} and
32
+ # {#children} of a Node instance; in other words, if an AST was to be
33
+ # stripped of all meta-information, it should remain a valid AST which
34
+ # could be successfully processed to yield a result with the same
35
+ # algorithmic properties.
36
+ #
37
+ # Thus, Node should never be inherited in order to define methods which
38
+ # affect or return semantic information, such as getters for `class_name`,
39
+ # `superclass` and `body` in the case of a hypothetical `ClassNode`. The
40
+ # correct solution is to use a generic Node with a {#type} of `:class`
41
+ # and three children. See also {Processor} for tips on working with such
42
+ # ASTs.
43
+ #
44
+ # On the other hand, Node can and should be inherited to define
45
+ # application-specific metadata (see also {#initialize}) or customize the
46
+ # printing format. It is expected that an application would have one or two
47
+ # such classes and use them across the entire codebase.
48
+ #
49
+ # The rationale for this pattern is extensibility and maintainability.
50
+ # Unlike static ones, dynamic languages do not require the presence of a
51
+ # predefined, rigid structure, nor does it improve dispatch efficiency,
52
+ # and while such a structure can certainly be defined, it does not add
53
+ # any value but incurs a maintaining cost.
54
+ # For example, extending the AST even with a transformation-local
55
+ # temporary node type requires making globally visible changes to
56
+ # the codebase.
57
+ #
58
+ # source://ast//lib/ast/node.rb#40
59
+ class AST::Node
60
+ # Constructs a new instance of Node.
61
+ #
62
+ # The arguments `type` and `children` are converted with `to_sym` and
63
+ # `to_a` respectively. Additionally, the result of converting `children`
64
+ # is frozen. While mutating the arguments is generally considered harmful,
65
+ # the most common case is to pass an array literal to the constructor. If
66
+ # your code does not expect the argument to be frozen, use `#dup`.
67
+ #
68
+ # The `properties` hash is passed to {#assign_properties}.
69
+ #
70
+ # @return [Node] a new instance of Node
71
+ #
72
+ # source://ast//lib/ast/node.rb#72
73
+ def initialize(type, children = T.unsafe(nil), properties = T.unsafe(nil)); end
74
+
75
+ # Concatenates `array` with `children` and returns the resulting node.
76
+ #
77
+ # @return [AST::Node]
78
+ #
79
+ # source://ast//lib/ast/node.rb#168
80
+ def +(array); end
81
+
82
+ # Appends `element` to `children` and returns the resulting node.
83
+ #
84
+ # @return [AST::Node]
85
+ #
86
+ # source://ast//lib/ast/node.rb#177
87
+ def <<(element); end
88
+
89
+ # Compares `self` to `other`, possibly converting with `to_ast`. Only
90
+ # `type` and `children` are compared; metadata is deliberately ignored.
91
+ #
92
+ # @return [Boolean]
93
+ #
94
+ # source://ast//lib/ast/node.rb#153
95
+ def ==(other); end
96
+
97
+ # Appends `element` to `children` and returns the resulting node.
98
+ #
99
+ # @return [AST::Node]
100
+ #
101
+ # source://ast//lib/ast/node.rb#177
102
+ def append(element); end
103
+
104
+ # Returns the children of this node.
105
+ # The returned value is frozen.
106
+ # The to_a alias is useful for decomposing nodes concisely.
107
+ # For example:
108
+ #
109
+ # node = s(:gasgn, :$foo, s(:integer, 1))
110
+ # var_name, value = *node
111
+ # p var_name # => :$foo
112
+ # p value # => (integer 1)
113
+ #
114
+ # @return [Array]
115
+ #
116
+ # source://ast//lib/ast/node.rb#56
117
+ def children; end
118
+
119
+ # Nodes are already frozen, so there is no harm in returning the
120
+ # current node as opposed to initializing from scratch and freezing
121
+ # another one.
122
+ #
123
+ # @return self
124
+ #
125
+ # source://ast//lib/ast/node.rb#115
126
+ def clone; end
127
+
128
+ # Concatenates `array` with `children` and returns the resulting node.
129
+ #
130
+ # @return [AST::Node]
131
+ #
132
+ # source://ast//lib/ast/node.rb#168
133
+ def concat(array); end
134
+
135
+ # Enables matching for Node, where type is the first element
136
+ # and the children are remaining items.
137
+ #
138
+ # @return [Array]
139
+ #
140
+ # source://ast//lib/ast/node.rb#253
141
+ def deconstruct; end
142
+
143
+ # Nodes are already frozen, so there is no harm in returning the
144
+ # current node as opposed to initializing from scratch and freezing
145
+ # another one.
146
+ #
147
+ # @return self
148
+ #
149
+ # source://ast//lib/ast/node.rb#115
150
+ def dup; end
151
+
152
+ # Test if other object is equal to
153
+ #
154
+ # @param other [Object]
155
+ # @return [Boolean]
156
+ #
157
+ # source://ast//lib/ast/node.rb#85
158
+ def eql?(other); end
159
+
160
+ # Returns the precomputed hash value for this node
161
+ #
162
+ # @return [Fixnum]
163
+ #
164
+ # source://ast//lib/ast/node.rb#61
165
+ def hash; end
166
+
167
+ # Converts `self` to a s-expression ruby string.
168
+ # The code return will recreate the node, using the sexp module s()
169
+ #
170
+ # @param indent [Integer] Base indentation level.
171
+ # @return [String]
172
+ #
173
+ # source://ast//lib/ast/node.rb#211
174
+ def inspect(indent = T.unsafe(nil)); end
175
+
176
+ # Returns the children of this node.
177
+ # The returned value is frozen.
178
+ # The to_a alias is useful for decomposing nodes concisely.
179
+ # For example:
180
+ #
181
+ # node = s(:gasgn, :$foo, s(:integer, 1))
182
+ # var_name, value = *node
183
+ # p var_name # => :$foo
184
+ # p value # => (integer 1)
185
+ #
186
+ # @return [Array]
187
+ #
188
+ # source://ast//lib/ast/node.rb#56
189
+ def to_a; end
190
+
191
+ # @return [AST::Node] self
192
+ #
193
+ # source://ast//lib/ast/node.rb#229
194
+ def to_ast; end
195
+
196
+ # Converts `self` to a pretty-printed s-expression.
197
+ #
198
+ # @param indent [Integer] Base indentation level.
199
+ # @return [String]
200
+ #
201
+ # source://ast//lib/ast/node.rb#187
202
+ def to_s(indent = T.unsafe(nil)); end
203
+
204
+ # Converts `self` to a pretty-printed s-expression.
205
+ #
206
+ # @param indent [Integer] Base indentation level.
207
+ # @return [String]
208
+ #
209
+ # source://ast//lib/ast/node.rb#187
210
+ def to_sexp(indent = T.unsafe(nil)); end
211
+
212
+ # Converts `self` to an Array where the first element is the type as a Symbol,
213
+ # and subsequent elements are the same representation of its children.
214
+ #
215
+ # @return [Array<Symbol, [...Array]>]
216
+ #
217
+ # source://ast//lib/ast/node.rb#237
218
+ def to_sexp_array; end
219
+
220
+ # Returns the type of this node.
221
+ #
222
+ # @return [Symbol]
223
+ #
224
+ # source://ast//lib/ast/node.rb#43
225
+ def type; end
226
+
227
+ # Returns a new instance of Node where non-nil arguments replace the
228
+ # corresponding fields of `self`.
229
+ #
230
+ # For example, `Node.new(:foo, [ 1, 2 ]).updated(:bar)` would yield
231
+ # `(bar 1 2)`, and `Node.new(:foo, [ 1, 2 ]).updated(nil, [])` would
232
+ # yield `(foo)`.
233
+ #
234
+ # If the resulting node would be identical to `self`, does nothing.
235
+ #
236
+ # @param type [Symbol, nil]
237
+ # @param children [Array, nil]
238
+ # @param properties [Hash, nil]
239
+ # @return [AST::Node]
240
+ #
241
+ # source://ast//lib/ast/node.rb#133
242
+ def updated(type = T.unsafe(nil), children = T.unsafe(nil), properties = T.unsafe(nil)); end
243
+
244
+ protected
245
+
246
+ # By default, each entry in the `properties` hash is assigned to
247
+ # an instance variable in this instance of Node. A subclass should define
248
+ # attribute readers for such variables. The values passed in the hash
249
+ # are not frozen or whitelisted; such behavior can also be implemented
250
+ # by subclassing Node and overriding this method.
251
+ #
252
+ # @return [nil]
253
+ #
254
+ # source://ast//lib/ast/node.rb#98
255
+ def assign_properties(properties); end
256
+
257
+ # Returns `@type` with all underscores replaced by dashes. This allows
258
+ # to write symbol literals without quotes in Ruby sources and yet have
259
+ # nicely looking s-expressions.
260
+ #
261
+ # @return [String]
262
+ #
263
+ # source://ast//lib/ast/node.rb#264
264
+ def fancy_type; end
265
+
266
+ private
267
+
268
+ def original_dup; end
269
+ end
270
+
271
+ # This class includes {AST::Processor::Mixin}; however, it is
272
+ # deprecated, since the module defines all of the behaviors that
273
+ # the processor includes. Any new libraries should use
274
+ # {AST::Processor::Mixin} instead of subclassing this.
275
+ #
276
+ # @deprecated Use {AST::Processor::Mixin} instead.
277
+ #
278
+ # source://ast//lib/ast/processor.rb#8
279
+ class AST::Processor
280
+ include ::AST::Processor::Mixin
281
+ end
282
+
283
+ # The processor module is a module which helps transforming one
284
+ # AST into another. In a nutshell, the {#process} method accepts
285
+ # a {Node} and dispatches it to a handler corresponding to its
286
+ # type, and returns a (possibly) updated variant of the node.
287
+ #
288
+ # The processor module has a set of associated design patterns.
289
+ # They are best explained with a concrete example. Let's define a
290
+ # simple arithmetic language and an AST format for it:
291
+ #
292
+ # Terminals (AST nodes which do not have other AST nodes inside):
293
+ #
294
+ # * `(integer <int-literal>)`,
295
+ #
296
+ # Nonterminals (AST nodes with other nodes as children):
297
+ #
298
+ # * `(add <node> <node>)`,
299
+ # * `(multiply <node> <node>)`,
300
+ # * `(divide <node> <node>)`,
301
+ # * `(negate <node>)`,
302
+ # * `(store <node> <string-literal>)`: stores value of `<node>`
303
+ # into a variable named `<string-literal>`,
304
+ # * `(load <string-literal>)`: loads value of a variable named
305
+ # `<string-literal>`,
306
+ # * `(each <node> ...)`: computes each of the `<node>`s and
307
+ # prints the result.
308
+ #
309
+ # All AST nodes have the same Ruby class, and therefore they don't
310
+ # know how to traverse themselves. (A solution which dynamically
311
+ # checks the type of children is possible, but is slow and
312
+ # error-prone.) So, a class including the module which knows how
313
+ # to traverse the entire tree should be defined. Such classes
314
+ # have a handler for each nonterminal node which recursively
315
+ # processes children nodes:
316
+ #
317
+ # require 'ast'
318
+ #
319
+ # class ArithmeticsProcessor
320
+ # include AST::Processor::Mixin
321
+ # # This method traverses any binary operators such as (add)
322
+ # # or (multiply).
323
+ # def process_binary_op(node)
324
+ # # Children aren't decomposed automatically; it is
325
+ # # suggested to use Ruby multiple assignment expansion,
326
+ # # as it is very convenient here.
327
+ # left_expr, right_expr = *node
328
+ #
329
+ # # AST::Node#updated won't change node type if nil is
330
+ # # passed as a first argument, which allows to reuse the
331
+ # # same handler for multiple node types using `alias'
332
+ # # (below).
333
+ # node.updated(nil, [
334
+ # process(left_expr),
335
+ # process(right_expr)
336
+ # ])
337
+ # end
338
+ # alias_method :on_add, :process_binary_op
339
+ # alias_method :on_multiply, :process_binary_op
340
+ # alias_method :on_divide, :process_binary_op
341
+ #
342
+ # def on_negate(node)
343
+ # # It is also possible to use #process_all for more
344
+ # # compact code if every child is a Node.
345
+ # node.updated(nil, process_all(node))
346
+ # end
347
+ #
348
+ # def on_store(node)
349
+ # expr, variable_name = *node
350
+ #
351
+ # # Note that variable_name is not a Node and thus isn't
352
+ # # passed to #process.
353
+ # node.updated(nil, [
354
+ # process(expr),
355
+ # variable_name
356
+ # ])
357
+ # end
358
+ #
359
+ # # (load) is effectively a terminal node, and so it does
360
+ # # not need an explicit handler, as the following is the
361
+ # # default behavior. Essentially, for any nodes that don't
362
+ # # have a defined handler, the node remains unchanged.
363
+ # def on_load(node)
364
+ # nil
365
+ # end
366
+ #
367
+ # def on_each(node)
368
+ # node.updated(nil, process_all(node))
369
+ # end
370
+ # end
371
+ #
372
+ # Let's test our ArithmeticsProcessor:
373
+ #
374
+ # include AST::Sexp
375
+ # expr = s(:add, s(:integer, 2), s(:integer, 2))
376
+ #
377
+ # p ArithmeticsProcessor.new.process(expr) == expr # => true
378
+ #
379
+ # As expected, it does not change anything at all. This isn't
380
+ # actually very useful, so let's now define a Calculator, which
381
+ # will compute the expression values:
382
+ #
383
+ # # This Processor folds nonterminal nodes and returns an
384
+ # # (integer) terminal node.
385
+ # class ArithmeticsCalculator < ArithmeticsProcessor
386
+ # def compute_op(node)
387
+ # # First, node children are processed and then unpacked
388
+ # # to local variables.
389
+ # nodes = process_all(node)
390
+ #
391
+ # if nodes.all? { |node| node.type == :integer }
392
+ # # If each of those nodes represents a literal, we can
393
+ # # fold this node!
394
+ # values = nodes.map { |node| node.children.first }
395
+ # AST::Node.new(:integer, [
396
+ # yield(values)
397
+ # ])
398
+ # else
399
+ # # Otherwise, we can just leave the current node in the
400
+ # # tree and only update it with processed children
401
+ # # nodes, which can be partially folded.
402
+ # node.updated(nil, nodes)
403
+ # end
404
+ # end
405
+ #
406
+ # def on_add(node)
407
+ # compute_op(node) { |left, right| left + right }
408
+ # end
409
+ #
410
+ # def on_multiply(node)
411
+ # compute_op(node) { |left, right| left * right }
412
+ # end
413
+ # end
414
+ #
415
+ # Let's check:
416
+ #
417
+ # p ArithmeticsCalculator.new.process(expr) # => (integer 4)
418
+ #
419
+ # Excellent, the calculator works! Now, a careful reader could
420
+ # notice that the ArithmeticsCalculator does not know how to
421
+ # divide numbers. What if we pass an expression with division to
422
+ # it?
423
+ #
424
+ # expr_with_division = \
425
+ # s(:add,
426
+ # s(:integer, 1),
427
+ # s(:divide,
428
+ # s(:add, s(:integer, 8), s(:integer, 4)),
429
+ # s(:integer, 3))) # 1 + (8 + 4) / 3
430
+ #
431
+ # folded_expr_with_division = ArithmeticsCalculator.new.process(expr_with_division)
432
+ # p folded_expr_with_division
433
+ # # => (add
434
+ # # (integer 1)
435
+ # # (divide
436
+ # # (integer 12)
437
+ # # (integer 3)))
438
+ #
439
+ # As you can see, the expression was folded _partially_: the inner
440
+ # `(add)` node which could be computed was folded to
441
+ # `(integer 12)`, the `(divide)` node is left as-is because there
442
+ # is no computing handler for it, and the root `(add)` node was
443
+ # also left as it is because some of its children were not
444
+ # literals.
445
+ #
446
+ # Note that this partial folding is only possible because the
447
+ # _data_ format, i.e. the format in which the computed values of
448
+ # the nodes are represented, is the same as the AST itself.
449
+ #
450
+ # Let's extend our ArithmeticsCalculator class further.
451
+ #
452
+ # class ArithmeticsCalculator
453
+ # def on_divide(node)
454
+ # compute_op(node) { |left, right| left / right }
455
+ # end
456
+ #
457
+ # def on_negate(node)
458
+ # # Note how #compute_op works regardless of the operator
459
+ # # arity.
460
+ # compute_op(node) { |value| -value }
461
+ # end
462
+ # end
463
+ #
464
+ # Now, let's apply our renewed ArithmeticsCalculator to a partial
465
+ # result of previous evaluation:
466
+ #
467
+ # p ArithmeticsCalculator.new.process(expr_with_division) # => (integer 5)
468
+ #
469
+ # Five! Excellent. This is also pretty much how CRuby 1.8 executed
470
+ # its programs.
471
+ #
472
+ # Now, let's do some automated bug searching. Division by zero is
473
+ # an error, right? So if we could detect that someone has divided
474
+ # by zero before the program is even run, that could save some
475
+ # debugging time.
476
+ #
477
+ # class DivisionByZeroVerifier < ArithmeticsProcessor
478
+ # class VerificationFailure < Exception; end
479
+ #
480
+ # def on_divide(node)
481
+ # # You need to process the children to handle nested divisions
482
+ # # such as:
483
+ # # (divide
484
+ # # (integer 1)
485
+ # # (divide (integer 1) (integer 0))
486
+ # left, right = process_all(node)
487
+ #
488
+ # if right.type == :integer &&
489
+ # right.children.first == 0
490
+ # raise VerificationFailure, "Ouch! This code divides by zero."
491
+ # end
492
+ # end
493
+ #
494
+ # def divides_by_zero?(ast)
495
+ # process(ast)
496
+ # false
497
+ # rescue VerificationFailure
498
+ # true
499
+ # end
500
+ # end
501
+ #
502
+ # nice_expr = \
503
+ # s(:divide,
504
+ # s(:add, s(:integer, 10), s(:integer, 2)),
505
+ # s(:integer, 4))
506
+ #
507
+ # p DivisionByZeroVerifier.new.divides_by_zero?(nice_expr)
508
+ # # => false. Good.
509
+ #
510
+ # bad_expr = \
511
+ # s(:add, s(:integer, 10),
512
+ # s(:divide, s(:integer, 1), s(:integer, 0)))
513
+ #
514
+ # p DivisionByZeroVerifier.new.divides_by_zero?(bad_expr)
515
+ # # => true. WHOOPS. DO NOT RUN THIS.
516
+ #
517
+ # Of course, this won't detect more complex cases... unless you
518
+ # use some partial evaluation before! The possibilites are
519
+ # endless. Have fun.
520
+ #
521
+ # source://ast//lib/ast/processor/mixin.rb#240
522
+ module AST::Processor::Mixin
523
+ # Default handler. Does nothing.
524
+ #
525
+ # @param node [AST::Node]
526
+ # @return [AST::Node, nil]
527
+ #
528
+ # source://ast//lib/ast/processor/mixin.rb#284
529
+ def handler_missing(node); end
530
+
531
+ # Dispatches `node`. If a node has type `:foo`, then a handler
532
+ # named `on_foo` is invoked with one argument, the `node`; if
533
+ # there isn't such a handler, {#handler_missing} is invoked
534
+ # with the same argument.
535
+ #
536
+ # If the handler returns `nil`, `node` is returned; otherwise,
537
+ # the return value of the handler is passed along.
538
+ #
539
+ # @param node [AST::Node, nil]
540
+ # @return [AST::Node, nil]
541
+ #
542
+ # source://ast//lib/ast/processor/mixin.rb#251
543
+ def process(node); end
544
+
545
+ # {#process}es each node from `nodes` and returns an array of
546
+ # results.
547
+ #
548
+ # @param nodes [Array<AST::Node>]
549
+ # @return [Array<AST::Node>]
550
+ #
551
+ # source://ast//lib/ast/processor/mixin.rb#274
552
+ def process_all(nodes); end
553
+ end
554
+
555
+ # This simple module is very useful in the cases where one needs
556
+ # to define deeply nested ASTs from Ruby code, for example, in
557
+ # tests. It should be used like this:
558
+ #
559
+ # describe YourLanguage::AST do
560
+ # include Sexp
561
+ #
562
+ # it "should correctly parse expressions" do
563
+ # YourLanguage.parse("1 + 2 * 3").should ==
564
+ # s(:add,
565
+ # s(:integer, 1),
566
+ # s(:multiply,
567
+ # s(:integer, 2),
568
+ # s(:integer, 3)))
569
+ # end
570
+ # end
571
+ #
572
+ # This way the amount of boilerplate code is greatly reduced.
573
+ #
574
+ # source://ast//lib/ast/sexp.rb#20
575
+ module AST::Sexp
576
+ # Creates a {Node} with type `type` and children `children`.
577
+ # Note that the resulting node is of the type AST::Node and not a
578
+ # subclass.
579
+ # This would not pose a problem with comparisons, as {Node#==}
580
+ # ignores metadata.
581
+ #
582
+ # source://ast//lib/ast/sexp.rb#26
583
+ def s(type, *children); end
584
+ end
@@ -0,0 +1,8 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `builder` gem.
5
+ # Please instead update this file by running `bin/tapioca gem builder`.
6
+
7
+ # THIS IS AN EMPTY RBI FILE.
8
+ # see https://github.com/Shopify/tapioca#manually-requiring-parts-of-a-gem