bootinq 2.0 → 2.0.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: e1652380ae399a299061b4faa8b2372fec798e02ce9f1fc9b3ab3b1a035d779e
4
- data.tar.gz: d2339a8385fad5b4aaca89a5c2992f0adf4c5205bb650a05eb2b92e52daa349f
3
+ metadata.gz: 6e377cd962a0467e2e6ea056674bae230612b823f667d780c9982d76ff4bbf0c
4
+ data.tar.gz: 402aef98700c975d26ef975c8e21fef639138dc03b5adb93c54f8e85e3b5a44f
5
5
  SHA512:
6
- metadata.gz: a08526e07966f344034a18f42d032a996ab5fc97db980b3a356a3b0b4173b6e6d98ecc345a6ab80d77ec7f9e30aca2641e75b029553a3c3d45bfbceaf1ab5c8d
7
- data.tar.gz: 850ee258bc77e6889b7a3ee5969f4befdf1ff217cb5eb1f5e70af1a3bce7b0c6c0191d2c0a87a7e5ce3d6d8f42611a3480f19bde7b7b002695133d39413eca60
6
+ metadata.gz: 78dffcca879fd25017dc6d09fdd33f5bfdbd5878922a7c705d10f0ccd07cd703bede9e2d5e2e06ccc8c18bcdc21e091fc9efb7611e8f7d0b69193bfe4f951676
7
+ data.tar.gz: e6aeda4ed1293fb720a9998d79dd877bc36cff136fc78b9bcf420b8dd2f9a322fe573014303c4572c0bde882c327d6d66d7c127ec0983403fa0693ab43047d0e
@@ -2,90 +2,306 @@
2
2
 
3
3
  class Bootinq
4
4
  class Component
5
- attr_reader :intern, :id2name, :group
5
+ # @!attribute [r] intern
6
+ # @return [Symbol]
6
7
 
7
- alias :to_sym :intern
8
- alias :to_s :id2name
9
- alias :gem_name :id2name
10
- alias :name :id2name
8
+ attr_reader :intern
11
9
 
10
+ # @!attribute [r] id2name
11
+ # @return [Symbol]
12
+
13
+ attr_reader :id2name
14
+
15
+ # @!attribute [r] group
16
+ # @return [Symbol] Bundle group name
17
+
18
+ attr_reader :group
19
+
20
+ alias_method :to_sym, :intern
21
+ alias_method :to_s, :id2name
22
+ alias_method :gem_name, :id2name
23
+ alias_method :name, :id2name
24
+
25
+ # @see #initialize
26
+ # @param intern [String, Symbol]
27
+ # @return [Bootinq::Component] frozen
28
+ def self.new(intern)
29
+ super.freeze
30
+ end
31
+
32
+ # @param intern [String, Symbol]
33
+ # @return [self]
12
34
  def initialize(intern)
13
- @intern = intern.to_sym
35
+ @intern = intern.to_sym
14
36
  @id2name = intern.to_s.freeze
15
- @group = :"#@id2name\_boot"
16
- freeze
37
+ @group = :"#{@id2name}_boot"
17
38
  end
18
39
 
40
+ # @return [Boolean]
19
41
  def mountable?
20
42
  false
21
43
  end
22
44
 
45
+ # @return [Symbol]
23
46
  def module_name
24
47
  @id2name.camelcase.to_sym
25
48
  end
26
49
 
50
+ # @return [Module]
51
+ def namespace
52
+ Object.const_get(module_name)
53
+ end
54
+
55
+ # @return [void]
27
56
  def engine
28
57
  end
29
58
 
59
+ # @param klass [Class]
60
+ # @return [Boolean]
30
61
  def kind_of?(klass)
31
62
  super || @intern.kind_of?(klass)
32
63
  end
33
64
 
34
- def == other
65
+ ##
66
+ # @!group Coercing methods
67
+
68
+ # Coerces self to other value klass.
69
+ # @overload coerce_to(string)
70
+ # @param string [String]
71
+ # @return [String] {#id2name}
72
+ # @overload coerce_to(symbol)
73
+ # @param symbol [Symbol]
74
+ # @return [Symbol] {#intern}
75
+ # @overload coerce_to(other)
76
+ # @param other [Any]
77
+ # @return [self]
78
+ def coerce_to(other)
35
79
  case other
