module Subledger::Path

Constants

COLLECTION_PATHS
KEY_FOR
VALUE_FOR

Public Class Methods

for_collect(args) click to toggle source
# File lib/subledger/path.rb, line 15
def self.for_collect args
  action          = args[:action]
  state           = args[:state]
  limit           = args[:limit]
  collection_name = args[:collection_name]

  key   = key_for args
  value = URI.escape value_for( args ).to_s

  path = for_collection( args ) + '?'

  query_params = []

  query_params << "state=#{    state  }" unless collection_name == :account_lines
  query_params << "action=#{   action }"
  query_params << "#{ key }=#{ value  }" unless value.respond_to?( :length ) and value.length.zero?
  query_params << "limit=#{    limit  }" unless limit.nil?

  path + query_params.join('&')
end
for_collection(args) click to toggle source
# File lib/subledger/path.rb, line 3
def self.for_collection args
  "/#{ API_VERSION }#{ path args }"
end
for_entity(args) click to toggle source
# File lib/subledger/path.rb, line 7
def self.for_entity args
  "#{ for_collection args }/#{ args[ :anchor ].id }"
end
for_entity_without_api_version(args) click to toggle source
# File lib/subledger/path.rb, line 11
def self.for_entity_without_api_version args
  "#{ path args }/#{ args[ :anchor ].id }"
end

Private Class Methods

key_for(args) click to toggle source
# File lib/subledger/path.rb, line 73
def self.key_for args
  action = args[:action]

  if [ :preceding, :following ].include? action
    'id'
  else
    KEY_FOR[ CollectionName.without_state args ]
  end
end
path(args) click to toggle source
# File lib/subledger/path.rb, line 53
def self.path args
  anchor = args[:anchor]

  collection_name = CollectionName.without_state args

  path = COLLECTION_PATHS[collection_name].call anchor

  "/#{path}"
end
value_for(args) click to toggle source
# File lib/subledger/path.rb, line 93
def self.value_for args
  action = args[:action]
  anchor = args[:anchor]

  if [ :preceding, :following ].include? action
    anchor.id
  else
    collection_name = CollectionName.without_state args

    VALUE_FOR[collection_name].call anchor
  end
end