Drop Virtus dependency

This commit is contained in:
Hakan Ensari 2016-04-11 15:05:41 +01:00
parent b6b697872e
commit 055017f68a
3 changed files with 19 additions and 30 deletions

View File

@ -11,7 +11,6 @@ gem 'sequel_pg'
gem 'sinatra-jsonp'
gem 'sinatra-cross_origin'
gem 'unicorn'
gem 'virtus'
gem 'yajl-ruby'
group :development do

View File

@ -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

View File

@ -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'