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 | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | spec/openapi_contracts/validators/documented_spec.rb | Ruby | mit | 47 | main | 801 | RSpec.describe OpenapiContracts::Validators::Documented do
subject { described_class.new(stack, env) }
let(:env) do
OpenapiContracts::Env.new(operation:, response:, request: response.request)
end
let(:operation) { doc.operation_for(path, method) }
let(:stack) { ->(errors) { errors } }
include_context ... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | spec/openapi_contracts/validators/response_body_spec.rb | Ruby | mit | 47 | main | 2,429 | RSpec.describe OpenapiContracts::Validators::ResponseBody do
subject { described_class.new(stack, env) }
let(:env) { OpenapiContracts::Env.new(operation:, response:) }
let(:operation) { doc.operation_for(path, method) }
let(:stack) { ->(errors) { errors } }
include_context 'when using GET /user' do
let(... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | spec/integration/rspec_spec.rb | Ruby | mit | 47 | main | 5,745 | RSpec.describe 'RSpec integration' do
subject { response }
include_context 'when using GET /user'
it { is_expected.to match_openapi_doc(doc) }
it { is_expected.to match_openapi_doc(doc).with_http_status(:ok) }
it { is_expected.to match_openapi_doc(doc).with_http_status(200) }
it { is_expected.to_not mat... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts.rb | Ruby | mit | 47 | main | 1,393 | require 'active_support'
require 'active_support/core_ext/array'
require 'active_support/core_ext/hash'
require 'active_support/core_ext/class'
require 'active_support/core_ext/module'
require 'active_support/core_ext/string'
require 'rubygems/version'
require 'json_schemer'
require 'openapi_parameters'
require 'rack'... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/rspec.rb | Ruby | mit | 47 | main | 883 | require 'rspec/matchers'
RSpec::Matchers.define :match_openapi_doc do |doc, options = {}| # rubocop:disable Metrics/BlockLength
include OpenapiContracts::Helper
match do |response|
match = OpenapiContracts::Match.new(
doc,
response,
options.merge({status: @status}.compact)
)
return t... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/coverage.rb | Ruby | mit | 47 | main | 527 | module OpenapiContracts
class Coverage
autoload :Report, 'openapi_contracts/coverage/report'
autoload :Store, 'openapi_contracts/coverage/store'
def self.merge_reports(doc, *others)
reports = others.map { |fp| JSON(File.read(fp))['paths'] }
Report.merge(doc, *reports)
end
attr_reade... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/parser.rb | Ruby | mit | 47 | main | 2,141 | module OpenapiContracts
class Parser
autoload :Transformers, 'openapi_contracts/parser/transformers'
TRANSFORMERS = [Transformers::Pointer].freeze
def self.call(dir, filename)
new(dir.join(filename)).parse
end
attr_reader :filenesting, :rootfile
def initialize(rootfile)
@cwd = ... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/payload_parser.rb | Ruby | mit | 47 | main | 966 | require 'singleton'
module OpenapiContracts
class PayloadParser
include Singleton
class << self
delegate :parse, :register, to: :instance
end
Entry = Struct.new(:matcher, :parser) do
def call(raw)
parser.call(raw)
end
def match?(media_type)
matcher == media_... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators.rb | Ruby | mit | 47 | main | 815 | module OpenapiContracts
module Validators
autoload :Base, 'openapi_contracts/validators/base'
autoload :Documented, 'openapi_contracts/validators/documented'
autoload :Headers, 'openapi_contracts/validators/headers'
autoload :HttpStatus, 'openapi_contracts/validators/h... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/match.rb | Ruby | mit | 47 | main | 2,375 | module OpenapiContracts
class Match
DEFAULT_OPTIONS = {
parameters: false,
request_body: false
}.freeze
MIN_REQUEST_ANCESTORS = %w(Rack::Request::Env Rack::Request::Helpers).freeze
MIN_RESPONSE_ANCESTORS = %w(Rack::Response::Helpers).freeze
attr_reader :errors
def initialize(do... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/operation_router.rb | Ruby | mit | 47 | main | 859 | module OpenapiContracts
class OperationRouter
def initialize(doc)
@doc = doc
@dynamic_paths = doc.paths.select(&:dynamic?)
end
def route(actual_path, method)
@doc.with_path(actual_path)&.then { |p| return p.with_method(method) }
@dynamic_paths.each do |path|
next unless p... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/doc.rb | Ruby | mit | 47 | main | 1,722 | module OpenapiContracts
class Doc
autoload :Header, 'openapi_contracts/doc/header'
autoload :Operation, 'openapi_contracts/doc/operation'
autoload :Parameter, 'openapi_contracts/doc/parameter'
autoload :Path, 'openapi_contracts/doc/path'
autoload :Pointer, 'opena... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/parser/transformers/base.rb | Ruby | mit | 47 | main | 265 | module OpenapiContracts::Parser::Transformers
class Base
def initialize(parser, cwd, pointer)
@parser = parser
@cwd = cwd
@pointer = pointer
end
# :nocov:
def call
raise NotImplementedError
end
# :nocov:
end
end |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/parser/transformers/pointer.rb | Ruby | mit | 47 | main | 1,292 | module OpenapiContracts::Parser::Transformers
class Pointer < Base
def call(object)
transform_discriminator(object)
transform_refs(object)
end
private
def transform_discriminator(object)
mappings = object.dig('discriminator', 'mapping')
return unless mappings.present?
... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/base.rb | Ruby | mit | 47 | main | 758 | module OpenapiContracts::Validators
class Base
include OpenapiContracts::Helper
class_attribute :final, instance_writer: false
self.final = false
def initialize(stack, env)
@stack = stack # next matcher
@env = env
@errors = []
end
def call(errors = [])
validate
... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/response_body.rb | Ruby | mit | 47 | main | 850 | module OpenapiContracts::Validators
class ResponseBody < Base
include SchemaValidation
private
delegate :media_type, to: :response
def data_for_validation
# ActionDispatch::Response body is a plain string, while Rack::Response returns an array
OpenapiContracts::PayloadParser.parse(media... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/http_status.rb | Ruby | mit | 47 | main | 255 | module OpenapiContracts::Validators
class HttpStatus < Base
self.final = true
private
def validate
return if options[:status] == response.status
@errors << "Response has #{http_status_desc(response.status)}"
end
end
end |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/parameters.rb | Ruby | mit | 47 | main | 655 | module OpenapiContracts::Validators
# Validates the input parameters, eg path/url parameters
class Parameters < Base
include SchemaValidation
private
def validate
operation.parameters.select(&:in_query?).each do |parameter|
if request.GET.key?(parameter.name)
value = request.GE... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/schema_validation.rb | Ruby | mit | 47 | main | 1,028 | module OpenapiContracts::Validators
module SchemaValidation
module_function
def error_to_message(error)
msg = error['error']
msg.sub!(/^value/, error['data'].to_json) if error['data'].to_json.length < 50
msg
end
def schema_draft_version(schema)
if schema.openapi_version.blank... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/request_body.rb | Ruby | mit | 47 | main | 730 | module OpenapiContracts::Validators
class RequestBody < Base
include SchemaValidation
private
delegate :media_type, to: :request
delegate :request_body, to: :operation
def data_for_validation
request.body.rewind
raw = request.body.read
OpenapiContracts::PayloadParser.parse(med... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/documented.rb | Ruby | mit | 47 | main | 711 | module OpenapiContracts::Validators
# Purpose of this validator
# * ensure the operation is documented (combination http-method + path)
# * ensure the response-status is documented on the operation
class Documented < Base
self.final = true
private
def validate
return operation_missing unless... |
github | mkon/openapi_contracts | https://github.com/mkon/openapi_contracts | lib/openapi_contracts/validators/headers.rb | Ruby | mit | 47 | main | 1,359 | module OpenapiContracts::Validators
class Headers < Base
private
def spec
@spec ||= operation.response_for_status(response.status)
end
def validate
spec.headers.each do |header|
value = response.headers[header.name]
# Rack 3.0.0 returns an Array for multi-value headers. ... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | Gemfile | Ruby | mit | 47 | main | 402 | source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Specify your gem's dependencies in lazy_value.gemspec.
gemspec
gem "sqlite3"
# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"
gem "sprockets-rails"
gem "pry"
gem "wrapped_print"
... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | lazy_value.gemspec | Ruby | mit | 47 | main | 1,116 | require_relative "lib/lazy_value/version"
Gem::Specification.new do |spec|
spec.name = "lazy_value"
spec.version = LazyValue::VERSION
spec.authors = ["Igor Kasyanchuk", "Liubomyr Manastyretskyi"]
spec.email = ["igorkasyanchuk@gmail.com", "manastyretskyi@gmail.com"]
spec.homepage = "ht... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | lib/lazy_value.rb | Ruby | mit | 47 | main | 609 | require "lazy_value/version"
require "lazy_value/routes"
require "lazy_value/engine"
module LazyValue
mattr_accessor :key
@@key = ENV["LAZY_VALUE_KEY"].presence || SecureRandom.hex(32)
mattr_accessor :salt
@@salt = ENV["LAZY_VALUE_SALT"].presence || SecureRandom.hex(8)
def self.setup
yield(self)
end
... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | lib/lazy_value/engine.rb | Ruby | mit | 47 | main | 226 | module LazyValue
class Engine < ::Rails::Engine
isolate_namespace LazyValue
config.to_prepare do
ActiveSupport.on_load(:action_view) do
include LazyValue::ApplicationHelper
end
end
end
end |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | lib/generators/lazy_value/lazy_value_generator.rb | Ruby | mit | 47 | main | 210 | class LazyValueGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
def copy_initializer
template 'template.rb', 'config/initializers/lazy_value.rb'
end
end |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | app/helpers/lazy_value/application_helper.rb | Ruby | mit | 47 | main | 3,001 | module LazyValue
module ApplicationHelper
SPINNER = <<~SVG
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_OSmW{transform-origin:center;animation:spinner_T6mA .75s step-end infinite}@keyframes spinner_T6mA{8.3%{transform:rotate(30deg)}16.6%{transform:rotate... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | app/controllers/lazy_value/application_controller.rb | Ruby | mit | 47 | main | 1,249 | module LazyValue
class ApplicationController < ActionController::Base
REGEXP = /<%= lazy_value_tag(?:.*?)do %>(.*?)<% end %>|<%= lazy_value_tag { (.+?) } %>/m
ERROR_MESSAGE = "Incorrect usage. Try to use \"lazy_value_tag do ... end\" or \"lazy_value_tag { ... }\""
def show
matches = code.match(REGE... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | test/system/homes_test.rb | Ruby | mit | 47 | main | 377 | require "application_system_test_case"
class HomesTest < ApplicationSystemTestCase
test "visiting the index" do
visit root_url
sleep(2)
assert page.body.include?("4242$")
assert page.body.include?("100%")
assert page.body.include?("7000")
assert page.body.include?("55₴")
assert page.body.... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | test/dummy/config/application.rb | Ruby | mit | 47 | main | 788 | require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require "lazy_value"
module Dummy
class Application < Rails::Application
config.load_defaults Rails::VERSION::STRING.to_f
... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | test/dummy/config/puma.rb | Ruby | mit | 47 | main | 1,792 | # Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | test/dummy/db/schema.rb | Ruby | mit | 47 | main | 934 | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... |
github | railsjazz/lazy_value | https://github.com/railsjazz/lazy_value | test/dummy/db/migrate/20230415203543_create_users.rb | Ruby | mit | 47 | main | 219 | class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name
t.timestamps
end
100.times do |i|
User.create(name: "User #{i}")
end
end
end |
github | motine/dsl_factory | https://github.com/motine/dsl_factory | dsl_factory.gemspec | Ruby | mit | 47 | master | 1,339 | # frozen_string_literal: true
require_relative "lib/dsl_factory/version"
Gem::Specification.new do |spec|
spec.name = "dsl_factory"
spec.version = DslFactory::VERSION
spec.authors = ["Tom Rothe"]
spec.email = ["info@tomrothe.de"]
spec.summary = "A small DSL to generate DS... |
github | motine/dsl_factory | https://github.com/motine/dsl_factory | lib/dsl_factory.rb | Ruby | mit | 47 | master | 466 | require_relative "dsl_factory/version"
require_relative "dsl_factory/generator"
require 'active_support/inflector'
module DslFactory
class DefinitionError < StandardError; end
class ValidationError < StandardError; end
def define_dsl(inspectable: false, &block)
generator = DslFactory::Generator.new
gen... |
github | motine/dsl_factory | https://github.com/motine/dsl_factory | lib/dsl_factory/generator.rb | Ruby | mit | 47 | master | 5,297 | class DslFactory::Generator
attr_reader :definition
def initialize
@definition = Module.new do
def get_dsl_value(name)
@dsl_values ||= {}
@dsl_values[name]
end
def set_dsl_value(name, value, &block)
@dsl_values ||= {}
@dsl_values[name] = value
end
en... |
github | motine/dsl_factory | https://github.com/motine/dsl_factory | test/basic_test.rb | Ruby | mit | 47 | master | 1,728 | require "test_helper"
class BasicTest < Minitest::Test
SomeDefinition = DslFactory.define_dsl do
any :some_any
string :some_string
symbol :some_symbol
numeric :some_numeric
boolean :some_boolean
callable :some_callable
end
def test_access_to_simple_value_from_class
using_class = Clas... |
github | motine/dsl_factory | https://github.com/motine/dsl_factory | test/array_test.rb | Ruby | mit | 47 | master | 2,122 | require "test_helper"
class ArrayTest < Minitest::Test
def test_raises_for_singular_array_names
assert_raises(DslFactory::DefinitionError) do
DslFactory.define_dsl do
array :item
end
end
end
def test_simple_array
definition = DslFactory.define_dsl do
array :items
end
... |
github | motine/dsl_factory | https://github.com/motine/dsl_factory | test/hash_test.rb | Ruby | mit | 47 | master | 2,282 | require "test_helper"
class HashTest < Minitest::Test
def test_raises_for_singular_hash_names
assert_raises(DslFactory::DefinitionError) do
DslFactory.define_dsl do
hash :assignment
end
end
end
def test_simple_hash
definition = DslFactory.define_dsl do
hash :assignments
... |
github | olabini/bumble | https://github.com/olabini/bumble | bumble/bumble.rb | Ruby | mit | 47 | master | 4,699 | require 'java'
module Bumble
module DS
import com.google.appengine.api.datastore.DatastoreServiceFactory
import com.google.appengine.api.datastore.Entity
import com.google.appengine.api.datastore.FetchOptions
import com.google.appengine.api.datastore.KeyFactory
import com.google.appengine.api.dat... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | railroader.gemspec | Ruby | mit | 47 | master | 1,092 | require './lib/railroader/version'
require './gem_common'
gem_priv_key = File.expand_path("~/.ssh/gem-private_key.pem")
Gem::Specification.new do |s|
s.name = %q{railroader}
s.version = Railroader::Version
s.authors = ["David A. Wheeler and Justin Collins"]
s.email = "gem@railroader.org"
s.summary = "Securit... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | railroader-min.gemspec | Ruby | mit | 47 | master | 1,015 | require './lib/railroader/version'
require './gem_common'
gem_priv_key = File.expand_path("~/.ssh/gem-private_key.pem")
Gem::Specification.new do |s|
s.name = %q{railroader-min}
s.version = Railroader::Version
s.authors = ["David A. Wheeler and Justin Collins"]
s.email = "gem@railroader.org"
s.summary = "Sec... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | railroader-lib.gemspec | Ruby | mit | 47 | master | 1,016 | require './lib/railroader/version'
require './gem_common'
gem_priv_key = File.expand_path("~/.ssh/gem-private_key.pem")
Gem::Specification.new do |s|
s.name = %q{railroader-lib}
s.version = Railroader::Version
s.authors = ["David A. Wheeler and Justin Collins"]
s.email = "gem@railroader.org"
s.summary = "Sec... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | build.rb | Ruby | mit | 47 | master | 535 | #!/usr/bin/env ruby
puts 'Packaging Railroader gem...'
system 'rm -rf bundle Gemfile.lock railroader-*.gem' and
system 'BM_PACKAGE=true bundle install --standalone'
abort "No bundle installed" unless Dir.exist? 'bundle'
File.delete "bundle/bundler/setup.rb"
Dir.delete "bundle/bundler"
File.open "bundle/load.rb", "w... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | gem_common.rb | Ruby | mit | 47 | master | 935 | module Railroader
module GemDependencies
def self.dev_dependencies spec
spec.add_development_dependency "minitest"
spec.add_development_dependency 'rubocop', '~> 0.68.1'
spec.add_development_dependency 'rubocop-performance'
end
def self.base_dependencies spec
spec.add_dependency "... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | Gemfile | Ruby | mit | 47 | master | 295 | source "https://rubygems.org"
gemspec :name => "railroader"
unless ENV['BM_PACKAGE']
gem "rake", "< 10.2.0"
gem "codeclimate-test-reporter", group: :test, require: nil
gem "json", "< 2.0", group: :test, require: nil # For Ruby 1.9.3 https://github.com/colszowka/simplecov/issues/511
end |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader.rb | Ruby | mit | 47 | master | 16,679 | require 'set'
require 'railroader/version'
module Railroader
# This exit code is used when warnings are found and the --exit-on-warn
# option is set
Warnings_Found_Exit_Code = 3
# Exit code returned when no Rails application is detected
No_App_Found_Exit_Code = 4
# Exit code returned when railroader was... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/ruby_parser/bm_sexp.rb | Ruby | mit | 47 | master | 13,747 | # Sexp changes from ruby_parser
# and some changes for caching hash value and tracking 'original' line number
# of a Sexp.
class Sexp
attr_accessor :original_line, :or_depth
ASSIGNMENT_BOOL = [:gasgn, :iasgn, :lasgn, :cvdecl, :cvasgn, :cdecl, :or, :and, :colon2, :op_asgn_or]
CALLS = [:call, :attrasgn, :safe_call,... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/ruby_parser/bm_sexp_processor.rb | Ruby | mit | 47 | master | 2,563 | ##
# SexpProcessor provides a uniform interface to process Sexps.
#
# In order to create your own SexpProcessor subclass you'll need
# to call super in the initialize method, then set any of the
# Sexp flags you want to be different from the defaults.
#
# SexpProcessor uses a Sexp's type to determine which process meth... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/report.rb | Ruby | mit | 47 | master | 2,002 | require 'railroader/report/report_base'
# Generates a report based on the Tracker and the results of
# Tracker#run_checks. Be sure to +run_checks+ before generating
# a report.
class Railroader::Report
attr_reader :tracker
VALID_FORMATS = [:to_html, :to_pdf, :to_csv, :to_json, :to_tabs, :to_hash, :to_s, :to_markd... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/file_parser.rb | Ruby | mit | 47 | master | 1,370 | module Railroader
ASTFile = Struct.new(:path, :ast)
# This class handles reading and parsing files.
class FileParser
attr_reader :file_list
def initialize tracker, app_tree
@tracker = tracker
@timeout = @tracker.options[:parser_timeout]
@app_tree = app_tree
@file_list = {}
en... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/scanner.rb | Ruby | mit | 47 | master | 9,556 | begin
Railroader.load_railroader_dependency 'ruby_parser'
require 'ruby_parser/bm_sexp.rb'
require 'ruby_parser/bm_sexp_processor.rb'
require 'railroader/processor'
require 'railroader/app_tree'
require 'railroader/file_parser'
require 'railroader/parsers/template_parser'
rescue LoadError => e
$stderr.p... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/checks.rb | Ruby | mit | 47 | master | 5,440 | require 'thread'
require 'railroader/differ'
# Collects up results from running different checks.
#
# Checks can be added with +Check.add(check_class)+
#
# All .rb files in checks/ will be loaded.
class Railroader::Checks
@checks = []
@optional_checks = []
attr_reader :warnings, :controller_warnings, :model_war... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/warning_codes.rb | Ruby | mit | 47 | master | 3,221 | module Railroader::WarningCodes
Codes = {
:sql_injection => 0,
:sql_injection_limit_offset => 1,
:cross_site_scripting => 2,
:xss_link_to => 3,
:xss_link_to_href => 4,
:xss_to_json => 5,
:csrf_protection_disabled => 6,
:csrf_protection_missing => 7,
:csrf_blacklist => 8,
:basic... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/tracker.rb | Ruby | mit | 47 | master | 9,328 | require 'set'
require 'railroader/call_index'
require 'railroader/checks'
require 'railroader/report'
require 'railroader/processors/lib/find_call'
require 'railroader/processors/lib/find_all_calls'
require 'railroader/tracker/config'
require 'railroader/tracker/constants'
# The Tracker keeps track of all the processe... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/options.rb | Ruby | mit | 47 | master | 11,664 | require 'optparse'
require 'set'
# Parses command line arguments for Railroader
module Railroader::Options
class << self
# Parse argument array
def parse args
get_options args
end
# Parse arguments and remove them from the array as they are matched
def parse! args
get_options args,... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/app_tree.rb | Ruby | mit | 47 | master | 6,122 | require 'pathname'
module Railroader
class AppTree
VIEW_EXTENSIONS = %w[html.erb html.haml rhtml js.erb html.slim].join(",")
attr_reader :root
def self.from_options(options)
root = File.expand_path options[:app_path]
# Convert files into Regexp for matching
init_options = {}
if... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/util.rb | Ruby | mit | 47 | master | 12,619 | require 'set'
require 'pathname'
# This is a mixin containing utility methods.
module Railroader::Util
QUERY_PARAMETERS = Sexp.new(:call, Sexp.new(:call, nil, :request), :query_parameters)
PATH_PARAMETERS = Sexp.new(:call, Sexp.new(:call, nil, :request), :path_parameters)
REQUEST_PARAMETERS = Sexp.new(:call, ... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/rescanner.rb | Ruby | mit | 47 | master | 12,523 | require 'railroader/scanner'
require 'railroader/util'
require 'railroader/differ'
# Class for rescanning changed files after an initial scan
class Railroader::Rescanner < Railroader::Scanner
include Railroader::Util
KNOWN_TEMPLATE_EXTENSIONS = Railroader::TemplateParser::KNOWN_TEMPLATE_EXTENSIONS
SCAN_ORDER = [:... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/commandline.rb | Ruby | mit | 47 | master | 5,128 | require 'railroader/options'
module Railroader
# Implements handling of running Railroader from the command line.
class Commandline
class << self
# Main method to run Railroader from the command line.
#
# If no options are provided, ARGV will be parsed and used instead.
# Otherwise, t... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/warning.rb | Ruby | mit | 47 | master | 7,675 | require 'json'
require 'digest/sha2'
require 'railroader/warning_codes'
# The Warning class stores information about warnings
class Railroader::Warning
attr_reader :called_from, :check, :class, :confidence, :controller,
:line, :method, :model, :template, :user_input, :user_input_type,
:wa... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processor.rb | Ruby | mit | 47 | master | 3,430 | # Load all files in processors/
Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/processors/*.rb").each { |f| require f.match(/railroader\/processors.*/)[0] }
require 'railroader/tracker'
require 'set'
require 'pathname'
module Railroader
# Makes calls to the appropriate processor.
#
# The ControllerProcess... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/differ.rb | Ruby | mit | 47 | master | 2,319 | # extracting the diff logic to it's own class for consistency. Currently handles
# an array of Railroader::Warnings or plain hash representations.
class Railroader::Differ
DEFAULT_HASH = {:new => [], :fixed => []}
OLD_WARNING_KEYS = [:warning_type, :location, :code, :message, :file, :link, :confidence, :user_input]... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/call_index.rb | Ruby | mit | 47 | master | 5,408 | require 'set'
# Stores call sites to look up later.
class Railroader::CallIndex
# Initialize index with calls from FindAllCalls
def initialize calls
@calls_by_method = Hash.new { |h, k| h[k] = [] }
@calls_by_target = Hash.new { |h, k| h[k] = [] }
index_calls calls
end
# Find calls matching speci... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/gem_processor.rb | Ruby | mit | 47 | master | 1,521 | require 'railroader/processors/lib/basic_processor'
# Processes Gemfile and Gemfile.lock
class Railroader::GemProcessor < Railroader::BasicProcessor
def initialize *args
super
@gem_name_version = /^\s*([-_+.A-Za-z0-9]+) \((\w(\.\w+)*)\)/
end
def process_gems gem_files
@gem_files = gem_files
@ge... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/alias_processor.rb | Ruby | mit | 47 | master | 29,454 | require 'railroader/util'
require 'ruby_parser/bm_sexp_processor'
require 'railroader/processors/lib/processor_helper'
require 'railroader/processors/lib/safe_call_helper'
require 'railroader/processors/lib/call_conversion_helper'
# Returns an s-expression with aliases replaced with their value.
# This does not preser... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/erubis_template_processor.rb | Ruby | mit | 47 | master | 2,336 | require 'railroader/processors/template_processor'
# Processes ERB templates using Erubis instead of erb.
class Railroader::ErubisTemplateProcessor < Railroader::TemplateProcessor
# s(:call, TARGET, :method, ARGS)
def process_call exp
target = exp.target
if sexp? target
target = process target
e... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/template_alias_processor.rb | Ruby | mit | 47 | master | 3,425 | require 'set'
require 'railroader/processors/alias_processor'
require 'railroader/processors/lib/render_helper'
require 'railroader/processors/lib/render_path'
require 'railroader/tracker'
# Processes aliasing in templates.
# Handles calls to +render+.
class Railroader::TemplateAliasProcessor < Railroader::AliasProces... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/model_processor.rb | Ruby | mit | 47 | master | 2,337 | require 'railroader/processors/base_processor'
require 'railroader/processors/lib/module_helper'
require 'railroader/tracker/model'
# Processes models. Puts results in tracker.models
class Railroader::ModelProcessor < Railroader::BaseProcessor
include Railroader::ModuleHelper
def initialize tracker
super
... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/library_processor.rb | Ruby | mit | 47 | master | 1,912 | require 'railroader/processors/base_processor'
require 'railroader/processors/alias_processor'
require 'railroader/processors/lib/module_helper'
require 'railroader/tracker/library'
# Process generic library and stores it in Tracker.libs
class Railroader::LibraryProcessor < Railroader::BaseProcessor
include Railroad... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/config_processor.rb | Ruby | mit | 47 | master | 442 | require 'railroader/processors/base_processor'
require 'railroader/processors/alias_processor'
require 'railroader/processors/lib/rails3_config_processor.rb'
require 'railroader/processors/lib/rails2_config_processor.rb'
class Railroader::ConfigProcessor
def self.new tracker
if tracker.options[:rails3]
Rai... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/haml_template_processor.rb | Ruby | mit | 47 | master | 5,553 | require 'railroader/processors/template_processor'
# Processes HAML templates.
class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
HAML_FORMAT_METHOD = /format_script_(true|false)_(true|false)_(true|false)_(true|false)_(true|false)_(true|false)_(true|false)/
HAML_HELPERS = s(:colon2, s(:const, ... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/controller_processor.rb | Ruby | mit | 47 | master | 7,288 | require 'railroader/processors/base_processor'
require 'railroader/processors/lib/module_helper'
require 'railroader/tracker/controller'
# Processes controller. Results are put in tracker.controllers
class Railroader::ControllerProcessor < Railroader::BaseProcessor
include Railroader::ModuleHelper
FORMAT_HTML = S... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/erb_template_processor.rb | Ruby | mit | 47 | master | 1,868 | require 'railroader/processors/template_processor'
# Processes ERB templates
# (those ending in .html.erb or .rthml).
class Railroader::ErbTemplateProcessor < Railroader::TemplateProcessor
# s(:call, TARGET, :method, ARGS)
def process_call exp
target = exp.target
if sexp? target
target = process tar... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/route_processor.rb | Ruby | mit | 47 | master | 529 | require 'railroader/processors/base_processor'
require 'railroader/processors/alias_processor'
require 'railroader/processors/lib/route_helper'
require 'railroader/util'
require 'railroader/processors/lib/rails3_route_processor.rb'
require 'railroader/processors/lib/rails2_route_processor.rb'
require 'set'
class Railr... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/output_processor.rb | Ruby | mit | 47 | master | 2,842 | Railroader.load_railroader_dependency 'ruby2ruby'
require 'railroader/util'
# Produces formatted output strings from Sexps.
# Recommended usage is
#
# OutputProcessor.new.format(Sexp.new(:str, "hello"))
class Railroader::OutputProcessor < Ruby2Ruby
include Railroader::Util
# Copies +exp+ and then formats it.
d... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/template_processor.rb | Ruby | mit | 47 | master | 2,073 | require 'railroader/processors/base_processor'
require 'railroader/tracker/template'
# Base Processor for templates/views
class Railroader::TemplateProcessor < Railroader::BaseProcessor
# Initializes template information.
def initialize tracker, template_name, called_from = nil, file_name = nil
super(tracker)... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/controller_alias_processor.rb | Ruby | mit | 47 | master | 7,807 | require 'railroader/processors/alias_processor'
require 'railroader/processors/lib/render_helper'
require 'railroader/processors/lib/render_path'
require 'railroader/processors/lib/find_return_value'
# Processes aliasing in controllers, but includes following
# renders in routes and putting variables into templates
cl... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/base_processor.rb | Ruby | mit | 47 | master | 6,836 | require 'railroader/processors/lib/processor_helper'
require 'railroader/processors/lib/safe_call_helper'
require 'railroader/util'
# Base processor for most processors.
class Railroader::BaseProcessor < Railroader::SexpProcessor
include Railroader::ProcessorHelper
include Railroader::SafeCallHelper
include Rail... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/slim_template_processor.rb | Ruby | mit | 47 | master | 2,794 | require 'railroader/processors/template_processor'
require 'railroader/processors/lib/render_helper'
class Railroader::SlimTemplateProcessor < Railroader::TemplateProcessor
include Railroader::RenderHelper
SAFE_BUFFER = s(:call, s(:colon2, s(:const, :ActiveSupport), :SafeBuffer), :new)
OUTPUT_BUFFER = s(:ivar, ... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/find_call.rb | Ruby | mit | 47 | master | 4,454 | require 'railroader/processors/lib/basic_processor'
# Finds method calls matching the given target(s).
# #-- This should be deprecated --#
# #-- Do not use for new code --#
#
# Targets/methods can be:
#
# - nil: matches anything, including nothing
# - Empty array: matches nothing
# - Symbol: matches single targe... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/render_path.rb | Ruby | mit | 47 | master | 1,990 | module Railroader
class RenderPath
attr_reader :path
def initialize
@path = []
end
def add_controller_render controller_name, method_name, line, file
method_name ||= ""
@path << { :type => :controller,
:class => controller_name.to_sym,
:method => ... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/rails3_route_processor.rb | Ruby | mit | 47 | master | 7,319 | require 'railroader/processors/lib/basic_processor'
# Processes the Sexp from routes.rb. Stores results in tracker.routes.
#
# Note that it is only interested in determining what methods on which
# controllers are used as routes, not the generated URLs for routes.
class Railroader::Rails3RoutesProcessor < Railroader::... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/find_all_calls.rb | Ruby | mit | 47 | master | 4,953 | require 'railroader/processors/lib/basic_processor'
class Railroader::FindAllCalls < Railroader::BasicProcessor
attr_reader :calls
def initialize tracker
super
@current_class = nil
@current_method = nil
@in_target = false
@calls = []
@cache = {}
end
# Process the given source. Provide... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/call_conversion_helper.rb | Ruby | mit | 47 | master | 2,687 | module Railroader
module CallConversionHelper
def all_literals? exp, expected_type = :array
node_type? exp, expected_type and
exp.length > 1 and
exp.all? { |e| e.is_a? Symbol or node_type? e, :lit, :str }
end
# Join two array literals into one.
def join_arrays lhs, rhs, original... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/safe_call_helper.rb | Ruby | mit | 47 | master | 464 | module Railroader
module SafeCallHelper
[[:process_safe_call, :process_call],
[:process_safe_attrasgn, :process_attrasgn],
[:process_safe_op_asgn, :process_op_asgn],
[:process_safe_op_asgn2, :process_op_asgn2]].each do |call, replacement|
define_method(call) do |exp|
if self.respond... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/rails2_config_processor.rb | Ruby | mit | 47 | master | 3,680 | require 'railroader/processors/lib/basic_processor'
# Processes configuration. Results are put in tracker.config.
#
# Configuration of Rails via Rails::Initializer are stored in tracker.config.rails.
# For example:
#
# Rails::Initializer.run |config|
# config.action_controller.session_store = :cookie_store
# end
... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/processor_helper.rb | Ruby | mit | 47 | master | 1,761 | # Contains a couple shared methods for Processors.
module Railroader::ProcessorHelper
def process_all exp
exp.each_sexp do |e|
process e
end
exp
end
def process_all! exp
exp.map! do |e|
if sexp? e
process e
else
e
end
end
exp
end
# Process the... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/route_helper.rb | Ruby | mit | 47 | master | 1,965 | module Railroader::RouteHelper
# Manage Controller prefixes
# @prefix is an Array, but this method returns a string
# suitable for prefixing onto a controller name.
def prefix
if @prefix.length > 0
@prefix.join("::") << "::"
else
''
end
end
# Sets the controller name to a proper cla... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/render_helper.rb | Ruby | mit | 47 | master | 5,355 | require 'digest/sha1'
# Processes a call to render() in a controller or template
module Railroader::RenderHelper
# Process s(:render, TYPE, OPTION?, OPTIONS)
def process_render exp
process_default exp
@rendered = true
case exp.render_type
when :action, :template, :inline
process_action exp[2... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/basic_processor.rb | Ruby | mit | 47 | master | 807 | require 'railroader/processors/lib/processor_helper'
require 'railroader/processors/lib/safe_call_helper'
require 'railroader/util'
class Railroader::BasicProcessor < Railroader::SexpProcessor
include Railroader::ProcessorHelper
include Railroader::SafeCallHelper
include Railroader::Util
def initialize tracke... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/rails2_route_processor.rb | Ruby | mit | 47 | master | 8,195 | require 'railroader/processors/lib/basic_processor'
# Processes the Sexp from routes.rb. Stores results in tracker.routes.
#
# Note that it is only interested in determining what methods on which
# controllers are used as routes, not the generated URLs for routes.
class Railroader::Rails2RoutesProcessor < Railroader::... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/rails3_config_processor.rb | Ruby | mit | 47 | master | 3,213 | require 'railroader/processors/lib/basic_processor'
# Processes configuration. Results are put in tracker.config.
#
# Configuration of Rails via Rails::Initializer are stored in tracker.config.rails.
# For example:
#
# MyApp::Application.configure do
# config.active_record.whitelist_attributes = true
# end
#
# wi... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/module_helper.rb | Ruby | mit | 47 | master | 2,636 | module Railroader::ModuleHelper
def handle_module exp, tracker_class, parent = nil
name = class_name(exp.module_name)
if @current_module
outer_module = @current_module
name = (outer_module.name.to_s + "::" + name.to_s).to_sym
end
if @current_class
name = (@current_class.name.to_s +... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/processors/lib/find_return_value.rb | Ruby | mit | 47 | master | 3,828 | require 'railroader/processors/alias_processor'
# Attempts to determine the return value of a method.
#
# Preferred usage:
#
# Railroader::FindReturnValue.return_value exp
class Railroader::FindReturnValue
include Railroader::Util
# Returns a guess at the return value of a given method or other block of code.
... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/codeclimate/engine_configuration.rb | Ruby | mit | 47 | master | 2,736 | require 'pathname'
module Railroader
module Codeclimate
class EngineConfiguration
def initialize(engine_config = {})
@engine_config = engine_config
end
def options
default_options.merge(configured_options)
end
private
attr_reader :engine_config
def d... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/parsers/template_parser.rb | Ruby | mit | 47 | master | 3,426 | module Railroader
class TemplateParser
include Railroader::Util
attr_reader :tracker
KNOWN_TEMPLATE_EXTENSIONS = /.*\.(erb|haml|rhtml|slim)$/
TemplateFile = Struct.new(:path, :ast, :name, :type)
def initialize tracker, file_parser
@tracker = tracker
@file_parser = file_parser
@... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/parsers/rails3_erubis.rb | Ruby | mit | 47 | master | 2,153 | Railroader.load_railroader_dependency 'erubis'
# This is from Rails 5 version of the Erubis handler
# https://github.com/rails/rails/blob/ec608107801b1e505db03ba76bae4a326a5804ca/actionview/lib/action_view/template/handlers/erb.rb#L7-L73
class Railroader::Rails3Erubis < ::Erubis::Eruby
def add_preamble(src)
@ne... |
github | david-a-wheeler/railroader | https://github.com/david-a-wheeler/railroader | lib/railroader/parsers/rails2_xss_plugin_erubis.rb | Ruby | mit | 47 | master | 1,347 | Railroader.load_railroader_dependency 'erubis'
# This is from the rails_xss plugin for Rails 2
class Railroader::Rails2XSSPluginErubis < ::Erubis::Eruby
def add_preamble(src)
# src << "@output_buffer = ActiveSupport::SafeBuffer.new;"
end
# This is different from rails_xss - fixes some line number issues
d... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.