acvwilson-currency 0.6.3 → 0.6.4
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.
data/currency.gemspec
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = %q{currency}
|
|
3
|
-
s.version = "0.6.
|
|
3
|
+
s.version = "0.6.4"
|
|
4
4
|
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
6
|
-
s.authors = ["Asa Wilson"]
|
|
6
|
+
s.authors = ["Asa Wilson", "David Palm"]
|
|
7
7
|
s.date = %q{#{Date.today}}
|
|
8
8
|
s.description = %q{Currency conversions for Ruby}
|
|
9
|
-
s.email = ["acvwilson@gmail.com"]
|
|
9
|
+
s.email = ["acvwilson@gmail.com", "dvdplm@gmail.com"]
|
|
10
10
|
s.extra_rdoc_files = ["ChangeLog", "COPYING.txt", "LICENSE.txt", "Manifest.txt", "README.txt", "Releases.txt", "TODO.txt"]
|
|
11
11
|
s.files = ["COPYING.txt", "currency.gemspec", "examples/ex1.rb", "examples/xe1.rb", "lib/currency/active_record.rb", "lib/currency/config.rb", "lib/currency/core_extensions.rb", "lib/currency/currency/factory.rb", "lib/currency/currency.rb", "lib/currency/exception.rb", "lib/currency/exchange/rate/deriver.rb", "lib/currency/exchange/rate/source/base.rb", "lib/currency/exchange/rate/source/failover.rb", "lib/currency/exchange/rate/source/federal_reserve.rb", "lib/currency/exchange/rate/source/historical/rate.rb", "lib/currency/exchange/rate/source/historical/rate_loader.rb", "lib/currency/exchange/rate/source/historical/writer.rb", "lib/currency/exchange/rate/source/historical.rb", "lib/currency/exchange/rate/source/new_york_fed.rb", "lib/currency/exchange/rate/source/provider.rb", "lib/currency/exchange/rate/source/test.rb", "lib/currency/exchange/rate/source/the_financials.rb", "lib/currency/exchange/rate/source/timed_cache.rb", "lib/currency/exchange/rate/source/xe.rb", "lib/currency/exchange/rate/source.rb", "lib/currency/exchange/rate.rb", "lib/currency/exchange/time_quantitizer.rb", "lib/currency/exchange.rb", "lib/currency/formatter.rb", "lib/currency/macro.rb", "lib/currency/money.rb", "lib/currency/money_helper.rb", "lib/currency/parser.rb", "lib/currency.rb", "LICENSE.txt", "Manifest.txt", "README.txt", "Releases.txt", "spec/ar_spec_helper.rb", "spec/ar_column_spec.rb", "spec/ar_simple_spec.rb", "spec/config_spec.rb", "spec/federal_reserve_spec.rb", "spec/formatter_spec.rb", "spec/historical_writer_spec.rb", "spec/macro_spec.rb", "spec/money_spec.rb", "spec/new_york_fed_spec.rb", "spec/parser_spec.rb", "spec/spec_helper.rb", "spec/time_quantitizer_spec.rb", "spec/timed_cache_spec.rb", "spec/xe_spec.rb", "TODO.txt"]
|
|
12
12
|
s.has_rdoc = true
|
|
@@ -203,6 +203,15 @@ end_eval
|
|
|
203
203
|
validate = "# Validation\n"
|
|
204
204
|
validate << "\nvalidates_numericality_of :#{attr_name}#{validate_allow_nil}\n"
|
|
205
205
|
validate << "\nvalidates_format_of :#{currency_column}, :with => /^[A-Z][A-Z][A-Z]$/#{validate_allow_nil}\n" if currency_column
|
|
206
|
+
# validate << "\nbefore_validation :debug_#{attr_name}_before_validate\n"
|
|
207
|
+
#
|
|
208
|
+
# validate << %Q{
|
|
209
|
+
# def debug_#{attr_name}_before_validate
|
|
210
|
+
# logger.debug "\tValidating #{attr_name}. Allow nils? #{validate_allow_nil}"
|
|
211
|
+
# logger.debug "\t\t'#{attr_name}': '\#\{#{attr_name}.inspect\}' (class: '\#\{#{attr_name}.class\}')"
|
|
212
|
+
# logger.debug "\t\tcurrency column, '#{currency_column}': '\#\{#{currency_column}.inspect\}' (class: '\#\{#{currency_column}.class\}'), matches '/^[A-Z][A-Z][A-Z]$/': \#\{'#{currency_column}'.match(/^[A-Z][A-Z][A-Z]$/).to_a.inspect\}"
|
|
213
|
+
# end
|
|
214
|
+
# }
|
|
206
215
|
|
|
207
216
|
alias_accessor ||= ''
|
|
208
217
|
|
|
@@ -246,13 +255,38 @@ def #{attr_name}=(value)
|
|
|
246
255
|
end
|
|
247
256
|
|
|
248
257
|
def #{attr_name}_before_type_cast
|
|
249
|
-
#
|
|
250
|
-
x = #{attr_name}
|
|
251
|
-
x &&= x.format(:symbol => false, :currency => false, :thousands => false)
|
|
252
|
-
x
|
|
258
|
+
#{attr_name}.to_f if #{attr_name}
|
|
253
259
|
end
|
|
254
260
|
|
|
255
261
|
end_eval
|
|
262
|
+
=begin
|
|
263
|
+
Replaced the _before_type_cast because it's buggy and weird:
|
|
264
|
+
|
|
265
|
+
Bug: if the Currency::Formatter.default is set to include the currency code (:code => true) then the
|
|
266
|
+
call below to format() will leave the code in. When the validates_numericality_of kicks in it
|
|
267
|
+
can't cast to Float (yes, validates_numericality_of basically does just that) because of the "USD"
|
|
268
|
+
of the currency code and everything fails. All the time.
|
|
269
|
+
|
|
270
|
+
Weird: assigning to "x" doesn't really make any sense, just useless overhead. Using the rare &&= is not a big
|
|
271
|
+
win over something like:
|
|
272
|
+
x && x.format(..., ...)
|
|
273
|
+
and actually longer too.
|
|
274
|
+
The intention of the _before_type_cast method is to return a raw, unformatted value.
|
|
275
|
+
When it does work, it returns a string on the form "123.456". Why not cast to Float right away?
|
|
276
|
+
Arguably, the "raw" currency value is the integer rep stored in the db, but that wouldn't work
|
|
277
|
+
very well with any known rails validations. I think casting to Float is reasonable.
|
|
278
|
+
The taste Kurt Stephens has for weird Ruby code never ceases to amaze me.
|
|
279
|
+
|
|
280
|
+
:)
|
|
281
|
+
(dvd, 05-02-2009)
|
|
282
|
+
def #{attr_name}_before_type_cast
|
|
283
|
+
# FIXME: User cannot specify Currency
|
|
284
|
+
x = #{attr_name}
|
|
285
|
+
x &&= x.format(:symbol => false, :currency => false, :thousands => false)
|
|
286
|
+
x
|
|
287
|
+
end
|
|
288
|
+
=end
|
|
289
|
+
|
|
256
290
|
# $stderr.puts " CODE = #{x}"
|
|
257
291
|
end
|
|
258
292
|
end
|
|
@@ -175,6 +175,7 @@ class Currency::Exchange::Rate::Source::Historical::Rate < ::ActiveRecord::Base
|
|
|
175
175
|
|
|
176
176
|
# Shorthand.
|
|
177
177
|
def find_matching_this(opt1 = :all, *opts)
|
|
178
|
+
# FIXME: this breaks somehow in Ruby 1.9 Not sure why. (dvd, 04-02-2009)
|
|
178
179
|
self.class.find(opt1, :conditions => find_matching_this_conditions, *opts)
|
|
179
180
|
end
|
|
180
181
|
|
metadata
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acvwilson-currency
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Asa Wilson
|
|
8
|
+
- David Palm
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
12
|
|
|
12
|
-
date: 2009-
|
|
13
|
+
date: 2009-02-05 06:05:45.477389 -08:00
|
|
13
14
|
default_executable:
|
|
14
15
|
dependencies: []
|
|
15
16
|
|
|
16
17
|
description: Currency conversions for Ruby
|
|
17
18
|
email:
|
|
18
19
|
- acvwilson@gmail.com
|
|
20
|
+
- dvdplm@gmail.com
|
|
19
21
|
executables: []
|
|
20
22
|
|
|
21
23
|
extensions: []
|