36
- when String then other == @id2name
37
- when Symbol then other == @intern
38
- else super
80
+ when String; @id2name
81
+ when Symbol; @intern
82
+ else self
39
83
  end
40
84
  end
41
85
 
42
- def ===(other)
86
+ # Coerces other value
87
+ # @overload coerce(symbol)
88
+ # @param symbol [Symbol]
89
+ # @return [Symbol] symbol
90
+ # @overload coerce(other)
91
+ # @param other [String, Any]
92
+ # @return [String] other
93
+ def coerce(other)
43
94
  case other
44
- when String then other === @id2name
45
- when Symbol then other === @intern
46
- else super
95
+ when String, Symbol; other
96
+ else other.to_s
47
97
  end
48
98
  end
49
99
 
100
+ # @!endgroup
101
+ ##
102
+
103
+ ##
104
+ # @!group Comparation methods
105
+
106
+ # @param other [Any]
107
+ # @return [Boolean]
108
+ def ==(other)
109
+ other = coerce(other)
110
+ other == coerce_to(other)
111
+ end
112
+
113
+ # @param other [Any]
114
+ # @return [Boolean]
115
+ def ===(other)
116
+ other = coerce(other)
117
+ other === coerce_to(other)
118
+ end
119
+
120
+ # @param other [Any]
121
+ # @return [Boolean]
50
122
  def casecmp(other)
51
- case other
52
- when String then @id2name.casecmp(other)
53
- when Symbol then @intern.casecmp(other)
54
- when self.class then casecmp(other.to_s)
55
- end
123
+ other = coerce(other)
124
+ coerce_to(other).casecmp(other)
56
125
  end
57
126
 
127
+ # @param other [Any]
128
+ # @return [Boolean]
58
129
  def casecmp?(other)
59
- case other
60
- when String then @id2name.casecmp?(other)
61
- when Symbol then @intern.casecmp?(other)
62
- when self.class then casecmp?(other.to_s)
63
- end
130
+ other = coerce(other)
131
+ coerce_to(other).casecmp?(other)
132
+ end
133
+
134
+ # @!endgroup
135
+ ##
136
+
137
+ ##
138
+ # @!group Symbol-delegated methods
139
+
140
+ # @return [String] representation of {#intern} as a symbol literal.
141
+ def inspect
142
+ @intern.inspect
143
+ end
144
+
145
+ # @return [Proc] responded to the given method by {#intern}
146
+ def to_proc
147
+ @intern.to_proc
64
148
  end
65
149
 
