mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
Refactor query building out of server
This commit is contained in:
parent
72fe6022c9
commit
ec302e726c
@ -1,6 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Query
|
||||
def self.build(params)
|
||||
new(params).to_h
|
||||
end
|
||||
|
||||
def initialize(params = {})
|
||||
@params = params
|
||||
end
|
||||
|
@ -32,6 +32,7 @@ set :static_cache_control, [:public, max_age: 300]
|
||||
helpers do
|
||||
def end_of_day_quote
|
||||
@end_of_day_quote ||= begin
|
||||
query = Query.build(params)
|
||||
quote = Quote::EndOfDay.new(query)
|
||||
quote.perform
|
||||
halt 404 if quote.not_found?
|
||||
@ -42,6 +43,7 @@ helpers do
|
||||
|
||||
def interval_quote
|
||||
@interval_quote ||= begin
|
||||
query = Query.build(params)
|
||||
quote = Quote::Interval.new(query)
|
||||
quote.perform
|
||||
halt 404 if quote.not_found?
|
||||
@ -50,10 +52,6 @@ helpers do
|
||||
end
|
||||
end
|
||||
|
||||
def query
|
||||
Query.new(params).to_h
|
||||
end
|
||||
|
||||
def json(data)
|
||||
json = Oj.dump(data, mode: :compat)
|
||||
callback = params['callback']
|
||||
|
@ -4,6 +4,10 @@ require_relative 'helper'
|
||||
require 'query'
|
||||
|
||||
describe Query do
|
||||
it 'builds a query hash' do
|
||||
Query.build(date: '2014-01-01').must_be_kind_of Hash
|
||||
end
|
||||
|
||||
it 'returns given amount' do
|
||||
query = Query.new(amount: '100')
|
||||
query.amount.must_equal 100.0
|
||||
|
Loading…
Reference in New Issue
Block a user