class Bluepine::Endpoint
Constants
- DEFAULT_OPTIONS
- HTTP_METHODS
- HTTP_METHODS_WITHOUT_BODY
See `docs/api/endpoint-validations.md`.
- HTTP_METHODS_WITH_BODY
Attributes
description[RW]
name[R]
path[R]
schema[R]
title[RW]
Private Class Methods
new(path, options = {}, &block)
click to toggle source
# File lib/bluepine/endpoint.rb, line 29 def initialize(path, options = {}, &block) options = DEFAULT_OPTIONS.merge(options) @schema = options[:schema] @path = path @name = normalize_name(options[:name]) @methods = {} @params = nil @block = block @loaded = false @title = options[:title] @description = options[:description] end
normalize_name(name)
click to toggle source
Converts `/users/:id/friends` to `users_id_friends`
# File lib/bluepine/endpoint.rb, line 15 def normalize_name(name) name.to_s.delete(":").gsub(/(\A\/+|\/+\z)/, '').tr('/', '_').to_sym end
Private Instance Methods
create_method(verb, action, path: "/", **options)
click to toggle source
Registers http verb method
create_method(:post, :create, path: "/")
# File lib/bluepine/endpoint.rb, line 78 def create_method(verb, action, path: "/", **options) # Automatically adds it self as schema value options[:schema] = options.fetch(:schema, schema) @methods[action.to_sym] = Bluepine::Endpoints::Method.new(verb, action: action, path: path, **options) end
ensure_loaded()
click to toggle source
Lazily executes &block
# File lib/bluepine/endpoint.rb, line 92 def ensure_loaded return if @loaded # We need to set status here; otherwise, we'll have # error when there's nested block. @loaded = true instance_exec(&@block) if @block end
method(name, resolver: nil)
click to toggle source
Lazily builds params for speicified method
# File lib/bluepine/endpoint.rb, line 61 def method(name, resolver: nil) ensure_loaded assert_in @methods, name.to_sym @methods[name.to_sym].tap { |method| method.build_params(params, resolver) } end
methods(resolver = nil)
click to toggle source
Lazily builds all params and return methods hash
# File lib/bluepine/endpoint.rb, line 54 def methods(resolver = nil) ensure_loaded @methods.each { |name, _| method(name, resolver: resolver) } end
normalize_name(name)
click to toggle source
# File lib/bluepine/endpoint.rb, line 87 def normalize_name(name) (name || @schema || self.class.normalize_name(@path)).to_sym end
params(&block)
click to toggle source
Returns default params
# File lib/bluepine/endpoint.rb, line 69 def params(&block) ensure_loaded @params ||= Bluepine::Endpoints::Params.new(:default, schema: schema, built: true, &block || -> {}) end