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 | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers/redirect.rb | Ruby | mit | 19 | main | 702 | # lib/otto/response_handlers/redirect.rb
#
# frozen_string_literal: true
require_relative 'base'
class Otto
module ResponseHandlers
# Handler for redirect responses
class RedirectHandler < BaseHandler
def self.handle(result, response, context = {})
# Determine redirect path
path = if c... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers/view.rb | Ruby | mit | 19 | main | 777 | # lib/otto/response_handlers/view.rb
#
# frozen_string_literal: true
require_relative 'base'
class Otto
module ResponseHandlers
# Handler for view/template responses
class ViewHandler < BaseHandler
def self.handle(result, response, context = {})
if context[:logic_instance].respond_to?(:view)
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers/json.rb | Ruby | mit | 19 | main | 1,074 | # lib/otto/response_handlers/json.rb
#
# frozen_string_literal: true
require_relative 'base'
class Otto
module ResponseHandlers
# Handler for JSON responses
class JSONHandler < BaseHandler
def self.handle(result, response, context = {})
# If a redirect has already been set, don't override with... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers/auto.rb | Ruby | mit | 19 | main | 1,345 | # lib/otto/response_handlers/auto.rb
#
# frozen_string_literal: true
require_relative 'base'
require_relative 'json'
require_relative 'redirect'
require_relative 'view'
require_relative 'default'
class Otto
module ResponseHandlers
# Auto-detection handler that chooses appropriate handler based on context
cl... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/uri_generator.rb | Ruby | mit | 19 | main | 1,255 | # lib/otto/core/uri_generator.rb
#
# frozen_string_literal: true
require 'uri'
class Otto
module Core
# URI generation module providing path and URL generation for route definitions
module UriGenerator
# Return the URI path for the given +route_definition+
# e.g.
#
# Otto.default... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/freezable.rb | Ruby | mit | 19 | main | 2,713 | # lib/otto/core/freezable.rb
#
# frozen_string_literal: true
class Otto
module Core
# Provides deep freezing capability for configuration objects
#
# This module enables objects to be deeply frozen, preventing any
# modifications to the object itself and all its nested structures.
# This is criti... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/router.rb | Ruby | mit | 19 | main | 8,899 | # lib/otto/core/router.rb
#
# frozen_string_literal: true
require_relative '../mcp/route_parser'
class Otto
module Core
# Router module providing route loading and request dispatching functionality
module Router
def load(path)
path = File.expand_path(path)
raise ArgumentError, "Bad pat... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/helper_registry.rb | Ruby | mit | 19 | main | 5,067 | # lib/otto/core/helper_registry.rb
#
# frozen_string_literal: true
class Otto
module Core
# Helper registration module for extending Otto's Request and Response classes.
# Provides the public API for registering custom helper modules.
module HelperRegistry
# Register request helper modules
#
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/configuration.rb | Ruby | mit | 19 | main | 8,471 | # lib/otto/core/configuration.rb
#
# frozen_string_literal: true
require_relative '../security/csrf'
require_relative '../security/validator'
require_relative '../security/authentication'
require_relative '../security/rate_limiting'
require_relative '../mcp/server'
require_relative 'freezable'
class Otto
module Cor... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/error_handler.rb | Ruby | mit | 19 | main | 12,456 | # lib/otto/core/error_handler.rb
#
# frozen_string_literal: true
require 'securerandom'
require 'json'
require 'rack/request'
class Otto
module Core
# Error handling module providing secure error reporting and logging functionality
module ErrorHandler
def handle_error(error, env)
# Check if th... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/middleware_stack.rb | Ruby | mit | 19 | main | 8,401 | # lib/otto/core/middleware_stack.rb
#
# frozen_string_literal: true
require_relative 'freezable'
class Otto
module Core
# Enhanced middleware stack management for Otto framework.
# Provides better middleware registration, introspection capabilities,
# and improved execution chain management.
class M... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/lifecycle_hooks.rb | Ruby | mit | 19 | main | 2,407 | # lib/otto/core/lifecycle_hooks.rb
#
# frozen_string_literal: true
class Otto
module Core
# Lifecycle hooks module for registering callbacks at various points in request processing.
# Provides the public API for request completion callbacks.
module LifecycleHooks
# Register a callback to be execute... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/file_safety.rb | Ruby | mit | 19 | main | 2,238 | # lib/otto/core/file_safety.rb
#
# frozen_string_literal: true
class Otto
module Core
# File safety module providing secure file access validation and path traversal protection
module FileSafety
def safe_file?(path)
return false if option[:public].nil? || option[:public].empty?
return f... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core/middleware_management.rb | Ruby | mit | 19 | main | 2,553 | # lib/otto/core/middleware_management.rb
#
# frozen_string_literal: true
class Otto
module Core
# Middleware management module for building and configuring the Rack middleware stack.
# Provides the public API for adding middleware and building the application.
module MiddlewareManagement
# Builds t... |
github | delano/otto | https://github.com/delano/otto | lib/otto/privacy/config.rb | Ruby | mit | 19 | main | 7,103 | # lib/otto/privacy/config.rb
#
# frozen_string_literal: true
require 'ipaddr'
require 'securerandom'
require 'digest'
require 'concurrent'
require_relative '../core/freezable'
class Otto
module Privacy
# Configuration for IP privacy features
#
# Privacy is ENABLED by default for public IPs. Private/lo... |
github | delano/otto | https://github.com/delano/otto | lib/otto/privacy/geo_resolver.rb | Ruby | mit | 19 | main | 10,495 | # lib/otto/privacy/geo_resolver.rb
#
# frozen_string_literal: true
require 'ipaddr'
class Otto
module Privacy
# Lightweight geo-location resolution for IP addresses
#
# Provides country-level geo-location without requiring external
# databases or API calls. Supports headers from major CDN/infrastruc... |
github | delano/otto | https://github.com/delano/otto | lib/otto/privacy/ip_privacy.rb | Ruby | mit | 19 | main | 6,610 | # lib/otto/privacy/ip_privacy.rb
#
# frozen_string_literal: true
require 'ipaddr'
require 'digest'
require 'openssl'
require 'socket'
class Otto
module Privacy
# IP address anonymization utilities
#
# Provides methods for masking and hashing IP addresses to enhance
# privacy while maintaining the ab... |
github | delano/otto | https://github.com/delano/otto | lib/otto/privacy/redacted_fingerprint.rb | Ruby | mit | 19 | main | 5,064 | # lib/otto/privacy/redacted_fingerprint.rb
#
# frozen_string_literal: true
require 'securerandom'
require 'time'
require 'uri'
class Otto
module Privacy
# Immutable privacy-safe request fingerprint (aka CrappyFingerprint)
#
# Contains anonymized information about a request that can be used for
# log... |
github | delano/otto | https://github.com/delano/otto | lib/otto/privacy/core.rb | Ruby | mit | 19 | main | 3,089 | # lib/otto/privacy/core.rb
#
# frozen_string_literal: true
class Otto
module Privacy
# Core privacy configuration methods included in the Otto class.
# Provides the public API for configuring IP privacy features.
module Core
# Disable IP privacy to access original IP addresses
#
# IMPOR... |
github | delano/otto | https://github.com/delano/otto | lib/otto/locale/config.rb | Ruby | mit | 19 | main | 1,880 | # lib/otto/locale/config.rb
#
# frozen_string_literal: true
require_relative '../core/freezable'
class Otto
module Locale
# Locale configuration for Otto applications
#
# This class manages locale-related settings including available locales
# and default locale selection.
#
# @example Basic... |
github | delano/otto | https://github.com/delano/otto | lib/otto/locale/middleware.rb | Ruby | mit | 19 | main | 8,402 | # lib/otto/locale/middleware.rb
#
# frozen_string_literal: true
class Otto
module Locale
# Locale detection and resolution middleware
#
# Sets env['otto.locale'] based on:
# 1. URL parameter (?locale=es)
# 2. Session preference (session['locale'])
# 3. HTTP Accept-Language header
# 4. Def... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/route_parser.rb | Ruby | mit | 19 | main | 2,482 | # lib/otto/mcp/route_parser.rb
#
# frozen_string_literal: true
class Otto
module MCP
# Parser for MCP route definitions and resource URIs
class RouteParser
def self.parse_mcp_route(_verb, _path, definition)
# MCP route format: MCP resource_uri HandlerClass.method_name
# Note: The path p... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/registry.rb | Ruby | mit | 19 | main | 2,486 | # lib/otto/mcp/registry.rb
#
# frozen_string_literal: true
class Otto
module MCP
# Registry for managing MCP resources and tools
class Registry
def initialize
@resources = {}
@tools = {}
end
def register_resource(uri, name, description, mime_type, handler)
@reso... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/server.rb | Ruby | mit | 19 | main | 6,929 | # lib/otto/mcp/server.rb
#
# frozen_string_literal: true
require_relative 'protocol'
require_relative 'registry'
require_relative 'route_parser'
require_relative 'auth/token'
require_relative 'schema_validation'
require_relative 'rate_limiting'
class Otto
module MCP
# MCP server implementation providing Model C... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/schema_validation.rb | Ruby | mit | 19 | main | 3,633 | # lib/otto/mcp/schema_validation.rb
#
# frozen_string_literal: true
require 'json'
begin
require 'json_schemer'
rescue LoadError
# json_schemer is optional - graceful fallback
end
class Otto
module MCP
class ValidationError < Otto::BadRequestError; end
# JSON Schema validator for MCP protocol requests... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/rate_limiting.rb | Ruby | mit | 19 | main | 5,626 | # lib/otto/mcp/rate_limiting.rb
#
# frozen_string_literal: true
require 'json'
require_relative '../security/rate_limiting'
begin
require 'rack/attack'
rescue LoadError
# rack-attack is optional - graceful fallback
end
class Otto
module MCP
# Rate limiter for MCP protocol endpoints
class RateLimiter <... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/core.rb | Ruby | mit | 19 | main | 1,061 | # lib/otto/mcp/core.rb
#
# frozen_string_literal: true
class Otto
module MCP
# Core MCP (Model Context Protocol) methods included in the Otto class.
# Provides the public API for enabling and querying MCP server support.
module Core
# Enable MCP (Model Context Protocol) server support
#
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/protocol.rb | Ruby | mit | 19 | main | 5,146 | # lib/otto/mcp/protocol.rb
#
# frozen_string_literal: true
require 'json'
require_relative 'registry'
class Otto
module MCP
# MCP protocol handler providing Model Context Protocol functionality
class Protocol
attr_reader :registry
def initialize(otto_instance)
@otto = otto_instance
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/mcp/auth/token.rb | Ruby | mit | 19 | main | 1,948 | # lib/otto/mcp/auth/token.rb
#
# frozen_string_literal: true
require 'json'
class Otto
module MCP
module Auth
# Token-based authentication for MCP protocol endpoints
class TokenAuth
def initialize(tokens)
@tokens = Array(tokens).to_set
end
def authenticate(env)
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_handlers/base.rb | Ruby | mit | 19 | main | 7,901 | # lib/otto/route_handlers/base.rb
#
# frozen_string_literal: true
require 'json'
require 'securerandom'
class Otto
module RouteHandlers
# Base class for all route handlers
# Provides common functionality and interface
class BaseHandler
attr_reader :route_definition, :otto_instance
def initi... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_handlers/factory.rb | Ruby | mit | 19 | main | 1,692 | # lib/otto/route_handlers/factory.rb
#
# frozen_string_literal: true
require_relative 'base'
require_relative '../security/authentication/route_auth_wrapper'
class Otto
module RouteHandlers
# Factory for creating appropriate handlers based on route definitions
class HandlerFactory
# Create a handler f... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_handlers/class_method.rb | Ruby | mit | 19 | main | 1,052 | # lib/otto/route_handlers/class_method.rb
#
# frozen_string_literal: true
require_relative 'base'
class Otto
module RouteHandlers
# Handler for class methods (existing Otto pattern)
# Route syntax: Controller.action
#
# Class methods receive full Rack request/response access:
# - Method signatur... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_handlers/instance_method.rb | Ruby | mit | 19 | main | 1,117 | # lib/otto/route_handlers/instance_method.rb
#
# frozen_string_literal: true
require_relative 'base'
class Otto
module RouteHandlers
# Handler for instance methods (existing Otto pattern)
# Route syntax: Controller#action
#
# Controller instances receive full Rack request/response access:
# - in... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_handlers/logic_class.rb | Ruby | mit | 19 | main | 4,030 | # lib/otto/route_handlers/logic_class.rb
#
# frozen_string_literal: true
require_relative 'base'
class Otto
module RouteHandlers
# Handler for Logic classes (new in Otto Framework Enhancement)
#
# Logic classes use a constrained signature: initialize(context, params, locale)
# - context: The authent... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_handlers/lambda.rb | Ruby | mit | 19 | main | 1,698 | # lib/otto/route_handlers/lambda.rb
#
# frozen_string_literal: true
require 'securerandom'
require_relative 'base'
class Otto
module RouteHandlers
# Custom handler for lambda/proc definitions (future extension)
class LambdaHandler < BaseHandler
def call(env, extra_params = {})
start_time = Ott... |
github | delano/otto | https://github.com/delano/otto | lib/otto/helpers/base.rb | Ruby | mit | 19 | main | 333 | # lib/otto/helpers/base.rb
#
# frozen_string_literal: true
class Otto
# Base helper methods providing core functionality for Otto applications
module BaseHelpers
# Keep only truly context-independent shared functionality here
# Methods requiring env access should be implemented in the specific helper modul... |
github | delano/otto | https://github.com/delano/otto | lib/otto/helpers/validation.rb | Ruby | mit | 19 | main | 3,600 | # lib/otto/helpers/validation.rb
#
# frozen_string_literal: true
require 'loofah'
class Otto
module Security
# Validation helper methods providing input validation and sanitization
module ValidationHelpers
# Replace filesystem-unsafe characters with an underscore. Borrowed
# verbatim from facets... |
github | xorond/passtrust | https://github.com/xorond/passtrust | Gemfile | Ruby | mit | 19 | master | 351 | source 'https://rubygems.org'
gem 'highline', :require => 'highline/import'
gem 'zxcvbn-ruby', :require => 'zxcvbn'
group :optional do
gem 'clipboard'
gem 'sysrandom', :require => 'sysrandom/securerandom'
gem 'ffi', :platforms => [:mswin, :mingw]
end
require 'optparse'
require 'ostruct'
require 'digest'
require '... |
github | xorond/passtrust | https://github.com/xorond/passtrust | import/passtrust.rb | Ruby | mit | 19 | master | 2,957 | #!/usr/bin/env ruby
class Passtrust
def initialize
@options_length = $options.length
@options_timeout = $options.timeout
@options_clipboard = $options.clipboard
@options_random = $options.random
@options_security = $options.security
@options_verify = $options.verify
@colorizer = ColorTex... |
github | xorond/passtrust | https://github.com/xorond/passtrust | import/colortext.rb | Ruby | mit | 19 | master | 259 | #!/usr/bin/env ruby
class ColorText
def colorize(text, color_code)
"\e[#{color_code}m#{text}\e[0m"
end
def red(text)
colorize(text, 31)
end
def green(text)
colorize(text, 32)
end
def blue(text)
colorize(text, 33)
end
end |
github | xorond/passtrust | https://github.com/xorond/passtrust | import/magic.rb | Ruby | mit | 19 | master | 1,170 | #!/usr/bin/env ruby
class Magic
def base64_encode(word); Base64.encode64(word);end
def sha512_digest(word); Digest::SHA512.hexdigest word; end
def sha384_digest(word); Digest::SHA384.hexdigest word; end
def sha2_digest(word); Digest::SHA2.hexdigest word; end
def sha1_digest(word); Digest::SHA1.hexdigest wor... |
github | mezis/level2 | https://github.com/mezis/level2 | level2.gemspec | Ruby | mit | 19 | master | 740 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.name = 'level2'
spec.version = '0.3.0'
spec.authors = ['Julien Letessier']
spec.email = ['julien.letessier@gmail.com']
spec.su... |
github | mezis/level2 | https://github.com/mezis/level2 | Gemfile | Ruby | mit | 19 | master | 203 | source 'https://rubygems.org'
# Specify your gem's dependencies in level2.gemspec
gemspec
gem 'activesupport', '~> 3'
gem 'appraisal'
gem 'bundler'
gem 'rake'
gem 'rspec'
gem 'guard-rspec'
gem 'pry' |
github | mezis/level2 | https://github.com/mezis/level2 | lib/active_support/cache/level2.rb | Ruby | mit | 19 | master | 2,762 | require 'active_support/cache'
require 'active_support/version'
if ActiveSupport::VERSION::MAJOR == 3
# active_support/cache actually depends on this but doesn't require it:
require 'securerandom'
end
module ActiveSupport
module Cache
class Level2 < Store
attr_reader :stores
def initialize(stor... |
github | mezis/level2 | https://github.com/mezis/level2 | spec/active_support/cache/level2_spec.rb | Ruby | mit | 19 | master | 4,749 | require 'spec_helper'
require 'active_support/cache/level2'
require 'active_support/notifications'
require 'pry'
describe ActiveSupport::Cache::Level2 do
subject do
ActiveSupport::Cache.lookup_store :level2,
L1: [
:memory_store, { size: 10.megabytes }
],
L2: [
:memory_store, { s... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | metadata.rb | Ruby | mit | 19 | master | 707 | name "opsworks_delayed_job"
maintainer "Artsy"
maintainer_email "it@artsymail.com"
license "MIT"
description "Configure and deploy background job workers."
version "0.8"
recipe 'opsworks_delayed_job::setup', 'Set up delayed_job worker.'
recipe 'opsworks_delayed_job::configure',... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | recipes/deploy.rb | Ruby | mit | 19 | master | 1,027 | # Adapted from deploy::rails: https://github.com/aws/opsworks-cookbooks/blob/master/deploy/recipes/rails.rb
include_recipe 'deploy'
node[:deploy].each do |application, deploy|
if deploy[:application_type] != 'rails'
Chef::Log.debug("Skipping opsworks_delayed_job::deploy application #{application} as it is not ... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | recipes/setup.rb | Ruby | mit | 19 | master | 1,068 | # Adapted from unicorn::rails: https://github.com/aws/opsworks-cookbooks/blob/master/unicorn/recipes/rails.rb
include_recipe "opsworks_delayed_job::service"
# setup delayed_job service per app
node[:deploy].each do |application, deploy|
if deploy[:application_type] != 'rails'
Chef::Log.debug("Skipping opsworks... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | recipes/configure.rb | Ruby | mit | 19 | master | 1,507 | # Adapted from rails::configure: https://github.com/aws/opsworks-cookbooks/blob/master/rails/recipes/configure.rb
include_recipe "deploy"
include_recipe "opsworks_delayed_job::service"
node[:deploy].each do |application, deploy|
deploy = node[:deploy][application]
node.default[:deploy][application][:database][:a... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | recipes/service.rb | Ruby | mit | 19 | master | 478 | service "monit" do
supports :status => false, :restart => true, :reload => true
action :nothing
end
node[:deploy].each do |application, deploy|
# Overwrite the unicorn restart command declared elsewhere
# Apologies for the `sleep`, but monit errors with "Other action already in progress" on some boots.
e... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | recipes/undeploy.rb | Ruby | mit | 19 | master | 524 | # Adapted from deploy::rails-undeploy: https://github.com/aws/opsworks-cookbooks/blob/master/deploy/recipes/rails-undeploy.rb
include_recipe 'deploy'
node[:deploy].each do |application, deploy|
if deploy[:application_type] != 'rails'
Chef::Log.debug("Skipping opsworks_delayed_job::undeploy application #{applica... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | recipes/stop.rb | Ruby | mit | 19 | master | 324 | # Adapted from nginx::stop: https://github.com/aws/opsworks-cookbooks/blob/master/nginx/recipes/stop.rb
include_recipe "opsworks_delayed_job::service"
node[:deploy].each do |application, deploy|
execute "stop Rails app #{application}" do
command "sudo monit stop -g delayed_job_#{application}_group"
end
... |
github | joeyAghion/opsworks_delayed_job | https://github.com/joeyAghion/opsworks_delayed_job | attributes/default.rb | Ruby | mit | 19 | master | 1,205 | include_attribute "deploy"
default[:delayed_job] = {}
default[:delayed_job][:pool_size] = 4
case node[:platform_family]
when 'rhel', 'fedora', 'suse'
default[:monit][:includes_dir] = '/etc/monit.d'
else
default[:monit][:includes_dir] = '/etc/monit/conf.d'
end
node[:deploy].each do |application, deploy|
defaul... |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | Rakefile | Ruby | mit | 19 | master | 221 | #!/usr/bin/env rake
require "bundler/gem_tasks"
require "rake/testtask"
desc "Run tests"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end
task default: :test |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | cache_rocket.gemspec | Ruby | mit | 19 | master | 798 | require "./lib/cache_rocket/version"
Gem::Specification.new do |spec|
spec.name = "cache_rocket"
spec.version = CacheRocket::VERSION
spec.authors = ["Tee Parham"]
spec.email = ["tee@neighborland.com"]
spec.description = "Rails rendering extension for server-side html caching"
... |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | test/test_helper.rb | Ruby | mit | 19 | master | 219 | # frozen_string_literal: true
if ENV["TRAVIS"]
require "coveralls"
Coveralls.wear!
end
require "minitest/autorun"
require "mocha/minitest"
require "cache_rocket"
begin
require "pry-byebug"
rescue LoadError
end |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | test/fragment_test.rb | Ruby | mit | 19 | master | 1,442 | # frozen_string_literal: true
require "test_helper"
module CacheRocket
class FragmentTest < Minitest::Spec
describe "#to_s" do
it "equal value" do
assert_equal "yo", Fragment.new("yo").to_s
end
end
describe "#gsub!" do
it "substitute value" do
fragment = Fragment.new("... |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | test/cache_rocket_test.rb | Ruby | mit | 19 | master | 5,164 | # frozen_string_literal: true
require "test_helper"
class CacheRocketTest < Minitest::Spec
class FakeRenderer
include CacheRocket
attr_accessor :html
def safe_concat(value)
@html ||= ""
@html += value
end
end
def dog_name(dog)
dog
end
def reverse(dog)
dog.reverse
en... |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | test/key_test.rb | Ruby | mit | 19 | master | 368 | # frozen_string_literal: true
require "test_helper"
module CacheRocket
class KeyTest < Minitest::Spec
describe "#cache_replace_key" do
it "return key with prefix" do
class KeyFake
include Key
end
key = KeyFake.new
assert_equal "<crk some/thing>", key.cache_replac... |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | lib/cache_rocket.rb | Ruby | mit | 19 | master | 2,442 | # frozen_string_literal: true
require "active_support/core_ext/string"
require "cache_rocket/key"
require "cache_rocket/fragment"
require "cache_rocket/version"
module CacheRocket
include Key
ERROR_MISSING_KEY_OR_BLOCK = "You must either pass a `replace` key or a block to render_cached."
ERROR_MISSING_KEY = "Y... |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | lib/cache_rocket/fragment.rb | Ruby | mit | 19 | master | 986 | # frozen_string_literal: true
module CacheRocket
class Fragment
include Key
def initialize(value)
@value = value.to_s.dup
end
def to_s
@value
end
def gsub!(key, value)
@value.gsub! key, value
end
def replace(hash, collection = nil)
if collection
rep... |
github | neighborland/cache_rocket | https://github.com/neighborland/cache_rocket | lib/cache_rocket/key.rb | Ruby | mit | 19 | master | 361 | # frozen_string_literal: true
module CacheRocket
module Key
# string key containing the partial file name or placeholder key.
# It is a tag that should never be returned to be rendered by the
# client, but if so, it will be hidden since CRK is not a valid html tag.
def cache_replace_key(key)
"<... |
github | namusyaka/airship | https://github.com/namusyaka/airship | airship.gemspec | Ruby | mit | 19 | master | 1,038 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'airship/version'
Gem::Specification.new do |spec|
spec.name = "airship"
spec.version = Airship::VERSION
spec.authors = ["namusyaka"]
spec.email = ["namusyaka@... |
github | namusyaka/airship | https://github.com/namusyaka/airship | lib/airship/management.rb | Ruby | mit | 19 | master | 1,435 | module Airship
module Management
##
# Airship::Management provides some useful methods for use in an environment like CRUD
#
# @example Sinatra
#
# class Sample < Sinatra::Base
# register Airship::Management::Sinatra
#
# index do
# "GET /"
# end
... |
github | namusyaka/airship | https://github.com/namusyaka/airship | lib/airship/attachment.rb | Ruby | mit | 19 | master | 1,004 | module Airship
module Attachment
##
# Airship::Attachment enables to use :to option with verb methods
#
# @example Sinatra
#
# class Sample < Sinatra::Base
# register Airship::Attachment::Sinatra
#
# def hello
# "Hello World"
# end
#
# ... |
github | namusyaka/airship | https://github.com/namusyaka/airship | lib/airship/management/padrino.rb | Ruby | mit | 19 | master | 698 | module Airship
module Management
module Padrino
def self.registered(app)
app.extend ClassMethods
end
module ClassMethods
def index(options = {}, &block)
route 'GET', "", options, &block
end
def show(options = {}, &block)
route 'GET', ":id", o... |
github | namusyaka/airship | https://github.com/namusyaka/airship | lib/airship/management/sinatra.rb | Ruby | mit | 19 | master | 658 | module Airship
module Management
module Sinatra
def self.registered(app)
app.extend ClassMethods
end
module ClassMethods
def index(options = {}, &block)
get "/", options, &block
end
def show(options = {}, &block)
get "/:id", options, &block
... |
github | namusyaka/airship | https://github.com/namusyaka/airship | lib/airship/extensions/padrino.rb | Ruby | mit | 19 | master | 4,149 | module Airship
module Extensions
module Padrino
##
# Airship::Extensions::Padrino separates methods of Padrino::Routing to convenient size.
ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2} unless defined?(ROUTE_PRIORITY)
def route(verb, path, *args, &block)
options = extrac... |
github | namusyaka/airship | https://github.com/namusyaka/airship | lib/airship/attachment/padrino.rb | Ruby | mit | 19 | master | 1,417 | require_relative '../extensions/padrino'
module Airship
module Attachment
module Padrino
def self.registered(app)
app.extend ClassMethods
end
module ClassMethods
include Airship::Extensions::Padrino
def construct_filter(*args, &block)
options = args.... |
github | namusyaka/airship | https://github.com/namusyaka/airship | lib/airship/attachment/sinatra.rb | Ruby | mit | 19 | master | 1,140 | module Airship
module Attachment
module Sinatra
def self.registered(app)
app.extend ClassMethods
end
module ClassMethods
def compile!(verb, path, block, options = {})
options = options.dup
if method_name = options.delete(:to)
block = unbound_met... |
github | namusyaka/airship | https://github.com/namusyaka/airship | test/attachment_test.rb | Ruby | mit | 19 | master | 3,499 | require File.expand_path('../../lib/airship/attachment', __FILE__)
$:.unshift(File.dirname(__FILE__))
require 'helper'
describe Airship::Attachment do
context Sinatra do
describe :to do
before do
mock_app Sinatra::Base do
register Airship::Attachment::Sinatra
def hello
... |
github | namusyaka/airship | https://github.com/namusyaka/airship | test/helper.rb | Ruby | mit | 19 | master | 446 | require 'minitest/autorun'
require 'minitest/spec'
require 'rack/test'
require 'sinatra/base'
require 'padrino-core'
class Sinatra::Base
include MiniTest::Assertions
end
class MiniTest::Spec
include Rack::Test::Methods
class << self
alias context describe
end
def app
Rack::Lint.new(@app)
end
... |
github | namusyaka/airship | https://github.com/namusyaka/airship | test/management_test.rb | Ruby | mit | 19 | master | 2,595 | require File.expand_path('../../lib/airship/management', __FILE__)
$:.unshift(File.dirname(__FILE__))
require 'helper'
describe Airship::Management do
context Sinatra do
describe :routing do
before do
mock_app Sinatra::Base do
register Airship::Management::Sinatra
index { "inde... |
github | TileImageTeamiOS/THStorytellingView | https://github.com/TileImageTeamiOS/THStorytellingView | Podfile | Ruby | mit | 19 | master | 409 | # Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'Demo' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Demo
pod "THTiledImageView"
pod 'SwiftLint'
pod "THScrollViewMinimap"
pod 'Fire... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | qywechat-notifier.gemspec | Ruby | mit | 19 | master | 1,144 | lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "qywechat/notifier/version"
Gem::Specification.new do |spec|
spec.name = "qywechat-notifier"
spec.version = Qywechat::Notifier::VERSION
spec.authors = ["yunyi"]
spec.email = [... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/tasks/create_groupchat.rake | Ruby | mit | 19 | master | 990 | require 'qywechat/notifier'
task create_groupchat: :environment do
raise '请先填写群 ID' unless Qywechat::Notifier::QyAPI.chatid.present?
puts('请输入群聊名:')
name = STDIN.gets().gsub(/\r\n|\n/, '')
raise '群聊名不能为空' unless name.present?
puts('请输入群主名:')
owner = STDIN.gets().gsub(/\r\n|\n/, '')
raise '群主名不能为空' unless... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/exception_notifier/qy_wechat_notifier.rb | Ruby | mit | 19 | master | 1,937 | require 'exception_notification'
require 'qywechat/notifier'
module ExceptionNotifier
class QyWechatNotifier < BaseNotifier
def initialize(options)
super
@filter_exception = options[:filter_exception]
@filter_exception = true if @filter_exception.nil?
end
def call(exception, options={}... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/qywechat/notifier.rb | Ruby | mit | 19 | master | 223 | require 'qywechat/notifier/qy_api'
require "qywechat/notifier/version"
module Qywechat
module Notifier
def self.configure
yield Qywechat::Notifier::QyAPI
end
class Error < StandardError; end
end
end |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/qywechat/notifier/qy_api.rb | Ruby | mit | 19 | master | 465 | require 'qywechat/notifier/qy_api/client'
require 'qywechat/notifier/qy_api/errors'
require 'qywechat/notifier/qy_api/api/message'
require 'qywechat/notifier/qy_api/api/token'
module Qywechat
module Notifier
module QyAPI
def self.api_token
@api_token ||= QyAPI::API::Token.new
end
def s... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/qywechat/notifier/qy_api/errors.rb | Ruby | mit | 19 | master | 465 | module Qywechat::Notifier::QyAPI
module Errors
# 通用异常
Error = Class.new(StandardError)
# HTTP 异常,比如请求超时等
HttpError = Class.new(Error)
# API 异常,比如返回失败状态码
class APIError < Error
attr_reader :errcode, :errmsg
def initialize(errcode, errmsg)
@errcode = errcode
@errms... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/qywechat/notifier/qy_api/client.rb | Ruby | mit | 19 | master | 3,177 | require 'http'
module Qywechat
module Notifier
module QyAPI
class Client
SERVER_SCHEME = 'https'.freeze
SERVER_HOST = 'qyapi.weixin.qq.com'.freeze
def get(path, options = {})
request(:get, path, options)
end
def post(path, options = {})
request(... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/qywechat/notifier/qy_api/api/token.rb | Ruby | mit | 19 | master | 580 | module Qywechat::Notifier::QyAPI
module API
class Token
attr_reader :client
def initialize
@client = Client.new
end
def get_access_token
Rails.cache.fetch('exception_notifier::qy_wechat_notifier', expires_in: 6800.seconds) do
refresh_access_token
end
... |
github | dao42/qywechat-notifier | https://github.com/dao42/qywechat-notifier | lib/qywechat/notifier/qy_api/api/message.rb | Ruby | mit | 19 | master | 493 | module Qywechat::Notifier::QyAPI
module API
class Message
attr_reader :client
def initialize
@client = Client.new
end
def send_groupchat(message)
client.post('/cgi-bin/appchat/send', params: { access_token: Qywechat::Notifier::QyAPI.api_token.get_access_token }, json: {
... |
github | orta/GitDawg | https://github.com/orta/GitDawg | Example/Podfile | Ruby | mit | 19 | master | 918 | inhibit_all_warnings!
# use_frameworks!
platform :ios, '9.0'
node_modules_path = '../node_modules'
react_path = File.join(node_modules_path, 'react-native')
yoga_path = File.join(react_path, 'ReactCommon/yoga')
folly_spec_path = File.join(react_path, 'third-party-podspecs/Folly.podspec')
glog_spec_path = File.join(re... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | Gemfile | Ruby | mit | 19 | master | 1,654 | source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.7.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/spec_helper.rb | Ruby | mit | 19 | master | 4,096 | # 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 require ... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/rails_helper.rb | Ruby | mit | 19 | master | 2,431 | # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby f... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/helpers/welcome_helper_spec.rb | Ruby | mit | 19 | master | 486 | require 'rails_helper'
describe WelcomeHelper do
it "returns true if the date is in advent calendar's date" do
expect(advent_calendar_date?(Date.new(2015, 12, 1))).to be_truthy
end
it "retuns false if the date is before advent calendar's date" do
expect(advent_calendar_date?(Date.new(2015, 11, -1))).to ... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/models/item_spec.rb | Ruby | mit | 19 | master | 353 | require 'rails_helper'
describe Item do
it "retuns title value if title is not empty" do
item = build(:item, title: "title")
expect(item.title).to eq("title")
end
it "returns deafult value if title is empty" do
item = build(:item, title: "")
expect(item.title).to eq(I18n.t("activerecord.attribut... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/models/advent_calendar_item_spec.rb | Ruby | mit | 19 | master | 1,799 | require 'rails_helper'
describe AdventCalendarItem do
it "returns previous advent_calendar_item which has Item" do
create(:advent_calendar_item, date: 1)
expect(AdventCalendarItem.prev(2).first.date).to equal(1)
end
it "returns next advent_calendar_item which has Item" do
create(:advent_calendar_ite... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/controllers/comments_controller_spec.rb | Ruby | mit | 19 | master | 905 | require 'rails_helper'
RSpec.describe CommentsController, :type => :controller do
describe "POST #create" do
it "saves the new comment in the database" do
expect{
post :create, comment: attributes_for(:comment, item_id: 1)
}.to change(Comment, :count).by(1)
end
it "redirect to items#... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/controllers/advent_calendar_items_controller_spec.rb | Ruby | mit | 19 | master | 3,560 | require 'rails_helper'
RSpec.describe AdventCalendarItemsController, :type => :controller do
describe "GET #show" do
it "assigns the requested advent_calendar_item to @advent_calendar_item" do
advent_calendar_item = create(:advent_calendar_item)
get :show, id: advent_calendar_item
expect(assign... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/controllers/attachments_controller_spec.rb | Ruby | mit | 19 | master | 985 | require 'rails_helper'
RSpec.describe AttachmentsController, :type => :controller do
describe "POST #create" do
it "saves the new attachment in the database" do
expect{
post :create, attachment: attributes_for(:attachment)
}.to change(Attachment, :count).by(1)
end
it "returns the jso... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/controllers/items_controller_spec.rb | Ruby | mit | 19 | master | 5,709 | require 'rails_helper'
RSpec.describe ItemsController, :type => :controller do
describe "GET #show" do
before :each do
today = Date.new(2015, 12, 2)
allow(Time.zone).to receive(:today).and_return(today)
end
it "redirects to root if requested item's date doesn't come yet" do
item = crea... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | spec/controllers/welcome_controller_spec.rb | Ruby | mit | 19 | master | 803 | require 'rails_helper'
describe WelcomeController, :type => :controller do
describe "GET #index" do
it 'is Sunday for the first element of @calendar_date' do
get :index
expect(assigns(:calendar_data).first.first.wday).to eq 0
end
it 'is Saturday for the last element of @calendar_date' do
... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | app/models/advent_calendar_item.rb | Ruby | mit | 19 | master | 421 | class AdventCalendarItem < ActiveRecord::Base
has_one :item, dependent: :destroy
has_many :attachments, dependent: :destroy
scope :prev, ->(date) { joins(:item).where("date < ?", date).order(:date).reverse_order}
scope :next, ->(date) { joins(:item).where("date > ?", date).order(:date)}
def published?
se... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | app/models/item.rb | Ruby | mit | 19 | master | 212 | class Item < ActiveRecord::Base
belongs_to :advent_calendar_item
has_many :comments, dependent: :destroy
def title
self[:title].presence || I18n.t("activerecord.attributes.item.title_empty")
end
end |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | app/helpers/welcome_helper.rb | Ruby | mit | 19 | master | 203 | module WelcomeHelper
def advent_calendar_date?(date)
date.month == Constants::MONTH &&
date.day >= Constants::START_DAY &&
date.day <= Constants::END_DAY
end
end |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | app/controllers/attachments_controller.rb | Ruby | mit | 19 | master | 564 | class AttachmentsController < ApplicationController
protect_from_forgery with: :null_session
def create
attachment = Attachment.new(attachment_params)
if attachment.save
render json: {
image_name: attachment.image.identifier,
image_url: attachment.image.url
}
else
ren... |
github | nanonanomachine/radvent | https://github.com/nanonanomachine/radvent | app/controllers/items_controller.rb | Ruby | mit | 19 | master | 1,422 | class ItemsController < ApplicationController
def new
@date = params[:date]
@item = Item.new(advent_calendar_item_id: params[:id])
@attachment = Attachment.new(advent_calendar_item_id: params[:id])
end
def create
@item = Item.new(item_params)
if params[:preview_button]
render :preview
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.