power_converter 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: 93f5ce27cd391f22fbebc0a5b98318ebb5e12f79
4
- data.tar.gz: 3f45e0e53f6af3fc363577aaa02007095b90bfeb
3
+ metadata.gz: 231f3bafb26ecf2efc70db2d2338e588507e3b5e
4
+ data.tar.gz: 23559b89538e7c97be6c0e236195ed0ff10dec2b
5
5
  SHA512:
6
- metadata.gz: 628a695ed189d9ed1b4922c053a42b538ae930bf049b1dd5c7eafa913bbe0b2251affc88a3c2c7731fa4a57836ac2660fb15c0e014d61877b4c8b9ae9737de23
7
- data.tar.gz: 58735d7bc79fd56f652cd87f605d48fb931668502e7bccc91f599fed168b75283fefa638928aba38f004010a469ebcb0a0714f1aff5f6de16e9ff1770cbb0006
6
+ metadata.gz: f1d69e2b8ec68a7a1243a859275f27fee157d9f2ebf6c917aba19917cb9fb3a918084787a7f118bbaa6ff9388ee44765a1351585cf35a3fff1bea9c174f249e2
7
+ data.tar.gz: 405afa509040219845f92b70f3830d75714651c2fd2c4e559684967df4ddc188c97fd5252394f6217dc5b19d437a2b4fdebe746bb52a7eae019877457e38a8e4
@@ -96,6 +96,26 @@ module PowerConverter
96
96
  @defined_conversions[named_conversion.to_s] = converter
97
97
  end
98
98
 
99
+ # @api public
100
+ # @since 0.0.4
101
+ #
102
+ # You may define an alias of a defined (or to be defined) power converter.
103
+ #
104
+ # @param aliased_named_conversion [String,Symbol] the name of the conversion that you
105
+ # are declaring.
106
+ # @param [Hash] options the options used to perform the conversion
107
+ # @option options [Symbol] :is_alias_of the aliased_named_conversion that we
108
+ # will be using for to perform the conversion.
109
+ #
110
+ # @return void
111
+ #
112
+ # @example
113
+ # PowerConverter.define_alias(:true_or_false, is_alias_of: :boolean)
114
+ def define_alias(aliased_named_conversion, options = {})
115
+ @aliased_conversions ||= {}
116
+ @aliased_conversions[aliased_named_conversion.to_s] = options.fetch(:is_alias_of)
117
+ end
118
+
99
119
  # @api public
100
120
  # @since 0.0.1
101
121
  #
@@ -187,10 +207,13 @@ module PowerConverter
187
207
  #
188
208
  # @example
189
209
  # PowerConverter.converter_for(:boolean).call(value)
210
+ #
211
+ # @note There are no protections for infinite alias loops.
190
212
  def converter_for(named_conversion)
191
- @defined_conversions.fetch(named_conversion.to_s)
192
- rescue KeyError
193
- raise ConverterNotFoundError.new(named_conversion, defined_converter_names)
213
+ key = named_conversion.to_s
214
+ return defined_conversions[key] if defined_conversions.key?(key)
215
+ return converter_for(aliased_conversions[key]) if aliased_conversions.key?(key)
216
+ fail ConverterNotFoundError.new(named_conversion, defined_converter_names)
194
217
  end
195
218
 
196
219
  # @api public
@@ -201,7 +224,7 @@ module PowerConverter
201
224
  #
202
225
  # @return [Array] of the defined converter's names
203
226
  def defined_converter_names
204
- @defined_conversions.keys
227
+ defined_conversions.keys + aliased_conversions.keys
205
228
  end
206
229
 
207
230
  # Useful for when you want to know if a method name is a valid conversion
@@ -273,4 +296,14 @@ module PowerConverter
273
296
  end
274
297
  end
275
298
  private_class_method :respond_to_missing?
299
+
300
+ def defined_conversions
301
+ @defined_conversions || {}
302
+ end
303
+ private_class_method :defined_conversions
304
+
305
+ def aliased_conversions
306
+ @aliased_conversions || {}
307
+ end
308
+ private_class_method :aliased_conversions
276
309
  end
@@ -1,5 +1,5 @@
1
1
  # :nodoc:
2
2
  module PowerConverter
3
3
  # :nodoc:
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,8 +126,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.4.3
129
+ rubygems_version: 2.4.6
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: A lightweight library to define object conversion methods/modules.
133
133
  test_files: []
134
+ has_rdoc: