sord 0.5.0 → 0.6.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: 9a20a16fb8b21d103c934ed6f4846db387ab40174ebe9468b33ec70b82c8c883
4
- data.tar.gz: 235f786ea4950554c1c78a9887c40218efdb1cafdf2b281ca5d923af2130eaf5
3
+ metadata.gz: 5de7160886a2e2fd6df02d245102315d772029a951075d885a88ac253ed1ea0a
4
+ data.tar.gz: a14f5c19796cfd9033111c76ef144541a3dd9304d1421341fcb3fb9e9f1e65f3
5
5
  SHA512:
6
- metadata.gz: e4c45eef8d708353b0a1817b273c7a548799fed3380e5ad76a0744e6c51b02d9b5d139e31a9aac49bfafc9936a4cecf8f0098a9911b2cda556b9c8456bb3cde9
7
- data.tar.gz: 47f885d8222de2169f987e603cc46b949475046439a7d7e7e312ecb09e9d1510459a59e1621622e967d185b5855cdd5face4a984cf825a1a17256e7ed0876186
6
+ metadata.gz: 3ec7636f302c059c5a1fe826cfa077c786410b1d3378783feac63ce77a7600df516fc1f1794f869996d0aa64f13de2a42eceda806d7378efece157c0254a58a6
7
+ data.tar.gz: 208a0d864121ca13eeeb2c5713cd98768e4710dc9cf2bdacb9fd13471e97e2dc580f9b31530dee847b4de8e9d62072f1a1cef640c4f768f4537754058ad253c3
data/README.md CHANGED
@@ -111,19 +111,6 @@ The general rule of thumb for type conversions is:
111
111
  You should search through your resulting RBI to find and fix and
112
112
  `SORD_ERROR`s.
113
113
 
114
- ## Things to work on
115
-
116
- - No support whatsoever for blocks (they appear to cause syntax errors in RBI
117
- currently)
118
- - I'm not 100% sure how this handles undocumented methods and classes.
119
- - More inference systems would be nice.
120
- - This won't generate type parameter definitions for things which mix-in
121
- `Enumerable`.
122
- - Module scoping is an issue - if `Example::Person` is replaced with `Person`
123
- in the YARD comments in the above example, Sorbet won't be able to resolve
124
- it. _This can be solved by making definitions syntactically heirarchical._
125
- - Tests!!
126
-
127
114
  ## Contributing
128
115
 
129
116
  Bug reports and pull requests are welcome on GitHub at https://github.com/AaronC81/sord. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/lib/sord/logging.rb CHANGED
@@ -61,7 +61,7 @@ module Sord
61
61
  # is associated with, if any. This is shown before the log message if it is
62
62
  # specified.
63
63
  def self.duck(msg, item=nil)
64
- generic(:ducl, '[DUCK ]'.cyan, msg, item)
64
+ generic(:duck, '[DUCK ]'.cyan, msg, item)
65
65
  end
66
66
 
67
67
  # Print an error message. This should be used for things which require the
@@ -128,4 +128,4 @@ module Sord
128
128
  @@hooks << blk
129
129
  end
130
130
  end
131
- end
131
+ end
@@ -132,6 +132,26 @@ module Sord
132
132
  end
133
133
  end
134
134
 
135
+ # Given a YARD NamespaceObject, add lines defining its mixins, methods
136
+ # and children to the RBI file.
137
+ # @param [YARD::CodeObjects::NamespaceObject] item
138
+ def add_namespace(item)
139
+ count_object
140
+
141
+ if item.type == :class && item.superclass.to_s != "Object"
142
+ rbi_contents << "class #{item.name} < #{item.superclass.path}"
143
+ else
144
+ rbi_contents << "#{item.type} #{item.name}"
145
+ end
146
+ add_mixins(item)
147
+ add_methods(item)
148
+
149
+ item.children.select { |x| [:class, :module].include?(x.type) }
150
+ .each { |child| add_namespace(child) }
151
+
152
+ rbi_contents << "end"
153
+ end
154
+
135
155
  # Generates the RBI file and writes it to the given file path.
136
156
  # @param [String] filename
137
157
  # @return [void]
@@ -143,26 +163,10 @@ module Sord
143
163
 
144
164
  # TODO: constants?
145
165
 
146
- # Populate the RBI with modules first
147
- YARD::Registry.all(:module).each do |item|
148
- count_object
149
-
150
- rbi_contents << "module #{item.path}"
151
- add_mixins(item)
152
- add_methods(item)
153
- rbi_contents << "end"
154
- end
155
-
156
- # Now populate with classes
157
- YARD::Registry.all(:class).each do |item|
158
- count_object
159
-
160
- superclass = (item.superclass if item.superclass.to_s != "Object")
161
- rbi_contents << "class #{item.path} #{"< #{superclass}" if superclass}"
162
- add_mixins(item)
163
- add_methods(item)
164
- rbi_contents << "end"
165
- end
166
+ # Generate top-level modules, which recurses to all modules
167
+ YARD::Registry.root.children
168
+ .select { |x| [:class, :module].include?(x.type) }
169
+ .each { |child| add_namespace(child) }
166
170
 
167
171
  # Write the file
168
172
  File.write(filename, rbi_contents.join(?\n))
data/lib/sord/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # typed: strong
2
2
  module Sord
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Christiansen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-22 00:00:00.000000000 Z
11
+ date: 2019-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard