yard-link_stdlib 0.1.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.
@@ -0,0 +1,233 @@
1
+ # frozen_string_literal: true
2
+ # encoding: UTF-8
3
+
4
+
5
+ # Namespace
6
+ # ========================================================================
7
+
8
+ module YARD
9
+ module LinkStdlib
10
+
11
+
12
+ # Definitions
13
+ # ========================================================================
14
+
15
+
16
+ # Handling which version of Ruby to link against.
17
+ #
18
+ module RubyVersion
19
+
20
+ # Constants
21
+ # ----------------------------------------------------------------------------
22
+
23
+ # Support for 2.2.X ended March 28, 2017. 2.3 is scheduled to go March 2019.
24
+ #
25
+ # https://www.ruby-lang.org/en/news/2018/06/20/support-of-ruby-2-2-has-ended/
26
+ #
27
+ # @return [Gem::Version]
28
+ #
29
+ MINIMUM_SUPPORTED = Gem::Version.new '2.3.0'
30
+
31
+
32
+ # As of 2018.09.23, the latest stable release
33
+ #
34
+ # @return [Gem::Version]
35
+ #
36
+ LATEST_STABLE = Gem::Version.new '2.5.1'
37
+
38
+
39
+ # Whatever version we're running here and now.
40
+ #
41
+ # @return [Gem::Version]
42
+ #
43
+ CURRENT_RUNTIME = Gem::Version.new RUBY_VERSION
44
+
45
+
46
+ # If no-one tells us different then use the minimum supported Ruby version.
47
+ #
48
+ # @return [Symbol]
49
+ #
50
+ DEFAULT_FALLBACK_MODE = :minimum_supported
51
+
52
+
53
+ # Class Methods
54
+ # ========================================================================
55
+
56
+ # Set what version of Ruby to link to.
57
+ #
58
+ # @param [#to_s] version
59
+ # Something that's string representation is the version you want to set.
60
+ #
61
+ # Note that {Gem::Version} works fine here 'cause it's string rep is the
62
+ # version string, effectively meaning a frozen copy of it is stored.
63
+ #
64
+ # @return [Gem::Version]
65
+ # The newly set value. Is frozen.
66
+ #
67
+ def self.set version
68
+ @ruby_version = Gem::Version.new version
69
+ end
70
+
71
+
72
+ # Get what version of Ruby is set to link to.
73
+ #
74
+ # @return [Gem::Version]
75
+ # Returns the actual in`stance var reference, but it's frozen, so it should
76
+ # be reasonably OK.
77
+ #
78
+ def self.get
79
+ @ruby_version || min_required || fallback
80
+ end
81
+
82
+
83
+ # {.ruby_version} rounded-off to the minor version (patch set to `0`).
84
+ #
85
+ # [docs.ruby-lang.org](https://docs.ruby-lang.org) only serves docs for major
86
+ # and minor releases, not patches (`2.3.0`, `2.4.0`, `2.5.0`, etc.).
87
+ #
88
+ # @example
89
+ # YARD::LinkStdlib.ruby_version = '2.5.1'
90
+ # YARD::LinkStdlib.ruby_minor_version #=> '2.5.0'
91
+ #
92
+ # @return [Gem::Version]
93
+ #
94
+ def self.minor
95
+ Gem::Version.new( ( get.segments[0..1] + [0] ).map( &:to_s ).join( '.' ) )
96
+ end
97
+
98
+
99
+ # Set the fallback mode that is used to pick a version of Ruby to link against
100
+ # when no value is provided by the developer and we couldn't figure one out
101
+ # we were happy with from the gemspec.
102
+ #
103
+ # @param [:minimum_supported, :latest_stable, :current_runtime] value
104
+ # Just picks which of these versions {#fallback} will use:
105
+ #
106
+ # 1. {MINIMUM_SUPPORTED}
107
+ # 2. {LATEST_STABLE}
108
+ # 3. {CURRENT_RUNTIME}
109
+ #
110
+ # @return [:minimum_supported, :latest_stable, :current_runtime]
111
+ # The value that was just set.
112
+ #
113
+ def self.fallback_mode= value
114
+ unless [ :minimum_supported,
115
+ :latest_stable,
116
+ :current_runtime ].include? value
117
+ raise ArgumentError,
118
+ "Fallback-mode must be one of :minimum_supported, :latest_stable, " +
119
+ "or :current_runtime; found #{ value.inspect }"
120
+ end
121
+
122
+ @fallback_mode = value
123
+ end
124
+
125
+
126
+ # Gets the fallback mode. Uses {DEFAULT_FALLBACK_MODE} if one was never set.
127
+ #
128
+ # More details available in {.fallback_mode=} and {.fallback}.
129
+ #
130
+ # @return [:minimum_supported, :latest_stable, :current_runtime]
131
+ # The value that was just set.
132
+ #
133
+ def self.fallback_mode
134
+ @fallback_mode || DEFAULT_FALLBACK_MODE
135
+ end
136
+
137
+
138
+ # Used as last-resort to pick a version of Ruby to link against, after
139
+ # looking for a user-provided value and trying {.min_required}.
140
+ #
141
+ # Simply selects between
142
+ #
143
+ # 1. {MINIMUM_SUPPORTED}
144
+ # 2. {LATEST_STABLE}
145
+ # 3. {CURRENT_RUNTIME}
146
+ #
147
+ # Depending on {.fallback_mode}.
148
+ #
149
+ # @return [Gem::Version]
150
+ # Fallback Ruby version to use.
151
+ #
152
+ def self.fallback
153
+ case fallback_mode
154
+ when :minimum_supported
155
+ MINIMUM_SUPPORTED
156
+ when :latest_stable
157
+ LATEST_STABLE
158
+ when :current_runtime
159
+ CURRENT_RUNTIME
160
+ else
161
+ raise RuntimeError,
162
+ "Bad value #{ fallback_mode.inspect } at " +
163
+ "{YARD::LinkStdlib::RubyVersion.fallback_mode}, " +
164
+ "expected :minimum_supported, :latest_stable or :current_runtime"
165
+ end
166
+ end
167
+
168
+
169
+ # Try to get the minimum required Ruby version from the gemspec (the
170
+ # {Gem::Specification#required_ruby_version} attribute).
171
+ #
172
+ # @return [nil]
173
+ # If we
174
+ #
175
+ # 1. didn't find any {Gem::Specification#required_ruby_version} values, or
176
+ #
177
+ # 2. couldn't figure a reasonable version out given what we found.
178
+ #
179
+ # This method uses a very simple approach, on the hypothesis that almost
180
+ # all real-world configurations will be really simple, and that it's
181
+ # more practical for the few that for some reason have some baffling
182
+ # requirement config to just explicitly specify what Ruby version they
183
+ # want to use.
184
+ #
185
+ # @return [Gem::Version]
186
+ # If we successfully determined a minimum required Ruby version that seems
187
+ # to make some sense to link to.
188
+ #
189
+ def self.min_required
190
+ # Load gemspecs in this dir that have required Ruby versions. There should
191
+ # probably only ever be one, but what they hell this is just as easy as
192
+ # any other handling I thought of off the top of my head...
193
+ specs = Dir[ './*.gemspec' ].
194
+ map { |path| Gem::Specification.load path }.
195
+ select { |spec|
196
+ spec.required_ruby_version && !spec.required_ruby_version.none?
197
+ }
198
+
199
+ # If we didn't find anything useful just assume the gem supports the oldest
200
+ # supported Ruby version and link to that
201
+ return nil if specs.empty?
202
+
203
+ # Map to their {Gem::Requirement} instances
204
+ reqs = specs.map &:required_ruby_version
205
+
206
+ req_arrays = reqs.
207
+ map( &:requirements ). # => Array<Array<Array<(String, Gem::Version)>>>
208
+ flatten( 1 ). # => Array<Array<(String, Gem::Version)>>
209
+ select { |(restriction, version)|
210
+ # We only look at exact `=`, and the "greater-than" ones where we can
211
+ # potentially use the version (with `>` for instance we need to know
212
+ # if another patch version exists *after* it so we know what to bump
213
+ # it too, and I ain't gonna deal with that tonight)
214
+ case restriction
215
+ when '=', '>=', '~>'
216
+ true
217
+ end
218
+ }. # => Array<Array<(String, Gem::Version)>>
219
+ map( &:last ). # => Array<Gem::Version>
220
+ sort. # So we have min first
221
+ # Then find the first one that satisfies all the {Gem::Requirements},
222
+ # or `nil` if none do
223
+ find { |version| reqs.all? { |req| req.satisfied_by? version } }
224
+
225
+ end # min_required
226
+
227
+ end # module RubyVersion
228
+
229
+ # /Namespace
230
+ # ========================================================================
231
+
232
+ end # module LinkStdlib
233
+ end # module YARD
@@ -0,0 +1,101 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ ##############################################################################
5
+ #
6
+ # This file is special - it should not have any dependencies outside the
7
+ # stdlib. It should be loadable without dependencies or paths or bundler
8
+ # or anything in place.
9
+ #
10
+ # This makes it easy for things that are not at all connected to this package
11
+ # or it's environment or whatever to load it up and get some basic info about
12
+ # what's going on.
13
+ #
14
+ ##############################################################################
15
+
16
+ # Requirements (Stdlib Only!)
17
+ # =======================================================================
18
+
19
+ require 'pathname'
20
+ require 'singleton'
21
+
22
+
23
+ # Namespace
24
+ # =======================================================================
25
+
26
+ module YARD
27
+ module LinkStdlib
28
+
29
+
30
+ # Definitions
31
+ # =======================================================================
32
+
33
+ # Absolute, expanded path to the gem's root directory.
34
+ #
35
+ # @return [Pathname]
36
+ #
37
+ ROOT = Pathname.new( __dir__ ).join( '..', '..', '..' ).expand_path
38
+
39
+
40
+ # String version read from `//VERSION` and used in the gemspec.
41
+ #
42
+ # @return [String]
43
+ #
44
+ VERSION = (ROOT + 'VERSION').read.chomp
45
+
46
+
47
+ # The gem name, read from the `//NAME` file, and used in the gemspec.
48
+ #
49
+ # @return [String]
50
+ #
51
+ NAME = (ROOT + 'NAME').read.chomp
52
+
53
+
54
+ def self.repo?
55
+ ROOT.join( 'dev' ).directory?
56
+ end
57
+
58
+ # {Singleton} extension of {Gem::Version} that loads {Locd::VERSION} and
59
+ # provides some convenient methods.
60
+ #
61
+ class Version < Gem::Version
62
+ include ::Singleton
63
+
64
+ # Private method to instantiate the {#instance} using the {Locd::VERSION}
65
+ # {String}.
66
+ #
67
+ # @return [Version]
68
+ #
69
+ def self.new
70
+ super VERSION
71
+ end
72
+
73
+ # We need to mark {.new} as private to dissuade construction of additional
74
+ # instances.
75
+ private_class_method :new
76
+
77
+ # Proxies to the {#instance}'s {#dev?}.
78
+ #
79
+ # @return (see #dev?)
80
+ #
81
+ def self.dev?
82
+ instance.dev?
83
+ end
84
+
85
+ # Tests if the package's version is a development pre-release.
86
+ #
87
+ # @return [Boolean]
88
+ # `true` if this is a development pre-release.
89
+ #
90
+ def dev?
91
+ segments[3] == 'dev'
92
+ end
93
+
94
+ end # module Version
95
+
96
+
97
+ # /Namespace
98
+ # =======================================================================
99
+
100
+ end # module LinkStdlib
101
+ end # module YARD
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-link_stdlib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nrser
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-rescue
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.4.5
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.4.5
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-stack_explorer
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.4.9
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.4.9
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard-commonmarker
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.0
125
+ description: "A YARD plugin (with a bit of monkey-business) to support referencing
126
+ \nmodules, classes, methods, etc. from Ruby's standard library the same way\nyou
127
+ can reference things in your own code, like {String}.\n\nI find this makes the generated
128
+ documentation considerably more useful and\nnatural.\n"
129
+ email:
130
+ - neil@neilsouza.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - LICENSE.txt
136
+ - NAME
137
+ - README.md
138
+ - VERSION
139
+ - bin/make_map.rb
140
+ - lib/yard-link_stdlib.rb
141
+ - lib/yard/cli/link_stdlib.rb
142
+ - lib/yard/link_stdlib.rb
143
+ - lib/yard/link_stdlib/dump.rb
144
+ - lib/yard/link_stdlib/html_helper.rb
145
+ - lib/yard/link_stdlib/object_map.rb
146
+ - lib/yard/link_stdlib/ruby_source.rb
147
+ - lib/yard/link_stdlib/ruby_version.rb
148
+ - lib/yard/link_stdlib/version.rb
149
+ - maps/ruby-2.3.0.json.gz
150
+ - maps/ruby-2.4.0.json.gz
151
+ - maps/ruby-2.5.0.json.gz
152
+ homepage: https://github.com/nrser/yard-link_stdlib
153
+ licenses:
154
+ - BSD
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.5.2.3
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: A YARD plugin & patch to link Ruby stdlib references.
176
+ test_files: []