66
- %i(inspect to_proc __id__ hash).
67
- each { |sym| class_eval %(def #{sym}; @intern.#{sym}; end), __FILE__, __LINE__ + 1 }
150
+ # @return [Integer] identifier for {#intern}
151
+ def __id__
152
+ @intern.__id__
153
+ end
68
154
 
69
- %i(encoding empty? length).
70
- each { |sym| class_eval %(def #{sym}; @id2name.#{sym}; end), __FILE__, __LINE__ + 1 }
155
+ # @return [Integer] {#intern}'s hash
156
+ def hash
157
+ @intern.hash
158
+ end
71
159
 
72
- %i(match match? =~ []).
73
- each { |sym| class_eval %(def #{sym}(*args); @id2name.#{sym}(*args); end), __FILE__, __LINE__ + 1 }
160
+ # @!endgroup
161
+ ##
74
162
 
75
- %i(upcase downcase capitalize swapcase succ next).
76
- each { |sym| class_eval %(def #{sym}; self.class.new(@intern.#{sym}); end), __FILE__, __LINE__ + 1 }
163
+ ##
164
+ # @!group String-delegated methods
77
165
 
78
- alias :slice :[]
79
- alias :size :length
166
+ # @return [Encoding] of {#id2name}
167
+ def encoding
168
+ @id2name.encoding
169
+ end
170
+
171
+ # @return [Boolean]
172
+ def empty?
173
+ @id2name.empty?
174
+ end
175
+
176
+ # @return [Integer] length of {#id2name}
177
+ def length
178
+ @id2name.length
179
+ end
180
+
181
+ # @param pattern [Regexp, String]
182
+ # @param start_from [Integer] position in {#id2name} to begin the search
183
+ # @yield [MatchData] if match succeed
184
+ # @yieldreturn [Any]
185
+ # @return [MatchData] unless block given
186
+ # @return [Any] returned by the given block
187
+ def match(*args, &block)
188
+ @id2name.match(*args, &block)
189
+ end
190
+
191
+ # @param pattern [Regexp, String]
192
+ # @param start_from [Integer] position in {#id2name} to begin the search
193
+ # @return [Boolean] indicates whether the regexp is matched or not
194
+ def match?(*args)
195
+ @id2name.match?(*args)
196
+ end
197
+
198
+ # @overload =~(pattern)
199
+ # @param pattern [Regexp]
200
+ # @return [Integer] if matched, the position the match starts
201
+ # @return [nil] if there is no match
202
+ # @overload =~(arg)
203
+ # @param arg [Object]
204
+ # @see Object#=~
205
+ def =~(arg)
206
+ @id2name =~ arg
207
+ end
208
+
209
+ # Element reference
210
+ # @see String#slice
211
+ def slice(*args)
212
+ @id2name[*args]
213
+ end
214
+
215
+ alias_method :[], :slice
216
+
217
+ # @!endgroup
218
+ ##
219
+
220
+ ##
221
+ # @!group Symbol-delegated mutation methods
222
+
223
+ # @see Symbol#upcase
224
+ # @return [Bootinq::Component] new instance with upcased {#intern}
225
+ def upcase
226
+ self.class.new(@intern.upcase)
227
+ end
228
+
229
+ # @see Symbol#downcase
230
+ # @return [Bootinq::Component] new instance with downcased {#intern}
231
+ def downcase
232
+ self.class.new(@intern.downcase)
233
+ end
234
+
235
+ # @see Symbol#capitalize
236
+ # @return [Bootinq::Component] new instance with capitalized {#intern}
237
+ def capitalize
238
+ self.class.new(@intern.capitalize)
239
+ end
240
+
241
+ # @see Symbol#swapcase
242
+ # @return [Bootinq::Component] new instance with swapcased {#intern}
243
+ def swapcase
244
+ self.class.new(@intern.swapcase)
245
+ end
246
+
247
+ # @see Symbol#succ
248
+ # @return [Bootinq::Component] new instance with the successor {#intern}
249
+ def succ
250
+ self.class.new(@intern.succ)
251
+ end
252
+
253
+ # @see Symbol#next
254
+ # @return [Bootinq::Component] new instance with the next {#intern}
255
+ def next
256
+ self.class.new(@intern.next)
257
+ end
258
+
259
+ # @endgroup
260
+ ##
80
261
  end
81
262
 
82
263
  class Mountable < Component
264
+ # @!attribute [r] module_name
265
+ # @return [Symbol]
266
+
267
+ # @!attribute [r] namespace
268
+ # @return [Module]
269
+
270
+ def initialize(intern)
271
+ super
272
+ @module_name = module_name()
273
+ @namespace = namespace()
274
+ end
275
+
83
276
  def mountable?
84
277
  true
85
278
  end
86
279
 
280
+ def module_name
281
+ return @module_name if frozen? || defined?(@module_name)
282
+ super
283
+ end
284
+
285
+ def namespace
286
+ if frozen? || defined?(@namespace)
287
+ @namespace.is_a?(Proc) ? @namespace.call : @namespace
288
+ elsif namespace_defined?
289
+ super
290
+ else
291
+ proc { super }
292
+ end
293
+ end
294
+
295
+ # @return [Class]
87
296
  def engine
88
- Object.const_get(module_name)::Engine
297
+ namespace::Engine
298
+ end
299
+
300
+ private
301
+
302
+ # @api private
303
+ def namespace_defined?
304
+ Object.const_defined?(module_name)
89
305
  end
90
306
  end
91
307
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Bootinq
4
- VERSION = "2.0"
4
+ VERSION = "2.0.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootinq
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-26 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler