Skip to content

Commit

Permalink
Reorder methods, make “!” methods private
Browse files Browse the repository at this point in the history
  • Loading branch information
radiospiel committed May 3, 2018
1 parent d5e5da2 commit 6e503ac
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/simple/sql/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ def where(sql_fragment, arg = :__dummy__no__arg, placeholder: "?")
duplicate.send(:where!, sql_fragment, arg, placeholder: placeholder)
end

# Set pagination
def paginate(per:, page:)
duplicate.send(:paginate!, per: per, page: page)
end

def order_by(sql_fragment)
duplicate.send(:order_by!, sql_fragment)
end

private

def where!(sql_fragment, arg = :__dummy__no__arg, placeholder: "?")
if arg == :__dummy__no__arg
@filters << sql_fragment
Expand All @@ -63,11 +74,6 @@ def where!(sql_fragment, arg = :__dummy__no__arg, placeholder: "?")
self
end

# Set pagination
def paginate(per:, page:)
duplicate.send(:paginate!, per: per, page: page)
end

def paginate!(per:, page:)
@per = per
@page = page
Expand All @@ -81,10 +87,6 @@ def order_by!(sql_fragment)
self
end

def order_by(sql_fragment)
duplicate.order_by!(sql_fragment)
end

public

# Is this a paginated scope?
Expand Down

0 comments on commit 6e503ac

Please sign in to comment.