Skip to content

Commit

Permalink
fixed query and query activerecord as_json function
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregorio Galante committed Apr 4, 2018
1 parent 8fc2a36 commit 0156d8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/rails/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
evnt (3.3.0)
evnt (3.4.0)

GEM
remote: https://rubygems.org/
Expand Down
6 changes: 3 additions & 3 deletions lib/evnt/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 8 additions & 11 deletions lib/evnt/query_activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

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

##
Expand All @@ -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
Expand Down

0 comments on commit 0156d8e

Please sign in to comment.