source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/plugin_concern.rb | Ruby | mit | 302 | master | 681 | # frozen_string_literal: true
module Praxis
module PluginConcern
extend ::ActiveSupport::Concern
included do
@setup = false
end
module ClassMethods
PLUGIN_CLASSES = %i[
Request
Controller
EndpointDefinition
ActionDefinition
Response
ApiGen... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/plugin.rb | Ruby | mit | 302 | master | 815 | # frozen_string_literal: true
module Praxis
# one instance is created per use.
class Plugin
attr_accessor :application, :block, :config, :config_attribute
def options
@options ||= {}
end
def config_key; end
def prepare_config!(node); end
def load_config!
return unless option... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/validation_handler.rb | Ruby | mit | 302 | master | 353 | # frozen_string_literal: true
module Praxis
class ValidationHandler
# Should return the Response to send back
def handle!(summary:, errors: nil, exception: nil, **opts)
opts.delete(:request)
opts.delete(:stage)
Responses::ValidationError.new(summary: summary, errors: errors, exception: exce... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/field_expander.rb | Ruby | mit | 302 | master | 3,873 | # frozen_string_literal: true
module Praxis
class FieldExpander
def self.expand(object, fields = true, displayable_filter = nil)
# check the displayability of the whole type/attr object at the top as well, not just the inner ones
if (privs = object.options[:displayable])
raise 'Attempting to ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/action_definition.rb | Ruby | mit | 302 | master | 13,198 | # frozen_string_literal: true
# A RESTful action allows you to define the following:
# - a payload structure
# - a params structure
# - the response MIME type
# - the return code/s ?
#
# Plugins may be used to extend this Config DSL.
#
module Praxis
class ActionDefinition
attr_reader :endpoint_definition, :api_... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/file_group.rb | Ruby | mit | 302 | master | 949 | # frozen_string_literal: true
module Praxis
class FileGroup
attr_reader :groups, :base
def initialize(base, &block)
if base.nil?
raise ArgumentError, 'base must not be nil.' \
'Are you missing a call Praxis::Application.instance.setup?'
end
@groups = {}
@base = Pat... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/renderer.rb | Ruby | mit | 302 | master | 2,515 | # frozen_string_literal: true
module Praxis
class Renderer
attr_reader :include_nil, :cache
class CircularRenderingError < StandardError
attr_reader :object, :context
def initialize(object, context)
@object = object
@context = context
first = Attributor.humanize_context... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/collection.rb | Ruby | mit | 302 | master | 1,016 | # frozen_string_literal: true
module Praxis
class Collection < Attributor::Collection
include Types::MediaTypeCommon
def self.of(type)
return type::Collection if defined?(type::Collection)
klass = super
klass.anonymous_type
raise 'Praxis::Collection.of() for non-MediaTypes is unsup... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/dispatcher.rb | Ruby | mit | 302 | master | 3,275 | # frozen_string_literal: true
module Praxis
CONTEXT_FOR = {
params: [Attributor::ROOT_PREFIX, 'params'],
headers: [Attributor::ROOT_PREFIX, 'headers'],
payload: [Attributor::ROOT_PREFIX, 'payload']
}.freeze
class Dispatcher
attr_reader :controller, :action, :request, :application
@deferred_... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/callbacks.rb | Ruby | mit | 302 | master | 1,002 | # frozen_string_literal: true
module Praxis
module Callbacks
extend ::ActiveSupport::Concern
included do
class_attribute :before_callbacks, :after_callbacks, :around_callbacks
self.before_callbacks = ({})
self.after_callbacks = ({})
self.around_callbacks = ({})
end
module Cl... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/stage.rb | Ruby | mit | 302 | master | 2,041 | # frozen_string_literal: true
module Praxis
class Stage
attr_reader :name, :context, :stages, :before_callbacks, :after_callbacks
def application
context
end
def initialize(name, context, **_opts)
@name = name
@context = context
@before_callbacks = []
@after_callbacks ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/resource_definition.rb | Ruby | mit | 302 | master | 207 | # frozen_string_literal: true
raise "ResourceDefinition class has changed name in this version of Praxis.\n" \
'Please blanket-replace all uses of ResourceDefinition with EndpointDefinition instead.' |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader.rb | Ruby | mit | 302 | master | 3,889 | # frozen_string_literal: true
module Praxis
class Bootloader
attr_reader :application, :stages
def initialize(application)
@application = application
@stages = []
setup_stages!
end
def config
@application.config
end
def root
@application.root
end
def... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/blueprint_attribute_group.rb | Ruby | mit | 302 | master | 737 | # frozen_string_literal: true
module Praxis
class BlueprintAttributeGroup < Blueprint
def self.constructable?
true
end
# Construct a new subclass, using attribute_definition to define attributes.
def self.construct(attribute_definition, options = {})
return self if attribute_definition.n... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/controller.rb | Ruby | mit | 302 | master | 1,091 | # frozen_string_literal: true
require 'active_support/concern'
require 'active_support/all'
module Praxis
module Controller
extend ::ActiveSupport::Concern
# A Controller always requires the callbacks
include Praxis::Callbacks
included do
attr_reader :request
attr_accessor :response
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/api_general_info.rb | Ruby | mit | 302 | master | 3,935 | # frozen_string_literal: true
module Praxis
class ApiGeneralInfo
attr_reader :version
def initialize(global_info = nil, version: nil)
@data = {}
@global_info = global_info
@version = version
return unless @global_info.nil?
# this *is* the global info
version_with %i[hea... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/trait.rb | Ruby | mit | 302 | master | 2,740 | # frozen_string_literal: true
module Praxis
class Trait
attr_reader :name, :attribute_groups
def initialize(&block)
@name = nil
@description = nil
@responses = {}
@routing = nil
@other = []
@attribute_groups = Hash.new do |h, k|
h[k] = []
end
instanc... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/config_hash.rb | Ruby | mit | 302 | master | 918 | # frozen_string_literal: true
# TODO: move to Praxis proper...it's not used here
module Praxis
class ConfigHash < BasicObject
attr_reader :hash
def self.from(hash = {}, &block)
new(hash, &block)
end
def initialize(hash = {}, &block)
@hash = hash
@block = block
end
def to_... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/endpoint_definition.rb | Ruby | mit | 302 | master | 8,934 | # frozen_string_literal: true
require 'active_support/concern'
require 'active_support/inflector'
module Praxis
module EndpointDefinition
extend ActiveSupport::Concern
DEFAULT_RESOURCE_HREF_ACTION = :show
included do
@version = 'n/a'
@actions = {}
@responses = {}
@action_defau... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/blueprint.rb | Ruby | mit | 302 | master | 13,293 | # frozen_string_literal: true
module Praxis
class Blueprint
class DSLCompiler < Attributor::HashDSLCompiler
# group DSL is meant to group a subset of attributes in the media type (instead of presenting all things flat)
# It will create a normal attribute, but as a BlueprintAttributeGroup, rather than... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/simple_media_type.rb | Ruby | mit | 302 | master | 585 | # frozen_string_literal: true
module Praxis
# Stripped-down representation of an Internet Media Type where the structure and content of the
# type are unknown, or are defined externally to the Praxis application.
#
# @see Praxis::MediaType
# @see Praxis::Types::MediaTypeCommon
SimpleMediaType = Struct.new(... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/api_definition.rb | Ruby | mit | 302 | master | 2,835 | # frozen_string_literal: true
require 'singleton'
require 'forwardable'
module Praxis
class ApiDefinition
include Singleton
extend Forwardable
attr_reader :traits, :responses, :infos, :global_info
attr_accessor :versioning_scheme
def self.define(&block)
if block.arity.zero?
inst... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/response_definition.rb | Ruby | mit | 302 | master | 8,840 | # frozen_string_literal: true
module Praxis
# Response spec DSL container
class ResponseDefinition
attr_reader :name
def initialize(response_name, **spec, &block)
raise Exceptions::InvalidConfiguration, 'Response name is required for a response specification' unless response_name
@spec = { h... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/finalizable.rb | Ruby | mit | 302 | master | 641 | # frozen_string_literal: true
module Praxis
module Finalizable
def self.extended(klass)
klass.module_eval do
@finalizable = Set.new
end
end
def inherited(base)
@finalizable << base
base.instance_variable_set(:@finalizable, @finalizable)
base.instance_variable_set(:@... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/notifications.rb | Ruby | mit | 302 | master | 908 | # frozen_string_literal: true
require 'active_support/notifications'
require 'singleton'
module Praxis
module Notifications
include Praxis::PluginConcern
class Plugin < Praxis::Plugin
include Singleton
def config_key
:notifications # 'praxis.notifications'
end
end
def s... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/router.rb | Ruby | mit | 302 | master | 3,455 | # frozen_string_literal: true
require 'praxis/router/rack'
module Praxis
class Router
attr_reader :request_class, :application
class VersionMatcher
def initialize(target, version: 'n/a')
@target = target
@version = version
end
def call(request)
if request.version ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/middleware_app.rb | Ruby | mit | 302 | master | 1,136 | # frozen_string_literal: true
module Praxis
class MiddlewareApp
attr_reader :target
# Initialize the application instance with the desired args, and return the wrapping class.
def self.for(**args)
Class.new(self) do
@args = args
@setup_done = false
def self.name
'... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/config.rb | Ruby | mit | 302 | master | 2,488 | # frozen_string_literal: true
module Praxis
class Config
include Attributor::Type
attr_reader :attribute
def initialize
@attribute = Attributor::Attribute.new(Attributor::Struct) {}
@value = nil
end
# You can define the configuration in different ways
#
# Add a key to the t... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/error_handler.rb | Ruby | mit | 302 | master | 386 | # frozen_string_literal: true
module Praxis
class ErrorHandler
def handle!(request, error)
Application.instance.logger.error error.inspect
error.backtrace.each do |line|
Application.instance.logger.error line
end
response = Responses::InternalServerError.new(error: error)
r... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/media_type_identifier.rb | Ruby | mit | 302 | master | 8,462 | # frozen_string_literal: true
require 'set'
require 'active_support/core_ext/object/blank'
module Praxis
# Ruby object representation of an Internet Media Type Identifier as defined by
# RFC6838; also known as MIME types due to their origin in RFC2046 (the
# MIME specification).
class MediaTypeIdentifier < At... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/application.rb | Ruby | mit | 302 | master | 3,425 | # frozen_string_literal: true
require 'singleton'
require 'mustermann'
require 'logger'
module Praxis
# Setup the option early, since things like MediaTypes and EndpointDefinitions might need it
Attributor::Attribute.custom_option :displayable, Types::SplattableStringArray.of(String)
class Application
incl... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/routing_config.rb | Ruby | mit | 302 | master | 1,889 | # frozen_string_literal: true
module Praxis
class RoutingConfig
attr_reader :route, :version, :base
def initialize(version: 'n/a', base: '', prefix: [], &block)
@version = version
@base = base
@prefix_segments = Array(prefix)
@route = nil
instance_eval(&block) if block_given?... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/response_template.rb | Ruby | mit | 302 | master | 1,086 | # frozen_string_literal: true
module Praxis
class ResponseTemplate
attr_reader :name, :block
def initialize(response_name, &block)
@name = response_name
@block = block
end
def compile(action = nil, **args)
# Default media_type to the endpoint_definition one, if the block has it in... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/route.rb | Ruby | mit | 302 | master | 1,310 | # frozen_string_literal: true
module Praxis
class Route
attr_accessor :verb, :path, :version, :prefixed_path, :options
def initialize(verb, path, version = 'n/a', prefixed_path: nil, **options)
@verb = verb
@path = path
@version = version
@options = options
@prefixed_path = pre... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/request.rb | Ruby | mit | 302 | master | 6,110 | # frozen_string_literal: true
module Praxis
class Request < Praxis.request_superclass
attr_reader :env, :query
attr_accessor :route_params, :action, :headers, :params, :payload, :forwarded_from_action
PATH_VERSION_PREFIX = '/v'
CONTENT_TYPE_NAME = 'CONTENT_TYPE'
PATH_INFO_NAME = 'PATH_INFO'
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/response.rb | Ruby | mit | 302 | master | 3,382 | # frozen_string_literal: true
module Praxis
class Response
attr_reader :name, :parts
attr_accessor :status, :headers, :body, :request
class << self
attr_accessor :response_name, :status
end
def self.inherited(klass)
klass.response_name = klass.name.demodulize.underscore.to_sym
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/tasks/routes.rb | Ruby | mit | 302 | master | 2,165 | # frozen_string_literal: true
namespace :praxis do
desc 'List routes, format=json or table, default table'
task :routes, [:format] => [:environment] do |_t, args|
require 'terminal-table'
table = Terminal::Table.new title: 'Routes',
headings: %w[
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/tasks/api_docs.rb | Ruby | mit | 302 | master | 1,619 | # frozen_string_literal: true
namespace :praxis do
namespace :docs do
desc 'Generate OpenAPI 3 docs for a Praxis App'
task generate: [:environment] do |_t, _args|
require 'fileutils'
Praxis::Blueprint.caching_enabled = false
generator = Praxis::Docs::OpenApiGenerator.instance
generat... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/tasks/console.rb | Ruby | mit | 302 | master | 1,189 | # frozen_string_literal: true
namespace :praxis do
desc 'Run interactive REPL'
task :console do
# Use irb if available (which it almost always is).
require 'irb'
# Ensure that we save history just like normal IRB
require 'irb/ext/save-history'
Rake::Task['praxis:environment'].invoke
based... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/action_definition/headers_dsl_compiler.rb | Ruby | mit | 302 | master | 1,331 | # frozen_string_literal: true
module Praxis
class ActionDefinition
class HeadersDSLCompiler < Attributor::DSLCompiler
# it allows to define expectations on incoming headers. For example:
# header :X_SpecialCookie => implies the header is required
# header :X_Something, /m... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/router/simple.rb | Ruby | mit | 302 | master | 4,681 | # frozen_string_literal: true
# Originally from:
# https://github.com/rkh/mustermann/blob/500a603fffe0594ab842d72addcc449eedd6d5be/mustermann/lib/mustermann/router/simple.rb
# Copied here after its removal from Mustermann proper
require 'mustermann'
module Mustermann
module Router
# Simple pattern based router... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/router/rack.rb | Ruby | mit | 302 | master | 1,847 | # frozen_string_literal: true
# Originally from:
# https://github.com/rkh/mustermann/blob/500a603fffe0594ab842d72addcc449eedd6d5be/mustermann/lib/mustermann/router/rack.rb
# Copied here after its removal from Mustermann proper
require 'praxis/router/simple'
module Mustermann
module Router
# Simple pattern base... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/request_stages/response.rb | Ruby | mit | 302 | master | 724 | # frozen_string_literal: true
module Praxis
module RequestStages
class Response < RequestStage
def execute
response = controller.response
response.handle
if Application.instance.config.praxis.validate_responses == true
validate_body = Application.instance.config.praxis.v... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/request_stages/validate_params_and_headers.rb | Ruby | mit | 302 | master | 1,388 | # frozen_string_literal: true
module Praxis
module RequestStages
class ValidateParamsAndHeaders < RequestStage
attr_reader :parent
def initialize(name, context, parent:)
super
@parent = parent
end
def path
@path ||= (@parent.path + [name])
end
def ex... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/request_stages/validate_payload.rb | Ruby | mit | 302 | master | 1,038 | # frozen_string_literal: true
module Praxis
module RequestStages
class ValidatePayload < RequestStage
attr_reader :parent
def initialize(name, context, parent:)
super
@parent = parent
end
def path
@path ||= (@parent.path + [name])
end
def execute
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/request_stages/validate.rb | Ruby | mit | 302 | master | 424 | # frozen_string_literal: true
module Praxis
module RequestStages
class Validate < RequestStage
def initialize(name, context, **opts)
super
# Add our sub-stages
@stages = [
RequestStages::ValidateParamsAndHeaders.new(:params_and_headers, context, parent: self),
Re... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/request_stages/action.rb | Ruby | mit | 302 | master | 923 | # frozen_string_literal: true
module Praxis
module RequestStages
class Action < RequestStage
def execute
response = Notifications.instrument 'praxis.request_stage.execute', controller: controller do
if controller.method(action.name).arity.zero?
controller.__send__(action.name)... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/request_stages/request_stage.rb | Ruby | mit | 302 | master | 3,279 | # frozen_string_literal: true
module Praxis
module RequestStages
# Special Stage what will hijack the run and execute methods to:
# 1- Run specific controller callbacks (in addition to any normal callbacks)
# 2- Shortcut the controller callback chain if any returns a Response object
class RequestStag... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/responses/internal_server_error.rb | Ruby | mit | 302 | master | 1,285 | # frozen_string_literal: true
module Praxis
module Responses
# A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
class InternalServerError < Praxis::Response
self.status = 500
attr_accessor :error
def initialize(error: nil... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/responses/multipart_ok.rb | Ruby | mit | 302 | master | 957 | # frozen_string_literal: true
module Praxis
module Responses
class MultipartOk < Ok
def initialize(status: self.class.status, headers: {}, body: '')
@name = response_name
@status = status
@headers = headers
@body = body
end
def handle
case @body
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/responses/http.rb | Ruby | mit | 302 | master | 8,352 | # frozen_string_literal: true
module Praxis
module Responses
# Descriptions from http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
# Standard response for successful HTTP requests.
# The actual response will depend on the request method used.
# In a GET request, the response will contain an ent... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/responses/validation_error.rb | Ruby | mit | 302 | master | 1,225 | # frozen_string_literal: true
module Praxis
module Responses
class ValidationError < BadRequest
def initialize(summary:, errors: nil, exception: nil, documentation: nil, **opts)
super(**opts)
@headers['Content-Type'] = 'application/json' # TODO: might want an error mediatype
@errors... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/sequel_compat.rb | Ruby | mit | 302 | master | 3,171 | # frozen_string_literal: true
require 'active_support/concern'
module Praxis
module Mapper
module SequelCompat
extend ActiveSupport::Concern
included do
attr_accessor :_resource
class << self
alias_method :find_by, :find # Easy way to be method compatible with AR
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/active_model_compat.rb | Ruby | mit | 302 | master | 5,330 | # frozen_string_literal: true
require 'active_support/concern'
require 'praxis/extensions/field_selection/active_record_query_selector'
require 'praxis/extensions/attribute_filtering/active_record_filter_query_builder'
module Praxis
module Mapper
module ActiveModelCompat
extend ActiveSupport::Concern
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/resource.rb | Ruby | mit | 302 | master | 24,360 | # frozen_string_literal: true
# A resource creates a data store and instantiates a list of models that it wishes to load, building up the overall set of data that it will need.
# Once that is complete, the data set is iterated and a resultant view is generated.
module Praxis
module Mapper
class ResourceNotFound ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/selector_generator.rb | Ruby | mit | 302 | master | 14,858 | # frozen_string_literal: true
module Praxis
module Mapper
class SelectorGeneratorNode
# prepend SelectorGeneratorNodeDebugger # Uncomment this to see the traces of how methods are called
attr_reader :select, :model, :resource, :tracks, :fields_node
# FieldDependenciesNode, attached to a Select... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/resources/typed_methods.rb | Ruby | mit | 302 | master | 6,628 | # frozen_string_literal: true
module Praxis
module Mapper
module Resources
# Error raised when trying to call a typed method and the validation of arguments fails
class IncompatibleTypeForMethodArguments < ::StandardError
attr_reader :errors, :method
def initialize(errors:, method:, ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/resources/query_methods.rb | Ruby | mit | 302 | master | 903 | # frozen_string_literal: true
module Praxis
module Mapper
module Resources
module QueryMethods
extend ::ActiveSupport::Concern
# Includes some limited, but handy query methods so we can transparently
# use them from the resource layer, and get wrapped resources from it
modu... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/resources/callbacks.rb | Ruby | mit | 302 | master | 1,059 | # frozen_string_literal: true
module Praxis
module Mapper
module Resources
module Callbacks
extend ::ActiveSupport::Concern
included do
class_attribute :before_callbacks, :after_callbacks, :around_callbacks
self.before_callbacks = Hash.new { |h, method| h[method] = [] }... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/mapper/resources/query_proxy.rb | Ruby | mit | 302 | master | 1,734 | # frozen_string_literal: true
module Praxis
module Mapper
module Resources
class QueryProxy
attr_reader :klass
def initialize(klass:)
@klass = klass
end
def including(includes)
@_includes = includes
self
end
# Can pass extra i... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/plugins/pagination_plugin.rb | Ruby | mit | 302 | master | 4,227 | # frozen_string_literal: true
require 'singleton'
require 'praxis/extensions/pagination'
# The PaginationPlugin can be configured to take advantage of adding pagination and sorting to
# your DB queries.
# When combined with the MapperPlugin, there is no extra configuration that needs to be done for
# the system to ap... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/plugins/rails_plugin.rb | Ruby | mit | 302 | master | 3,472 | # frozen_string_literal: true
require 'praxis/plugin'
require 'praxis/plugin_concern'
module Praxis
module Plugins
module RailsPlugin
include Praxis::PluginConcern
class Plugin < Praxis::Plugin
def setup!
require 'praxis/dispatcher'
enable_action_controller_instrumentati... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/plugins/mapper_plugin.rb | Ruby | mit | 302 | master | 3,143 | # frozen_string_literal: true
require 'singleton'
require 'praxis/extensions/field_selection'
module Praxis
module Plugins
module MapperPlugin
include Praxis::PluginConcern
# The Mapper plugin is an overarching set of things to include in your application
# when you want to use the rendring,... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/exceptions/config_validation.rb | Ruby | mit | 302 | master | 215 | # frozen_string_literal: true
module Praxis
module Exceptions
class ConfigValidation < Config
def initialize(errors:)
super("Validation error: #{errors.join('; ')}")
end
end
end
end |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/exceptions/validation.rb | Ruby | mit | 302 | master | 249 | # frozen_string_literal: true
module Praxis
module Exceptions
class Validation < RuntimeError
attr_accessor :errors
def initialize(message, errors: nil)
super(message)
@errors = errors
end
end
end
end |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/types/fuzzy_hash.rb | Ruby | mit | 302 | master | 831 | # frozen_string_literal: true
module Praxis
module Types
class FuzzyHash
def initialize(value = {})
@hash = {}
@regexes = []
update(value)
end
def update(value)
value.each do |key, val|
self[key] = val
end
self
end
def []=... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/types/media_type_common.rb | Ruby | mit | 302 | master | 1,162 | # frozen_string_literal: true
module Praxis
module Types
# Traits that are shared by MediaType and SimpleMediaType.
module MediaTypeCommon
extend ::ActiveSupport::Concern
module ClassMethods
def as_json_schema(**args)
the_type = @attribute&.type || member_type
the_typ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/types/multipart_array.rb | Ruby | mit | 302 | master | 13,121 | # frozen_string_literal: true
require 'praxis/types/multipart_array/part_definition'
module Praxis
module Types
class MultipartArray < Attributor::Collection
include Types::MediaTypeCommon
@member_type = Praxis::MultipartPart
@payload_type = Attributor::String
@name_type = Attributor::S... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/types/splattable_string_array.rb | Ruby | mit | 302 | master | 387 | # frozen_string_literal: true
module Praxis
module Types
class SplattableStringArray < Attributor::Collection
# Make a type, to allow to load the value, as s single string, if it isn't a numerable
# This way we can do displayable: 'foobar' , or displayable: ['one', 'two']
def self.decode_string... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/types/multipart_array/part_definition.rb | Ruby | mit | 302 | master | 1,711 | # frozen_string_literal: true
module Praxis
module Types
class MultipartArray < Attributor::Collection
class PartDefinition
attr_accessor :payload_attribute, :headers_attribute, :filename_attribute
def initialize(&block)
instance_eval(&block)
end
def update_attri... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/handlers/www_form.rb | Ruby | mit | 302 | master | 1,003 | # frozen_string_literal: true
# This is an example of a handler that can load and generate www-url-encoded payloads.
# Note that if you use your API to pass nil values for attributes as a way to unset their
# values, this handler will not work (as there isn't necessarily a defined "null" value in
# this encoding (alth... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/handlers/plain.rb | Ruby | mit | 302 | master | 245 | # frozen_string_literal: true
module Praxis
module Handlers
class Plain
# no-op
def parse(entity)
entity
end
# no-op
def generate(structured_data)
structured_data
end
end
end
end |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/handlers/xml_sample.rb | Ruby | mit | 302 | master | 2,983 | # frozen_string_literal: true
# This is an example of a handler that can load and generate 'activesupport-style' xml payloads.
# Note that if you use your API to pass nil values for attributes as a way to unset their values,
# this handler will not work (as there isn't necessarily a defined "null" value in this encod... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/handlers/json.rb | Ruby | mit | 302 | master | 1,186 | module Praxis
module Handlers
class JSON
# Construct a JSON handler and initialize any related libraries.
#
# @raise [Praxis::Exceptions::InvalidConfiguration] if the handler is unsupported
def initialize
require 'json'
rescue LoadError
# Should never happen since JSO... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/subgroup_loader.rb | Ruby | mit | 302 | master | 459 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class SubgroupLoader < Stage
attr_writer :order
def order
@order ||= application.file_layout[name] == [] ? [] : application.file_layout[name].groups.keys
end
def setup!
order.each do |group|
@s... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/plugin_config_prepare.rb | Ruby | mit | 302 | master | 476 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class PluginConfigPrepare < Stage
def execute
application.plugins.each do |config_key, plugin|
attribute = Attributor::Attribute.new(Attributor::Struct) {}
plugin.config_attribute = attribute
plugin.p... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/plugin_config_load.rb | Ruby | mit | 302 | master | 502 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class PluginConfigLoad < Stage
def execute
application.plugins.each do |config_key, plugin|
context = [plugin.class.name]
value = plugin.load_config!
object = plugin.config_attribute.load(value, contex... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/plugin_setup.rb | Ruby | mit | 302 | master | 241 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class PluginSetup < Stage
def execute
application.plugins.each do |_config_key, plugin|
plugin.setup!
end
end
end
end
end |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/plugin_loader.rb | Ruby | mit | 302 | master | 398 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class PluginLoader < Stage
def initialize(name, context, **opts)
super
stages << PluginConfigPrepare.new(:prepare, context, parent: self)
stages << PluginConfigLoad.new(:load, context, parent: self)
stages ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/file_loader.rb | Ruby | mit | 302 | master | 592 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class FileLoader < Stage
attr_reader :path
def initialize(name, application, path: nil)
super
@path = path || Array(name)
end
def execute
application.file_layout[*path].each do |file|
n... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/warn_unloaded_files.rb | Ruby | mit | 302 | master | 964 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class WarnUnloadedFiles < Stage
@enabled = true
class << self
attr_writer :enabled
end
class << self
attr_reader :enabled
end
def execute
return unless self.class.enabled
re... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/environment.rb | Ruby | mit | 302 | master | 1,833 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class Environment < Stage
# require environment files. we will require 2 files:
# 1) the environment.rb file - generic stuff for all environments
# 2) "Deployer.environment".rb - environment specific stuff
def execute... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/bootloader_stages/routing.rb | Ruby | mit | 302 | master | 1,303 | # frozen_string_literal: true
module Praxis
module BootloaderStages
class Routing < Stage
class Target
attr_reader :action
def initialize(application, controller, action)
@application = application
@controller = controller
@action = action
end
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/pagination.rb | Ruby | mit | 302 | master | 4,270 | # frozen_string_literal: true
begin
require 'link_header'
rescue LoadError
warn "Praxis::Pagination requires the 'link_header' gem, which can not be found. " \
"Please make sure it's in your Gemfile or installed in your system."
end
require 'praxis/extensions/pagination/pagination_params'
require 'praxis/ex... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/field_expansion.rb | Ruby | mit | 302 | master | 891 | # frozen_string_literal: true
module Praxis
module Extensions
module FieldExpansion
extend ActiveSupport::Concern
included do
Praxis::ActionDefinition.include ActionDefinitionExtension
end
def expanded_fields
@expanded_fields ||=
begin
expansion_fil... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/rendering.rb | Ruby | mit | 302 | master | 1,466 | # frozen_string_literal: true
module Praxis
module Extensions
module Rendering
extend ActiveSupport::Concern
include FieldExpansion
def render(object, include_nil: false)
loaded = media_type.load(object)
renderer = Praxis::Renderer.new(include_nil: include_nil)
renderer... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering.rb | Ruby | mit | 302 | master | 567 | # frozen_string_literal: true
require 'praxis/extensions/attribute_filtering/filtering_params'
require 'praxis/extensions/attribute_filtering/filter_tree_node'
module Praxis
module Extensions
module AttributeFiltering
class MultiMatchWithFuzzyNotAllowedByAdapter < StandardError
def initialize
... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/field_selection/sequel_query_selector.rb | Ruby | mit | 302 | master | 2,050 | # frozen_string_literal: true
require 'sequel'
module Praxis
module Extensions
module FieldSelection
class SequelQuerySelector
attr_reader :selector, :query
# Gets a dataset, a selector...and should return a dataset with the selector definition applied.
def initialize(query:, sele... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/field_selection/field_selector.rb | Ruby | mit | 302 | master | 3,452 | # frozen_string_literal: true
module Praxis
module Extensions
module FieldSelection
class FieldSelector
include Attributor::Type
include Attributor::Dumpable
def self.json_schema_type
:string
end
def self.native_type
self
end
de... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/field_selection/active_record_query_selector.rb | Ruby | mit | 302 | master | 3,668 | # frozen_string_literal: true
module Praxis
module Extensions
module FieldSelection
class ActiveRecordQuerySelector
attr_reader :selector, :query
# Gets a dataset, a selector...and should return a dataset with the selector definition applied.
def initialize(query:, selectors:, debu... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/filtering_params.rb | Ruby | mit | 302 | master | 12,374 | # frozen_string_literal: true
require 'praxis/extensions/attribute_filtering/filters_parser'
#
# Attributor type to define and handle the language to express filtering attributes in listings.
# Commonly used in a query string parameter value for listing calls.
#
# The type allows you to restrict the allowable fields ... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/active_record_patches.rb | Ruby | mit | 302 | master | 367 | # frozen_string_literal: true
require 'active_record'
if ActiveRecord.gem_version < Gem::Version.new('6')
require_relative 'active_record_patches/5x'
elsif ActiveRecord.gem_version < Gem::Version.new('6.1')
require_relative 'active_record_patches/6_0'
else
# As of 7.0.4 our 6.1-plus patches still work
require... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/sequel_filter_query_builder.rb | Ruby | mit | 302 | master | 5,602 | # frozen_string_literal: true
# rubocop:disable all
module Praxis
module Extensions
class SequelFilterQueryBuilder
attr_reader :query, :root
# Abstract class, which needs to be used by subclassing it through the .for method, to set the mapping of attributes
class << self
def for(definit... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb | Ruby | mit | 302 | master | 17,938 | # frozen_string_literal: true
module Praxis
module Extensions
module AttributeFiltering
ALIAS_TABLE_PREFIX = ''
require_relative 'active_record_patches'
# Helper class that can present an SqlLiteral string which we have already quoted
# ... but! that can properly provide a "to_sym" that h... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/filters_parser.rb | Ruby | mit | 302 | master | 7,638 | # frozen_string_literal: true
require 'parslet'
module Praxis
module Extensions
module AttributeFiltering
class FilteringParams
class Condition
attr_reader :name, :op, :values
attr_accessor :parent_group
# For operands with a single or no values: Incoming data is a h... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/filter_tree_node.rb | Ruby | mit | 302 | master | 1,602 | # frozen_string_literal: true
module Praxis
module Extensions
module AttributeFiltering
class FilterTreeNode
attr_reader :path, :conditions, :children
# Parsed_filters is an Array of {name: X, op: Y, value: Z} ... exactly the format of the FilteringParams.load method
def initialize... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb | Ruby | mit | 302 | master | 2,423 | # frozen_string_literal: true
# rubocop:disable all
# FOR AR >= 6.1
module ActiveRecord
PRAXIS_JOIN_ALIAS_PREFIX = Praxis::Extensions::AttributeFiltering::ALIAS_TABLE_PREFIX
module Associations
class JoinDependency
private
def make_constraints(parent, child, join_type)
foreign_table = pare... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb | Ruby | mit | 302 | master | 2,675 | # frozen_string_literal: true
# rubocop:disable all
# FOR AR < 6.1
module ActiveRecord
PRAXIS_JOIN_ALIAS_PREFIX = Praxis::Extensions::AttributeFiltering::ALIAS_TABLE_PREFIX
class Relation
def construct_join_dependency(associations, join_type) # :nodoc:
# Praxis: inject references into the join dependency... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb | Ruby | mit | 302 | master | 3,492 | # frozen_string_literal: true
# rubocop:disable all
require 'active_record'
module ActiveRecord
PRAXIS_JOIN_ALIAS_PREFIX = Praxis::Extensions::AttributeFiltering::ALIAS_TABLE_PREFIX
class Relation
def construct_join_dependency
including = eager_load_values + includes_values
# Praxis: inject refere... |
github | praxis/praxis | https://github.com/praxis/praxis | lib/praxis/extensions/pagination/pagination_params.rb | Ruby | mit | 302 | master | 15,806 | # frozen_string_literal: true
module Praxis
module Extensions
module Pagination
class PaginationParams
include Attributor::Type
include Attributor::Dumpable
# Pagination type that allows you to define a parameter type in an endpoint, including a DSL to restrict or configure
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.