mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-22 02:52:49 +01:00
Drop Virtus dependency
This commit is contained in:
parent
b6b697872e
commit
055017f68a
1
Gemfile
1
Gemfile
@ -11,7 +11,6 @@ gem 'sequel_pg'
|
||||
gem 'sinatra-jsonp'
|
||||
gem 'sinatra-cross_origin'
|
||||
gem 'unicorn'
|
||||
gem 'virtus'
|
||||
gem 'yajl-ruby'
|
||||
|
||||
group :development do
|
||||
|
17
Gemfile.lock
17
Gemfile.lock
@ -3,19 +3,9 @@ GEM
|
||||
specs:
|
||||
ansi (1.5.0)
|
||||
ast (2.2.0)
|
||||
axiom-types (0.1.1)
|
||||
descendants_tracker (~> 0.0.4)
|
||||
ice_nine (~> 0.11.0)
|
||||
thread_safe (~> 0.3, >= 0.3.1)
|
||||
coderay (1.1.1)
|
||||
coercible (1.0.0)
|
||||
descendants_tracker (~> 0.0.1)
|
||||
descendants_tracker (0.0.4)
|
||||
thread_safe (~> 0.3, >= 0.3.1)
|
||||
equalizer (0.0.11)
|
||||
fixer (0.6.0)
|
||||
oga (~> 2.0)
|
||||
ice_nine (0.11.2)
|
||||
kgio (2.10.0)
|
||||
method_source (0.8.2)
|
||||
minitest (5.8.4)
|
||||
@ -56,16 +46,10 @@ GEM
|
||||
multi_json (~> 1.8)
|
||||
sinatra (~> 1.0)
|
||||
slop (3.6.0)
|
||||
thread_safe (0.3.5)
|
||||
tilt (2.0.2)
|
||||
unicorn (5.1.0)
|
||||
kgio (~> 2.6)
|
||||
raindrops (~> 0.7)
|
||||
virtus (1.0.5)
|
||||
axiom-types (~> 0.1)
|
||||
coercible (~> 1.0)
|
||||
descendants_tracker (~> 0.0, >= 0.0.3)
|
||||
equalizer (~> 0.0, >= 0.0.9)
|
||||
yajl-ruby (1.2.1)
|
||||
|
||||
PLATFORMS
|
||||
@ -84,7 +68,6 @@ DEPENDENCIES
|
||||
sinatra-cross_origin
|
||||
sinatra-jsonp
|
||||
unicorn
|
||||
virtus
|
||||
yajl-ruby
|
||||
|
||||
BUNDLED WITH
|
||||
|
31
lib/quote.rb
31
lib/quote.rb
@ -1,32 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'virtus'
|
||||
require 'currency'
|
||||
|
||||
class Quote
|
||||
include Virtus.value_object
|
||||
|
||||
Invalid = Class.new(StandardError)
|
||||
|
||||
DEFAULT_BASE = 'EUR'.freeze
|
||||
DEFAULT_BASE = 'EUR'
|
||||
|
||||
values do
|
||||
attribute :base, String, default: DEFAULT_BASE
|
||||
attribute :date, Date, default: proc { Currency.current_date }
|
||||
attribute :rates, Hash, default: :find_rates, lazy: true
|
||||
attr_reader :base, :date
|
||||
|
||||
def initialize(params = {})
|
||||
self.base = params[:base]
|
||||
self.date = params[:date]
|
||||
end
|
||||
|
||||
def rates
|
||||
@rates ||= find_rates
|
||||
end
|
||||
|
||||
def attributes
|
||||
{ base: base, date: date, rates: rates }
|
||||
end
|
||||
|
||||
alias to_h attributes
|
||||
|
||||
private
|
||||
|
||||
def base=(base)
|
||||
base.upcase!
|
||||
super base
|
||||
@base = base ? base.upcase : DEFAULT_BASE
|
||||
end
|
||||
|
||||
def date=(date)
|
||||
current_date = Currency.current_date_before(date)
|
||||
current_date = date ? Currency.current_date_before(date) : Currency.current_date
|
||||
raise Invalid, 'Date too old' unless current_date
|
||||
super current_date
|
||||
@date = current_date
|
||||
rescue Sequel::DatabaseError => ex
|
||||
if ex.wrapped_exception.is_a?(PG::DatetimeFieldOverflow)
|
||||
raise Invalid, 'Invalid date'
|
||||
|
Loading…
Reference in New Issue
Block a user