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
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/presenter.rb
Ruby
mit
202
master
6,206
require 'brainstem/api_docs' require 'brainstem/concerns/optional' require 'brainstem/concerns/formattable' require 'forwardable' require 'active_support/inflector' # # Wrapper for common presenter information lookups. # module Brainstem module ApiDocs class Presenter extend Forwardable include Conce...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/resolver.rb
Ruby
mit
202
master
1,821
require 'brainstem/concerns/optional' # # The Resolver is responsible for taking a non-ApiDocs class and turning it # into an ApiDocs wrapper class (such as a Presenter, Controller, or Endpoint). # # It's useful for doing object lookups for associated objects where we only # have the original class or constant to look...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/endpoint.rb
Ruby
mit
202
master
9,854
require 'brainstem/concerns/optional' require 'active_support/core_ext/string/inflections' require 'brainstem/concerns/formattable' require 'forwardable' require 'pathname' # # Per-endpoint holder for presenter and controller information. # module Brainstem module ApiDocs class Endpoint extend Forwardable ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/presenter_collection.rb
Ruby
mit
202
master
3,003
require 'active_support/inflector/inflections' require 'brainstem/api_docs/abstract_collection' require 'brainstem/api_docs/presenter' require 'brainstem/concerns/formattable' module Brainstem module ApiDocs class PresenterCollection < AbstractCollection include Concerns::Formattable def valid_optio...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/exceptions.rb
Ruby
mit
202
master
320
module Brainstem module ApiDocs class IncorrectIntrospectorForAppException < StandardError; end class InvalidIntrospectorError < StandardError; end class InvalidAtlasError < StandardError; end class NoSinkSpecifiedException < StandardError; end end end
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/introspectors/rails_introspector.rb
Ruby
mit
202
master
9,104
require 'brainstem/api_docs/introspectors/abstract_introspector' require 'brainstem/api_docs/exceptions' # For 'constantize' require 'active_support/inflector/methods' module Brainstem module ApiDocs module Introspectors class RailsIntrospector < AbstractIntrospector # # Loads ./config/en...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/introspectors/abstract_introspector.rb
Ruby
mit
202
master
2,917
require 'brainstem/concerns/optional' module Brainstem module ApiDocs module Introspectors class AbstractIntrospector include Brainstem::Concerns::Optional def valid_options [ ] end # Returns a new instance of the introspector with the environment # loade...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/abstract_formatter.rb
Ruby
mit
202
master
1,972
require 'brainstem/api_docs' require 'brainstem/api_docs/exceptions' require 'brainstem/concerns/optional' # # A formatter is fundamentally just a function that, when +#call+ed, accepts an # atlas and returns the whole or portion of its data in a readable format. # # There are (informally) several types of formatters,...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/helper.rb
Ruby
mit
202
master
2,771
module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Helper def presenter_title(presenter) presenter.contextual_documentation(:title).presence || presenter.target_class.underscore.singularize.titleize.strip end ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/controller_formatter.rb
Ruby
mit
202
master
1,567
require 'brainstem/api_docs/formatters/abstract_formatter' module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 class ControllerFormatter < AbstractFormatter # # Declares the options that are permissable to set on this inst...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/tags_formatter.rb
Ruby
mit
202
master
4,042
require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/open_api_specification/helper' module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 class TagsFormatter < AbstractFormatter include Helper...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_formatter.rb
Ruby
mit
202
master
5,300
require 'active_support/core_ext/hash/except' require 'forwardable' require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/param_definitions_formatter' require 'brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/re...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb
Ruby
mit
202
master
4,674
require 'active_support/core_ext/string/inflections' require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/open_api_specification/helper' require 'brainstem/api_docs/formatters/open_api_specification/version_2/field_definitions/presenter_field_formatter' module Brainstem m...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/info_formatter.rb
Ruby
mit
202
master
3,744
require 'brainstem/api_docs/formatters/abstract_formatter' module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 class InfoFormatter < AbstractFormatter # # Declares the options that are permissable to set on this instance. ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/security_definitions_formatter.rb
Ruby
mit
202
master
2,995
require 'brainstem/api_docs/formatters/abstract_formatter' module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 class SecurityDefinitionsFormatter < AbstractFormatter attr_accessor :output def initialize(options = {}) ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint_collection_formatter.rb
Ruby
mit
202
master
1,760
require 'brainstem/api_docs/formatters/abstract_formatter' # # Responsible for formatting each endpoint. # module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 class EndpointCollectionFormatter < AbstractFormatter attr_accessor :endpoi...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/field_definitions/endpoint_param_formatter.rb
Ruby
mit
202
master
1,444
require 'brainstem/api_docs/formatters/open_api_specification/version_2/field_definitions/response_field_formatter' module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 module FieldDefinitions class EndpointParamFormatter < ResponseFiel...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/field_definitions/response_field_formatter.rb
Ruby
mit
202
master
5,937
require 'brainstem/api_docs' require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/open_api_specification/helper' module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 module FieldDefinitions c...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/field_definitions/presenter_field_formatter.rb
Ruby
mit
202
master
5,535
require 'brainstem/api_docs' require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/open_api_specification/helper' module Brainstem module ApiDocs module Formatters module OpenApiSpecification module Version2 module FieldDefinitions c...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/response_definitions_formatter.rb
Ruby
mit
202
master
6,538
require 'active_support/core_ext/hash/except' require 'active_support/inflector' require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/open_api_specification/helper' require 'brainstem/api_docs/formatters/open_api_specification/version_2/field_definitions/response_field_forma...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/open_api_specification/version_2/endpoint/param_definitions_formatter.rb
Ruby
mit
202
master
11,023
require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/compact' require 'active_support/inflector' require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/open_api_specification/helper' require 'brainstem/api_docs/formatters/open_api_specification/v...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/markdown/helper.rb
Ruby
mit
202
master
1,494
# This is a very simple DSL that makes generating a markdown document a bit # easier. module Brainstem module ApiDocs module Formatters module Markdown module Helper def md_h1(text) "# #{text}\n\n" end def md_h2(text) "## #{text}\n\n" ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/markdown/endpoint_formatter.rb
Ruby
mit
202
master
6,760
require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/markdown/helper' require 'active_support/core_ext/hash/except' require 'forwardable' # # Responsible for formatting each endpoint. # module Brainstem module ApiDocs module Formatters module Markdown cl...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter.rb
Ruby
mit
202
master
1,847
require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/markdown/helper' # # Responsible for formatting each endpoint. # module Brainstem module ApiDocs module Formatters module Markdown class EndpointCollectionFormatter < AbstractFormatter includ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/markdown/presenter_formatter.rb
Ruby
mit
202
master
6,529
require 'active_support/core_ext/string/inflections' require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/markdown/helper' module Brainstem module ApiDocs module Formatters module Markdown class PresenterFormatter < AbstractFormatter include He...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/formatters/markdown/controller_formatter.rb
Ruby
mit
202
master
1,889
require 'brainstem/api_docs/formatters/abstract_formatter' require 'brainstem/api_docs/formatters/markdown/helper' module Brainstem module ApiDocs module Formatters module Markdown class ControllerFormatter < AbstractFormatter include Helper # # Declares the options t...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb
Ruby
mit
202
master
2,200
require 'brainstem/api_docs/sinks/abstract_sink' require 'fileutils' require 'forwardable' module Brainstem module ApiDocs module Sinks class ControllerPresenterMultifileSink < AbstractSink extend Forwardable delegate [:controllers, :presenters] => :atlas def <<(atlas) s...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/sinks/stdout_sink.rb
Ruby
mit
202
master
931
require 'brainstem/api_docs/sinks/abstract_sink' module Brainstem module ApiDocs module Sinks class StdoutSink < AbstractSink # # Writes the output using stdout.puts. # def <<(output) puts_method.call(output) end ##################################...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/sinks/abstract_sink.rb
Ruby
mit
202
master
769
require 'brainstem/concerns/optional' module Brainstem module ApiDocs module Sinks class AbstractSink include Concerns::Optional # # Primary method for putting the atlas into the sink. # # @param [Brainstem::ApiDocs::Atlas] the atlas # def <<(atlas) ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/api_docs/sinks/open_api_specification_sink.rb
Ruby
mit
202
master
7,029
require 'brainstem/api_docs' require 'brainstem/api_docs/formatters/open_api_specification/helper' require 'brainstem/api_docs/sinks/abstract_sink' require 'fileutils' require 'forwardable' module Brainstem module ApiDocs module Sinks class OpenApiSpecificationSink < AbstractSink include Brainstem:...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/controller_param_management.rb
Ruby
mit
202
master
1,117
require 'active_support/concern' require 'active_support/inflector' # Provide `brainstem_model_name` and `brainstem_plural_model_name` in # controllers for use when accessing the `params` hash. module Brainstem module Concerns module ControllerParamManagement extend ActiveSupport::Concern def brain...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/presenter_dsl.rb
Ruby
mit
202
master
7,460
require 'brainstem/concerns/inheritable_configuration' require 'brainstem/dsl/association' require 'brainstem/dsl/field' require 'brainstem/dsl/array_block_field' require 'brainstem/dsl/hash_block_field' require 'brainstem/dsl/conditional' require 'brainstem/dsl/base_block' require 'brainstem/dsl/conditionals_block' r...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/error_presentation.rb
Ruby
mit
202
master
2,572
module Brainstem module Concerns module ErrorPresentation extend ActiveSupport::Concern # Given one or more error messages, return Brainstem-style errors, defaulting to type 'system'. def brainstem_system_error(*messages) options = messages.last.is_a?(Hash) ? messages.pop : {} r...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/formattable.rb
Ruby
mit
202
master
698
require 'brainstem/api_docs' require 'active_support/inflector/inflections' module Brainstem module Concerns module Formattable attr_writer :formatters def valid_options super | [ :formatters ] end def formatters @formatters ||= ::Brainstem::ApiDocs::FORMATTERS[formatter...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/controller_dsl.rb
Ruby
mit
202
master
27,413
require 'brainstem/concerns/inheritable_configuration' require 'active_support/core_ext/object/with_options' module Brainstem module Concerns module ControllerDSL extend ActiveSupport::Concern include Brainstem::Concerns::InheritableConfiguration DEFAULT_BRAINSTEM_PARAMS_CONTEXT = :_default ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/inheritable_configuration.rb
Ruby
mit
202
master
653
require 'active_support/concern' require 'brainstem/dsl/configuration' module Brainstem module Concerns module InheritableConfiguration extend ActiveSupport::Concern module ClassMethods def configuration @configuration ||= begin if superclass.respond_to?(:configuration)...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/lookup.rb
Ruby
mit
202
master
1,083
module Brainstem module Concerns module Lookup extend ActiveSupport::Concern def run_on_with_lookup(model, context, helper_instance) context[:lookup][key_for_lookup][name] ||= begin proc = options[:lookup] lookup = helper_instance.instance_exec(context[:models], &proc) ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/concerns/optional.rb
Ruby
mit
202
master
1,288
# # This module is used in lieu of an dependency on optional kwargs. Any symbol # included in the array of +#valid_options+ will be whitelisted from passed # options and sent to the instance on initialization. # # In this simple way, we can make classes accept options, whitelist which # are acceptable, and set them wit...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/cli/generate_api_docs_command.rb
Ruby
mit
202
master
7,566
require 'brainstem/cli/abstract_command' require 'brainstem/api_docs' require 'brainstem/api_docs/exceptions' require 'brainstem/api_docs/builder' # # Require all sinks and formatters. # sinks_path = File.expand_path('../../api_docs/sinks/**/*.rb', __FILE__) formatters_path = File.expand_path('../../api_docs/formatter...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/cli/abstract_command.rb
Ruby
mit
202
master
2,488
require 'optparse' # # A Command is a callable object that acts as an entrypoint into the # application logic. It is responsible for translating given options into # specific enquiries. # # Internally, it wraps an OptionParser instance returned through its # +option_parser` method. The evaluation of this parser mutate...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/query_strategies/filter_and_search.rb
Ruby
mit
202
master
2,575
module Brainstem module QueryStrategies class FilterAndSearch < BaseStrategy def execute(scope) scope, ordered_search_ids = run_search(scope, filter_includes.map(&:name)) scope = primary_presenter.apply_filters_to_scope(scope, @options[:params], @options) if ordering? coun...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/query_strategies/filter_or_search.rb
Ruby
mit
202
master
2,701
module Brainstem module QueryStrategies class FilterOrSearch < BaseStrategy def execute(scope) if searching? # Search sort_name, direction = primary_presenter.calculate_sort_name_and_direction @options[:params] scope, count, ordered_search_ids = run_search(scope, filter...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/query_strategies/base_strategy.rb
Ruby
mit
202
master
2,481
module Brainstem module QueryStrategies class NotImplemented < StandardError end class BaseStrategy def initialize(options) @options = options end def execute(scope) raise NotImplemented, 'Your strategy class must implement an `execute` method' end def calc...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/query_strategies/data_mapper.rb
Ruby
mit
202
master
290
module Brainstem module QueryStrategies class DataMapper def get_models(ids:, scope:) id_lookup = {} ids.each.with_index { |id, index| id_lookup[id] = index } scope.klass.where(id: ids).sort_by { |model| id_lookup[model.id] } end end end end
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/query_strategies/paginator.rb
Ruby
mit
202
master
1,597
module Brainstem module QueryStrategies class Paginator attr_reader :pagination_strategy, :primary_presenter def initialize(primary_presenter:) @primary_presenter = primary_presenter @cached_count = nil end def get_ids(scope:, limit:, offset:) scope = scope.limit(...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/hash_block_field.rb
Ruby
mit
202
master
908
require 'brainstem/dsl/configuration' require 'brainstem/dsl/block_field' module Brainstem module DSL class HashBlockField < BlockField def run_on(model, context, helper_instance = Object.new) evaluated_model = nil evaluated_model = evaluate_value_on(model, context, helper_instance) if exec...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/configuration.rb
Ruby
mit
202
master
9,363
require 'active_support/hash_with_indifferent_access' require 'forwardable' # A hash-like object that accepts a parent configuration object that defers to # the parent in the absence of one of its own keys (thus simulating inheritance). module Brainstem module DSL class Configuration extend Forwardable ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/base_block.rb
Ruby
mit
202
master
811
module Brainstem module Concerns module PresenterDSL class BaseBlock attr_accessor :configuration, :block_options def initialize(configuration, block_options = {}, &block) @configuration = configuration @block_options = block_options block.arity < 1 ? self.inst...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/associations_block.rb
Ruby
mit
202
master
381
module Brainstem module Concerns module PresenterDSL class AssociationsBlock < BaseBlock def association(name, target_class, options = {}) configuration[:associations][name] = DSL::Association.new( name, target_class, block_options.merge(format_options(o...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/association.rb
Ruby
mit
202
master
1,478
require 'brainstem/concerns/lookup' module Brainstem module DSL class Association include Brainstem::Concerns::Lookup attr_reader :name, :target_class, :options def initialize(name, target_class, options) @name = name.to_s @target_class = target_class @options = option...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/fields_block.rb
Ruby
mit
202
master
1,628
module Brainstem module Concerns module PresenterDSL class FieldsBlock < BaseBlock def field(name, type, options = {}) configuration[name] = DSL::Field.new(name, type, smart_merge(block_options, format_options(options))) end def fields(name, type = :hash, options = {}, &bl...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/array_block_field.rb
Ruby
mit
202
master
723
require 'brainstem/dsl/configuration' require 'brainstem/dsl/block_field' module Brainstem module DSL class ArrayBlockField < BlockField def run_on(model, context, helper_instance = Object.new) evaluated_models = evaluate_value_on(model, context, helper_instance) evaluated_models.map do |e...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/conditional.rb
Ruby
mit
202
master
879
module Brainstem module DSL class Conditional attr_reader :name, :type, :action, :options def initialize(name, type, action, options = {}) @name = name @type = type @action = action @options = options end def description options[:info].presence ...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/conditionals_block.rb
Ruby
mit
202
master
480
module Brainstem module Concerns module PresenterDSL class ConditionalsBlock < BaseBlock def request(name, action, options = {}) configuration[:conditionals][name] = DSL::Conditional.new(name, :request, action, format_options(options)) end def model(name, action, options =...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/block_field.rb
Ruby
mit
202
master
2,024
require 'brainstem/dsl/configuration' require 'brainstem/dsl/field' module Brainstem module DSL class BlockField < Field attr_reader :configuration delegate :to_h, :keys, :has_key?, :each, to: :configuration def initialize(name, type, options, parent_field = nil) super(name, type, opt...
github
mavenlink/brainstem
https://github.com/mavenlink/brainstem
lib/brainstem/dsl/field.rb
Ruby
mit
202
master
2,218
require 'brainstem/concerns/lookup' module Brainstem module DSL class Field include Brainstem::Concerns::Lookup attr_reader :name, :type, :conditionals, :options def initialize(name, type, options) @name = name.to_s @type = type.to_s @conditionals = [options[:if]].flat...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
Gemfile
Ruby
mit
202
master
1,200
source 'https://rubygems.org' gem 'rails', '7.1.3.2' gem 'activerecord-session_store' gem 'ansi' gem 'bootstrap' gem 'countries', require: 'countries/global' gem 'devise' gem 'dotenv-rails' gem 'font-awesome-rails' gem 'httparty' gem 'jbuilder' gem 'mysql2' gem 'omniauth' gem 'omniauth-google-oauth2' gem 'paranoia' g...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/lib/saml_app.rb
Ruby
mit
202
master
805
class SamlApp attr_accessor :config, :app_name def initialize(org_id) @config = SamlAppConfig.find_or_initialize_by( app_name: @app_name, organisation_id: org_id ) end def save_config(sso_url, config = {}) unless @config.persisted? group_name = "#{@config.organisation.slug}_saml_#{app...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/lib/datadog.rb
Ruby
mit
202
master
851
class Datadog < SamlApp def initialize(org_id) @app_name = 'datadog' super(org_id) if @config.persisted? @client = DataDogClient.new( @config.config['app_key'], @config.config['api_key'] ) else @config.config = { app_key: '', api_key: '' } end end def save_c...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/api_resources_controller.rb
Ruby
mit
202
master
4,412
class ApiResourcesController < ApplicationController before_action :set_api_resource, only: %i[show edit update destroy regenerate_access_key] before_action :authenticate_user!, except: [:authenticate] before_action :authorize_user, only: %i[regenerate_access_key destroy update] # GET /api_resources # GET /a...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/saml_idp_controller.rb
Ruby
mit
202
master
2,071
#TODO rename back to SAMLController #class SamlIdpController < SamlIdp::IdpController class SamlIdpController < ApplicationController layout false before_action :setup_saml_configuration def show xml_content = SamlIdp.metadata.signed if params.key?(:download) send_data xml_content, type: '...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/users_controller.rb
Ruby
mit
202
master
4,114
class UsersController < ApplicationController before_action :authenticate_user!, except: %i[user_id verify authenticate authenticate_cas authenticate_ms_chap authenticate_pam public_key] before_action :authorize_user, only: %i[create update] def index @user_search = params[:user_search] @users = [] @...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/application_controller.rb
Ruby
mit
202
master
706
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception def render_404 respond_to do |format| format.html { render file: "#{Rails.root}/public/404", layout: false,...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/organisations_controller.rb
Ruby
mit
202
master
3,727
class OrganisationsController < ApplicationController before_action :authorize_user, except: [:index] before_action :load_org, only: %i( config_saml_app update show setup_saml save_config_saml_app remove_user_saml_app add_user_saml_app ) before_action :validate_app_name, only: %i( config_saml_app sa...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/host_controller.rb
Ruby
mit
202
master
564
class HostController < ApplicationController before_action :authenticate_user! def add_host @user = User.find(params[:id]) if current_user.admin? host = Host.new host.user = @user host.host_pattern = params[:host_pattern] host.save! end redirect_to user_path end def del...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/profile_controller.rb
Ruby
mit
202
master
6,344
class ProfileController < ApplicationController require 'vpn/mobileconfig' skip_before_action :verify_authenticity_token, if: Proc.new { |c| c.request.format == 'application/json' } before_action :authenticate_user!, except: %i[user_id verify authenticate authenticate_cas authenticate_ms_chap authenticate_pam pu...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/host_machines_controller.rb
Ruby
mit
202
master
2,620
class HostMachinesController < ApplicationController before_action :set_host_machine, only: %i[add_group show edit update destroy delete_group] before_action :authenticate_user! before_action :authorize_user, only: %i[delete_group update] def index @title = 'Host' @host_machines = HostMachine.all @...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/nss_controller.rb
Ruby
mit
202
master
3,797
class NssController < ApplicationController skip_before_action :verify_authenticity_token, only: %i[add_host add_user_to_group] before_action :authenticate_access_token!, only: %i[add_host] def host token = AccessToken.valid_token params[:token] @response = nil if token @response = HostMachine....
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/groups_controller.rb
Ruby
mit
202
master
6,072
class GroupsController < ApplicationController before_action :set_group, only: %i[show edit update destroy add_user add_machine add_vpn add_admin remove_admin delete_user delete_vpn delete_machine] before_action :authenticate_user! def ind...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/vpn_domain_name_servers_controller.rb
Ruby
mit
202
master
306
class VpnsController < ApplicationController before_action :authorize_user before_action :set_vpn, only: %i[show edit update destroy user_associated_groups] def destroy; end end #TODO fix this in future. This is something not great. class VpnDomainNameServersController < ApplicationController end
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/host_machine_groups_controller.rb
Ruby
mit
202
master
764
class HostMachineGroupsController < ApplicationController def show @host_machines = HostMachine.all end def create @host_machine = HostMachine.new(host_machine_params) respond_to do |format| @host_machine.save format.html { redirect_to :show, notice: 'host_machine was successfully created...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/vpns_controller.rb
Ruby
mit
202
master
6,323
class VpnsController < ApplicationController before_action :authorize_user, except: %i[create_group_associated_users show index user_associated_groups group_associated_users search] before_action :set_vpn, only: %i[show edit update destroy ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/api/v1/groups_controller.rb
Ruby
mit
202
master
1,309
class ::Api::V1::GroupsController < ::Api::V1::BaseController def create if current_user.admin? @group = Group.new(group_params) if @group.save render json: { id: @group.id, name: @group.name, }, status: :ok else is_taken = @group.errors.details[:name]...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/api/v1/users_controller.rb
Ruby
mit
202
master
2,158
class ::Api::V1::UsersController < ::Api::V1::BaseController before_action :set_user, only: %i[show update] def create return head :forbidden unless current_user.admin? user = user_params if User.add_temp_user user[:name], user[:email] render json: { status: 'created' }, status: :ok else ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/api/v1/vpns_controller.rb
Ruby
mit
202
master
886
class ::Api::V1::VpnsController < ::Api::V1::BaseController before_action :set_vpn, only: [:assign_group] def create if current_user.admin? @vpn = Vpn.new(vpn_params) @vpn.uuid = SecureRandom.uuid if @vpn.save render json: { id: @vpn.id, name: @vpn.name, ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/api/v1/endpoints_controller.rb
Ruby
mit
202
master
985
class ::Api::V1::EndpointsController < ::Api::V1::BaseController before_action :authorize_user def create endpoint = Endpoint.new(endpoint_param) if endpoint.save render json: { id: endpoint.id, path: endpoint.path, method: endpoint.method, } else render json: ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/api/v1/base_controller.rb
Ruby
mit
202
master
713
class ::Api::V1::BaseController < ActionController::Base protect_from_forgery with: :null_session before_action :authenticate_user_from_token! def authenticate_user_from_token! if get_token.nil? || !AccessToken.valid_token(get_token) raise_unauthorized end end protected def current_user ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/users/omniauth_callbacks_controller.rb
Ruby
mit
202
master
733
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def google_oauth2 # You need to implement the method below in your model (e.g. app/models/user.rb) # data = request.env['omniauth.auth'] domain = data['info']['email'].split('@').last unless User.valid_domain? domain ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/controllers/users/auth_controller.rb
Ruby
mit
202
master
500
class Users::AuthController < ApplicationController def log_in unless ENV['SIGN_IN_TYPE'] == 'form' return redirect_to root_path end email = params.require(:email) name = params.require(:name) unless User.valid_domain? email.split('@').last return render plain: 'Your domain is unaut...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/validators/email_validator.rb
Ruby
mit
202
master
265
class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value.to_s.match?(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i) record.errors[attribute] << (options[:message] || 'is not an email') end end end
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/user.rb
Ruby
mit
202
master
12,507
class User < ApplicationRecord include MsChapAuth devise :timeoutable, :omniauthable, omniauth_providers: [:google_oauth2] has_many :hosts has_many :group_associations has_many :groups, through: :group_associations has_many :group_admin, dependent: :destroy has_one :access_token # TODO: Need to add t...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/group.rb
Ruby
mit
202
master
5,307
class Group < ApplicationRecord has_many :group_admins, dependent: :destroy has_many :group_associations has_many :users, through: :group_associations has_many :vpn_group_associations has_many :vpns, through: :vpn_group_associations has_many :host_access_groups has_many :host_machines, through: :host_a...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/organisation.rb
Ruby
mit
202
master
2,303
class Organisation < ApplicationRecord validates :name, :website, :domain, :country, :state, :address, :admin_email_address, :slug, presence: true validates :address, format: { with: /\A[a-zA-Z0-9\s]+\z/, message: 'Invalid - Only Alphabets, Space and Numbers Allowed', } validates :admin_emai...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/saml_app_config.rb
Ruby
mit
202
master
262
class SamlAppConfig < ApplicationRecord belongs_to :group belongs_to :organisation serialize :config, JSON def self.get_config(app_name, org_id) SamlAppConfig.find_or_initialize_by( app_name: app_name, organisation_id: org_id ) end end
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/endpoint.rb
Ruby
mit
202
master
344
class Endpoint < ApplicationRecord has_many :group_endpoints has_many :groups, through: :group_endpoints validates_presence_of :path validates_presence_of :method validates :method, inclusion: { in: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'] } validates_format_of :path, with: /\A((\/(([0-9, a-z,\-,_]+)|(:...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/host_machine.rb
Ruby
mit
202
master
1,272
class HostMachine < ApplicationRecord has_many :host_access_groups has_many :groups, through: :host_access_groups validates_uniqueness_of :name, case_sensitive: false validates :name, presence: true before_create :set_lower_case_name before_create :set_host_access_key def set_host_access_key self.a...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/access_token.rb
Ruby
mit
202
master
452
class AccessToken < ApplicationRecord attr_accessor :token belongs_to :user before_save :hash_token! def self.find_token challenge_token AccessToken.where(hashed_token: Digest::SHA512.hexdigest(challenge_token)).first end def self.valid_token challenge_token find_token(challenge_token).present?...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/vpn.rb
Ruby
mit
202
master
1,981
class Vpn < ApplicationRecord belongs_to :user belongs_to :group has_many :vpn_group_associations has_many :groups, through: :vpn_group_associations has_many :vpn_group_user_associations has_many :users, through: :vpn_group_user_associations has_many :vpn_domain_name_servers has_many :vpn_search_doma...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/group_endpoint.rb
Ruby
mit
202
master
208
class GroupEndpoint < ApplicationRecord belongs_to :group belongs_to :endpoint validates :group, uniqueness: { scope: :endpoint } validates_presence_of :group validates_presence_of :endpoint end
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/api_resource.rb
Ruby
mit
202
master
707
class ApiResource < ApplicationRecord attr_accessor :access_key validates :name, format: { with: /\A[a-zA-Z0-9_-]+\Z/ }, uniqueness: true, presence: true validates :access_key, presence: true, on: :create belongs_to :user belongs_to :group before_save :hash_access_key! def self.authenticate access_key,...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/models/concerns/ms_chap_auth.rb
Ruby
mit
202
master
2,927
module MsChapAuth def hexlify(msg) msg.unpack('H*').first end def unhexlify(msg) msg.scan(/../).collect { |c| c.to_i(16).chr }.join end def test_key key, challenge des = OpenSSL::Cipher::DES.new('ECB') des.encrypt des.key = key des.update challenge #need to do it twice, don't kn...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/helpers/application_helper.rb
Ruby
mit
202
master
268
module ApplicationHelper def add_placeholder_to_list(list, placeholder, string_convert: 'titleize') (list.map do |row| name = string_convert.present? ? row.send(string_convert.to_sym) : row [name, row] end).insert(0, [placeholder, '']) end end
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
app/clients/data_dog_client.rb
Ruby
mit
202
master
1,501
class DataDogClient include HTTParty base_uri 'https://api.datadoghq.com/api/v1' def initialize(app_key, api_key) @base_path = 'https://api.datadoghq.com/api/v1' @app_key = app_key @api_key = api_key @headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json', ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
spec/rails_helper.rb
Ruby
mit
202
master
4,242
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../config/environment', __dir__) # Prevent database truncation if the environment is production abort('The Rails environment is running in production mode!') if Rails.env.production? require ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
spec/spec_helper.rb
Ruby
mit
202
master
2,085
# This file was generated by the `rails generate rspec:install` command. # Conventionally, all specs live under a `spec` directory, which RSpec adds to # the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause # this file to always be loaded, without a need to explicitly requir...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
spec/features/layout_spec.rb
Ruby
mit
202
master
1,621
require 'rails_helper' RSpec.feature 'Layout', type: :feature do let(:user) { create(:user) } let(:group_admin) { create(:group_admin) } let(:admin) { create(:admin_user) } scenario 'Access to user links' do sign_in(user) visit profile_path links = { 'APIs' => api_resources_path, 'VPNs' ...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
spec/features/users/regenerate_auth_spec.rb
Ruby
mit
202
master
488
require 'rails_helper' RSpec.feature 'Rengenerate Auth Token', type: :feature do let(:user) { create(:user) } let(:rotp_key) { ROTP::Base32.random_base32 } before(:each) do allow(ROTP::Base32).to receive(:random_base32).and_return(rotp_key) end scenario 'Create an organisation successfully' do sign_in...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
spec/features/users/create_user_spec.rb
Ruby
mit
202
master
3,354
require 'rails_helper' RSpec.feature 'Create User', type: :feature do let(:user) { create(:user, admin: true) } before(:each) do sign_in user end scenario 'Main Navigation should have link to create user' do visit new_user_path expect(page).to have_xpath("//div[@id='main-navigation']//a[@href='#{n...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
spec/features/saml/show_spec.rb
Ruby
mit
202
master
848
require 'rails_helper' RSpec.feature 'Config Saml App', type: :feature do let(:org) { create(:organisation) } let(:user) { create(:user) } let(:saml_apps) { ENV['SAML_APPS'].split(',') } let(:xml_content) { Nokogiri::XML::Builder.new { |xml| xml.foo_bar 'hello' }.to_xml } before do sign_in(user) allo...
github
gate-sso/gate-openvpn
https://github.com/gate-sso/gate-openvpn
spec/features/organisations/list_spec.rb
Ruby
mit
202
master
1,303
require 'rails_helper' RSpec.feature 'List Organisations', type: :feature do let!(:orgs) { create_list(:organisation, 5) } let(:user) { create(:user) } scenario 'Can create an organisation' do sign_in(user) visit organisations_path expect(page).to have_xpath("//a[@id='new_organisation_btn']") end ...