diff --git a/examples/rails/Gemfile.lock b/examples/rails/Gemfile.lock index 8e9a324..352cc1c 100644 --- a/examples/rails/Gemfile.lock +++ b/examples/rails/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../.. specs: - evnt (3.3.0) + evnt (3.4.0) GEM remote: https://rubygems.org/ diff --git a/lib/evnt/query.rb b/lib/evnt/query.rb index 38bd130..bb71313 100644 --- a/lib/evnt/query.rb +++ b/lib/evnt/query.rb @@ -16,15 +16,15 @@ def initialize raise SystemCallError, 'Query can not be initialized' end - def self.as_json(_query, _parameters, except: [], only: []) + def self.as_json(_query, _parameters = {}) raise NotImplementedError, 'As json method should be implemented on Query subclasses' end - def self.as_string(_query, _parameters, except: [], only: []) + def self.as_string(_query, _parameters = {}) raise NotImplementedError, 'As string method should be implemented on Query subclasses' end - def self.as_bytes(_query, _parameters, except: [], only: []) + def self.as_bytes(_query, _parameters = {}) raise NotImplementedError, 'As bytes method should be implemented on Query subclasses' end diff --git a/lib/evnt/query_activerecord.rb b/lib/evnt/query_activerecord.rb index 236e5d1..1705fd4 100644 --- a/lib/evnt/query_activerecord.rb +++ b/lib/evnt/query_activerecord.rb @@ -17,10 +17,11 @@ class QueryActiverecord < Evnt::Query # # * +query+ - The name of the query that should be executed. # * +parameters+ - An object containing the parameters for the query. - # * +except+ - The list of attributes that should be removed from the json. - # * +only+ - The list of parameters that shoud be accepted for the json. ## - def self.as_json(query, parameters = {}, except: [], only: []) + def self.as_json(query, parameters = {}) + except = parameters[:_except] || [] + only = parameters[:_only] || [] + result = send(query, parameters).as_json return result unless except.length.positive? || only.length.positive? @@ -35,11 +36,9 @@ def self.as_json(query, parameters = {}, except: [], only: []) # # * +query+ - The name of the query that should be executed. # * +parameters+ - An object containing the parameters for the query. - # * +except+ - The list of attributes that should be removed from the json. - # * +only+ - The list of parameters that shoud be accepted for the json. ## - def self.as_string(query, parameters = {}, except: [], only: []) - as_json(query, parameters, except: except, only: only).to_s + def self.as_string(query, parameters = {}) + as_json(query, parameters).to_s end ## @@ -49,11 +48,9 @@ def self.as_string(query, parameters = {}, except: [], only: []) # # * +query+ - The name of the query that should be executed. # * +parameters+ - An object containing the parameters for the query. - # * +except+ - The list of attributes that should be removed from the json. - # * +only+ - The list of parameters that shoud be accepted for the json. ## - def self.as_bytes(query, parameters = {}, except: [], only: []) - as_string(query, parameters, except: except, only: only).bytes.to_a + def self.as_bytes(query, parameters = {}) + as_string(query, parameters).bytes.to_a end end