module Graphiti::Links

Constants

DEFAULT_ACTIONS

Public Instance Methods

allow_request?(request_path, params, action) click to toggle source
# File lib/graphiti/resource/links.rb, line 71
def allow_request?(request_path, params, action)
  request_path = request_path.split(".")[0]

  endpoints.any? do |e|
    has_id = params[:id] || params[:data].try(:[], :id)
    path = request_path
    if [:update, :show, :destroy].include?(context_namespace) && has_id
      path = request_path.split("/")
      path.pop if path.last == has_id.to_s
      path = path.join("/")
    end
    e[:full_path].to_s == path && e[:actions].include?(context_namespace)
  end
end
endpoints() click to toggle source
# File lib/graphiti/resource/links.rb, line 67
def endpoints
  ([endpoint] + secondary_endpoints).compact
end
full_path_for(path) click to toggle source
# File lib/graphiti/resource/links.rb, line 88
def full_path_for(path)
  [endpoint_namespace, path].join("").to_sym
end
infer_endpoint() click to toggle source
# File lib/graphiti/resource/links.rb, line 34
def infer_endpoint
  return unless name

  path = "/#{name.gsub("Resource", "").pluralize.underscore}".to_sym
  {
    path: path,
    full_path: full_path_for(path),
    url: url_for(path),
    actions: DEFAULT_ACTIONS.dup
  }
end
primary_endpoint(path, actions = DEFAULT_ACTIONS.dup) click to toggle source
# File lib/graphiti/resource/links.rb, line 46
def primary_endpoint(path, actions = DEFAULT_ACTIONS.dup)
  path = path.to_sym
  self.endpoint = {
    path: path,
    full_path: full_path_for(path),
    url: url_for(path),
    actions: actions
  }
end
secondary_endpoint(path, actions = DEFAULT_ACTIONS.dup) click to toggle source

NB: avoid << b/c class_attribute

# File lib/graphiti/resource/links.rb, line 57
def secondary_endpoint(path, actions = DEFAULT_ACTIONS.dup)
  path = path.to_sym
  self.secondary_endpoints += [{
    path: path,
    full_path: full_path_for(path),
    url: url_for(path),
    actions: actions
  }]
end
url_for(path) click to toggle source
# File lib/graphiti/resource/links.rb, line 92
def url_for(path)
  [base_url, full_path_for(path)].join("").to_sym
end