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 | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/headers.rb | Ruby | mit | 89 | master | 2,469 | require 'delegate'
module M2R
# Normalize headers access so that it is not case-sensitive
# @api public
class Headers
include Enumerable
# @param [Hash, #inject] hash Collection of headers
# @param [true, false] compatible Whether the hash already contains
# downcased strings only. If so it is... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/connection_factory.rb | Ruby | mit | 89 | master | 1,477 | require 'ostruct'
module M2R
# {Connection} factory so that every thread can use it generate its own
# {Connection} for communication with Mongrel2.
#
# @api public
class ConnectionFactory
class Options < Struct.new(:sender_id, :recv_addr, :send_addr)
# @param [String, nil] sender_id {ZMQ::IDENTITY... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/reply.rb | Ruby | mit | 89 | master | 376 | require 'm2r/response'
require 'm2r/response/content_length'
require 'm2r/response/to_request'
module M2R
# Response object to be used without any other framework
# doing the job of handling content lenght and dealing with
# 'Connection' header.
#
# @api public
class Reply < Response
include Response::... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/rack_handler.rb | Ruby | mit | 89 | master | 1,330 | require 'm2r'
require 'rack'
module M2R
# Handle Mongrel2 requests using Rack application
# @private
class RackHandler < Handler
attr_accessor :app
def initialize(app, connection_factory, parser)
@app = app
super(connection_factory, parser)
end
def process(request)
script_name... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/handler.rb | Ruby | mit | 89 | master | 4,802 | module M2R
# Basic handler, scaffold for your own Handler.
# Overwrite hook methods to define behavior.
# After calling #listen the Handler will block
# waiting for request from connection generated
# by {M2R::Handler#connection_factory}, process them and send
# reponses back.
#
# @api public
# @abst... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/request.rb | Ruby | mit | 89 | master | 3,195 | require 'set'
require 'm2r/http/close'
require 'm2r/request/base'
require 'm2r/request/upload'
require 'm2r/headers'
module M2R
# Abstraction over Mongrel 2 request
# @api public
class Request
# @api private
TRUE_STRINGS = Set.new(%w(true yes on 1).map(&:freeze)).freeze
# @api private
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/response.rb | Ruby | mit | 89 | master | 3,421 | require 'm2r/http/close'
require 'm2r/response/content_length'
require 'm2r/response/to_request'
module M2R
# Simplest possible abstraction layer over HTTP request
#
# @api public
class Response
include HTTP::Close
# @private
VERSION = "HTTP/1.1".freeze
# @private
CRLF = "\r\... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/multithread_handler.rb | Ruby | mit | 89 | master | 516 | module M2R
class MultithreadHandler
attr_reader :threads
def initialize(singlethread_handler_factory)
@singlethread_handler_factory = singlethread_handler_factory
end
def listen
@threads = 8.times.map do
Thread.new do
handler = @singlethread_handler_factory.new
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/http/close.rb | Ruby | mit | 89 | master | 749 | module M2R
module HTTP
# Detect that whether connection should be closed
# based on http protocol version and `Connection' header
# We do not support persistent connections for HTTP 1.0
module Close
# @return [true, false] Information whether HTTP Connection should
# be closed after pr... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/response/content_length.rb | Ruby | mit | 89 | master | 546 | module M2R
class Response
# Adds Content-Length header based on body size
# This is mostly required when you use bare
# Response class without any framework on top of it.
# HTTP clients require such header when there is
# body in response. Otherwise they hang out.
#
# @api public
modul... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/response/to_request.rb | Ruby | mit | 89 | master | 750 | module M2R
class Response
# Handles the logic of having response with proper
# http version and 'Connection' header in relation to
# given request
#
# @api public
module ToRequest
# params [Request] request Request that response handles
# params [true, false] identical Whether htt... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/response/always_close.rb | Ruby | mit | 89 | master | 436 | require 'm2r/response'
module M2R
class Response
# Use to disable persisent connections even though
# your client would prefer otherwise.
#
# @api public
module AlwaysClose
def close?
true
end
def headers(value = GETTER)
if value == GETTER
h = super
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/request/base.rb | Ruby | mit | 89 | master | 537 | module M2R
# Logic for typical Mongrel2 request with no fancy features such as
# async upload
#
# @private
module Base
# @return [StringIO] Request body encapsulated in IO compatible object
# @api public
def body_io
@body_io ||= begin
b = StringIO.new(body)
b.set_encoding(Enc... |
github | perplexes/m2r | https://github.com/perplexes/m2r | lib/m2r/request/upload.rb | Ruby | mit | 89 | master | 1,325 | module M2R
# Logic for Mongrel2 request delivered using async-upload feature
# Contains methods for recognizing such requests and reading them.
# @private
module Upload
# @return [true,false] True if this is async-upload related request
# @api public
def upload?
!!@mongrel_headers['x-mongrel2-... |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/Rakefile | Ruby | mit | 89 | master | 852 | COOKBOOKS_DIR = File.expand_path('../cookbooks', __FILE__)
ROLE_DIR = File.expand_path('../roles', __FILE__)
require 'chef'
require 'posix/spawn'
namespace :roles do
desc "Convert ruby roles from ruby to json, creating/overwriting json files."
task :to_json do
Dir.glob(File.join(ROLE_DIR, '*.rb')) do |... |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/m2r/metadata.rb | Ruby | mit | 89 | master | 247 | maintainer "YOUR_COMPANY_NAME"
maintainer_email "YOUR_EMAIL"
license "All rights reserved"
description "Installs/Configures m2r"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.0" |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/essential/metadata.rb | Ruby | mit | 89 | master | 253 | maintainer "YOUR_COMPANY_NAME"
maintainer_email "YOUR_EMAIL"
license "All rights reserved"
description "Installs/Configures essential"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.0" |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/essential/recipes/default.rb | Ruby | mit | 89 | master | 216 | #
# Cookbook Name:: essential
# Recipe:: default
#
# Copyright 2012, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
package 'htop' do
action :install
end
package 'vim' do
action :install
end |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/ruby-build/metadata.rb | Ruby | mit | 89 | master | 259 | maintainer "Arkency"
maintainer_email "michal.lomnicki@gmail.com"
license "All rights reserved"
description "Installs/Configures ruby-build"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.1" |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/ruby-build/definitions/ruby.rb | Ruby | mit | 89 | master | 1,791 | define :ruby do
version = params[:version]
home_dir = params[:home]
ruby_dir = "#{home_dir}/#{version}"
ruby_build_dir = "#{home_dir}/ruby-build"
rubygems = params[:rubygems]
owner = params[:owner]
bin_dir = "#{ruby_dir}/bin"
ruby_bin = "#{bin_dir}/ruby"
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/ruby-build/recipes/default.rb | Ruby | mit | 89 | master | 203 | package "git-core" do
action :install
end
%w[git-core zlib1g-dev libssl-dev libreadline-dev libxml2-dev libxslt1-dev libmysqlclient-dev].each do |name|
package name do
action :install
end
end |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/mongrel2/metadata.rb | Ruby | mit | 89 | master | 252 | maintainer "YOUR_COMPANY_NAME"
maintainer_email "YOUR_EMAIL"
license "All rights reserved"
description "Installs/Configures mongrel2"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.0" |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/mongrel2/recipes/default.rb | Ruby | mit | 89 | master | 925 | #
# Cookbook Name:: mongrel2
# Recipe:: default
#
# Copyright 2012, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
%w[uuid-dev uuid-runtime libsqlite3-dev sqlite3].each do |name|
package name do
action :install
end
end
source = "https://github.com/zedshaw/mongrel2/tarball/v1.8.0"
name = "... |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/build-essential/metadata.rb | Ruby | mit | 89 | master | 344 | maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs C compiler / build tools"
version "1.0.0"
recipe "build-essential", "Installs C compiler and build tools on Linux"
%w{ fedora redhat centos ubuntu debian }.each do... |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/build-essential/recipes/default.rb | Ruby | mit | 89 | master | 1,061 | #
# Cookbook Name:: build-essential
# Recipe:: default
#
# Copyright 2008-2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.... |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/zmq/metadata.rb | Ruby | mit | 89 | master | 247 | maintainer "YOUR_COMPANY_NAME"
maintainer_email "YOUR_EMAIL"
license "All rights reserved"
description "Installs/Configures zmq"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.0" |
github | perplexes/m2r | https://github.com/perplexes/m2r | kitchen/cookbooks/zmq/recipes/default.rb | Ruby | mit | 89 | master | 953 | #
# Cookbook Name:: zmq
# Recipe:: default
#
# Copyright 2012, Arkency
#
# All rights reserved - Do Not Redistribute
#
package 'uuid-dev'
zmq = node['zmq'] || {}
zmq_v = zmq['version'] || '2.2.0'
#zmq_v = zmq['version'] || '3.2.1-rc2'
name = "zeromq-#{zmq_v}.tar.gz"
unpack = 'zeromq-' + zmq_v.split("-").f... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/acceptance/examples_test.rb | Ruby | mit | 89 | master | 961 | require 'test_helper'
module M2R
class ExamplesTest < MiniTest::Unit::TestCase
include MongrelHelper
def test_rack_example
user = TestUser.new
user.visit("/handler")
user.see!("SENDER", "PATH", "HEADERS", "x-forwarded-for", "x-forwarded-for", "BODY")
end
def test_handler_example
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/support/mongrel_helper.rb | Ruby | mit | 89 | master | 748 | require 'timeout'
module MongrelHelper
attr_accessor :pid
def setup
check_mongrel
`cd example && m2sh load -config mongrel2.conf --db config.sqlite`
self.pid = Process.spawn("bundle exec foreman start --procfile=example/Procfile", pgroup: 0, out: "/dev/null", err: "/dev/null")
wait_until_mongrel_r... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/support/test_user.rb | Ruby | mit | 89 | master | 801 | require 'bbq/test'
require 'bbq/test_user'
require 'support/capybara'
class TestUser < Bbq::TestUser
include MiniTest::Assertions
def initialize
super(:driver => :mechanize)
end
def see!(*args)
msg = "Expected to see %s but not found"
args.each { |arg| assert has_content?(arg), msg % arg }
end
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/support/test_handler.rb | Ruby | mit | 89 | master | 1,222 | require 'thread'
require 'm2r/handler'
class TestHandler < M2R::Handler
attr_reader :called_methods
def initialize(connection_factory, parser)
super
@mutex = Mutex.new
@called_methods = []
Thread.current[:called_methods] = []
end
def on_wait()
unless Thread.current[:called_methods].empty?
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/connection_factory_test.rb | Ruby | mit | 89 | master | 782 | require 'test_helper'
require 'securerandom'
module M2R
class ConnectionFactoryTest < MiniTest::Unit::TestCase
def test_factory
sender_id = "sid"
request_addr = "req"
response_addr = "req"
pull = stub(:pull)
pub = stub(:pub)
context = stub(:context)
context.expe... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/m2r_test.rb | Ruby | mit | 89 | master | 967 | require 'test_helper'
require 'timeout'
module M2R
class ModuleTest < MiniTest::Unit::TestCase
def setup
if context = M2R.instance_variable_get(:@zmq_context)
context.send(:remove_finalizer) if context.respond_to?(:remove_finalizer)
M2R.instance_variable_set(:@zmq_context, nil)
end
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/rack_handler_test.rb | Ruby | mit | 89 | master | 2,895 | require 'test_helper'
require 'm2r/rack_handler'
require 'm2r/connection_factory'
require 'tempfile'
class HelloWorld
def call(env)
return [200, {'Content-Type' => 'text/plain'}, ["Hello world!"]]
end
end
class HelloWorldFile
def call(env)
Thread.current[:tempfile] = t = Tempfile.new("asd")
t << "He... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/request_parsing_test.rb | Ruby | mit | 89 | master | 1,408 | require 'test_helper'
module M2R
class TestRequestParsing < MiniTest::Unit::TestCase
def test_parse
data = %q[FAKESENDER 0 / 97:{"PATH":"/","host":"default","METHOD":"HEAD","VERSION":"HTTP/1.1","URI":"/","URL_SCHEME":"https"},0:,]
request = Parser.new.parse(data)
assert_equal "/", request.path... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/connection_test.rb | Ruby | mit | 89 | master | 5,240 | require 'test_helper'
require 'securerandom'
module M2R
class ConnectionTest < MiniTest::Unit::TestCase
def setup
@request_addr = "inproc://#{SecureRandom.hex}"
@response_addr = "inproc://#{SecureRandom.hex}"
@push = M2R.zmq_context.socket(ZMQ::PUSH)
assert_equal 0, @push.bind(@request... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/multithread_handler_test.rb | Ruby | mit | 89 | master | 2,051 | require 'test_helper'
module M2R
class MultithreadHandlerTest < MiniTest::Unit::TestCase
SLEEP_TIME = 3
MARGIN_TIME = 1
WAIT_TIME = 1
class ThreadTestHandler < TestHandler
def process(request)
sleep(SLEEP_TIME)
super
return Thread.current.object_id.to_s
end
... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/headers_test.rb | Ruby | mit | 89 | master | 1,734 | require 'test_helper'
module M2R
class HeadersTest < MiniTest::Unit::TestCase
def test_case_insensitivity
headers = Headers.new({"Content-Type" => "CT"})
assert_equal "CT", headers['content-type']
assert_equal "CT", headers['Content-Type']
assert_equal "CT", headers['Content-type']
en... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/handler_test.rb | Ruby | mit | 89 | master | 3,514 | require 'test_helper'
module M2R
class HandlerTest < MiniTest::Unit::TestCase
def test_lifecycle_for_disconnect
connection = stub(:receive => "", :close => nil)
connection.stubs(:connection).returns(connection)
parser = stub(:parse => disconnect_request)
h = TestHandler.new(connection, p... |
github | perplexes/m2r | https://github.com/perplexes/m2r | test/unit/response_test.rb | Ruby | mit | 89 | master | 3,336 | require 'test_helper'
module M2R
class ResponseTest < MiniTest::Unit::TestCase
def test_response_with_nil_body
ok = Response.new.status(200).headers({"Transfer-Encoding" => "chunked"}).body(nil)
http = "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"
assert_equal http, ok.to_s
end
... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | Gemfile | Ruby | mit | 89 | master | 300 | source 'https://rubygems.org'
gemspec
group :development, :test do
gem 'rake'
gem 'debug'
end
group :development do
gem 'appraisal'
gem 'benchmark-ips'
gem 'slim', '~> 5.0'
gem 'appraisal-run', '~> 1.0'
end
group :test do
gem 'rspec-rails'
gem 'capybara', '~> 3.0'
end
gem "csv" |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | rux-rails.gemspec | Ruby | mit | 89 | master | 759 | $:.unshift File.join(File.dirname(__FILE__), 'lib')
require 'rux-rails/version'
Gem::Specification.new do |s|
s.name = 'rux-rails'
s.version = ::RuxRails::VERSION
s.authors = ['Cameron Dutro']
s.email = ['camertron@gmail.com']
s.homepage = 'http://github.com/camertron/rux-rails'
s.description = s.... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | Appraisals | Ruby | mit | 89 | master | 394 | appraise 'rails-7.0' do
ruby '~> 3.1'
gem 'rails', '~> 7.0.0'
gem 'concurrent-ruby', '< 1.3.5'
end
appraise 'rails-7.1' do
ruby '~> 3.2'
gem 'rails', '~> 7.1.0'
end
appraise 'rails-7.2' do
ruby '~> 3.3'
gem 'rails', '~> 7.2.0'
end
appraise 'rails-8.0' do
ruby '~> 3.4'
gem 'rails', '~> 8.0.0'
en... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | Rakefile | Ruby | mit | 89 | master | 248 | require 'bundler'
require 'rspec/core/rake_task'
require 'rubygems/package_task'
require 'rux-rails'
Bundler::GemHelper.install_tasks
task default: :spec
desc 'Run specs'
RSpec::Core::RakeTask.new do |t|
t.pattern = './spec/**/*_spec.rb'
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | lib/rux-rails.rb | Ruby | mit | 89 | master | 765 | module RuxRails
autoload :Components, 'rux-rails/components'
autoload :OutputBuffer, 'rux-rails/output_buffer'
autoload :RuxLoader, 'rux-rails/rux_loader'
autoload :TagBuilder, 'rux-rails/tag_builder'
autoload :TemplateHandler, 'rux-rails/template_handler'
autoload :Visitor, 'rux-... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | lib/rux-rails/output_buffer.rb | Ruby | mit | 89 | master | 256 | require 'action_view'
module RuxRails
class OutputBuffer < ActionView::OutputBuffer
def safe_append(obj)
Array(obj).each { |o| self.safe_append=(o) }
end
def append(obj)
Array(obj).each { |o| self.append=(o) }
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | lib/rux-rails/engine.rb | Ruby | mit | 89 | master | 1,259 | require 'onload'
module RuxRails
class Engine < ::Rails::Engine
isolate_namespace RuxRails
config.rux = ActiveSupport::OrderedOptions.new
initializer 'rux-rails.initialize', before: 'onload.initialize' do |app|
if config.rux.transpile.nil? && (Rails.env.development? || Rails.env.test?)
co... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | lib/rux-rails/template_handler.rb | Ruby | mit | 89 | master | 291 | module RuxRails
module TemplateHandler
def self.call(template, source = nil)
# rails 5 passes 1 argument (template), rails 6 passes two arguments
# (template, source)
source ||= template.source
::Rux.to_ruby(source, visitor: RuxRails.visitor)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | lib/rux-rails/tasks/transpile.rake | Ruby | mit | 89 | master | 477 | require 'rux'
require 'set'
namespace :rux do
task transpile: :environment do
ignore_file = if Rails.application.config.rux.ignore_path
Onload::IgnoreFile.load(Rails.application.config.rux.ignore_path)
end
Dir.glob(Rails.root.join('**/*.rux')) do |file|
rux_file = Rux::File.new(file)
r... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/hidden_field.rb | Ruby | mit | 89 | master | 257 | # frozen_string_literal: true
module Rails
class HiddenField < FormInput
def initialize(name:, **kwargs)
@name = name
@kwargs = normalize_kwargs(kwargs)
end
def call
builder.hidden_field(@name, **@kwargs)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/form_with.rb | Ruby | mit | 89 | master | 254 | # frozen_string_literal: true
require "use_context"
module Rails
class FormWith < BaseComponent
include UseContext::ContextMethods
def initialize(*args, **kwargs)
@args = args
@kwargs = normalize_kwargs(kwargs)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/form_input.rb | Ruby | mit | 89 | master | 449 | # frozen_string_literal: true
require "use_context"
module Rails
class BuilderNotFoundError < StandardError; end
class FormInput < BaseComponent
include UseContext::ContextMethods
def builder
use_context(:rux, :form_builder).tap do |builder|
unless builder
raise BuilderNotFoundEr... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/text_field.rb | Ruby | mit | 89 | master | 253 | # frozen_string_literal: true
module Rails
class TextField < FormInput
def initialize(name:, **kwargs)
@name = name
@kwargs = normalize_kwargs(kwargs)
end
def call
builder.text_field(@name, **@kwargs)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/button_to.rb | Ruby | mit | 89 | master | 391 | # frozen_string_literal: true
module Rails
class ButtonTo < BaseComponent
def initialize(url:, label: nil, **kwargs)
@url = url
@label = label
@kwargs = normalize_kwargs(kwargs)
end
def call
if @label
button_to(@label, @url, **@kwargs)
else
button_to(@url, *... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/link_to.rb | Ruby | mit | 89 | master | 385 | # frozen_string_literal: true
module Rails
class LinkTo < BaseComponent
def initialize(url:, label: nil, **kwargs)
@url = url
@label = label
@kwargs = normalize_kwargs(kwargs)
end
def call
if @label
link_to(@label, @url, **@kwargs)
else
link_to(@url, **@kwar... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/button.rb | Ruby | mit | 89 | master | 259 | # frozen_string_literal: true
module Rails
class Button < BaseComponent
def initialize(label: "Button", **kwargs)
@label = label
@kwargs = normalize_kwargs(kwargs)
end
def call
button_tag(@label, **@kwargs)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/password_field.rb | Ruby | mit | 89 | master | 261 | # frozen_string_literal: true
module Rails
class PasswordField < FormInput
def initialize(name:, **kwargs)
@name = name
@kwargs = normalize_kwargs(kwargs)
end
def call
builder.password_field(@name, **@kwargs)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/base_component.rb | Ruby | mit | 89 | master | 337 | # frozen_string_literal: true
module Rails
class BaseComponent < ViewComponent::Base
private
def normalize_kwargs(kwargs)
klass = kwargs.delete(:class)
klasses = kwargs.delete(:classes)
return kwargs unless klass || klasses
kwargs[:class] = class_names(klass, klasses)
kwargs
... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/label.rb | Ruby | mit | 89 | master | 253 | # frozen_string_literal: true
module Rails
class Label < FormInput
def initialize(name:, **kwargs)
@name = name
@kwargs = normalize_kwargs(kwargs)
end
def call
builder.label(@name, content, **@kwargs)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rails/content_tag.rb | Ruby | mit | 89 | master | 279 | # frozen_string_literal: true
module Rails
class ContentTag < BaseComponent
def initialize(tag:, **kwargs)
@tag = tag
@kwargs = kwargs
@kwargs = normalize_kwargs(kwargs)
end
def call
content_tag(@tag, content, **@kwargs)
end
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | app/components/rux/component.rb | Ruby | mit | 89 | master | 326 | # frozen_string_literal: true
module Rux
# For rendering a component that you already have an instance of, perhaps
# created in another component's constructor
class Component < ViewComponent::Base
def initialize(instance:)
@instance = instance
end
def call
render(@instance)
end
en... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/html_safety_spec.rb | Ruby | mit | 89 | master | 248 | require 'spec_helper'
describe "html safety", type: :component do
it "escapes HTML" do
render_inline(HtmlSafetyComponent.new(value: "<p>Foo</p>"))
expect(rendered_content).to eq(
"<div><p>Foo</p></div>"
)
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/spec_helper.rb | Ruby | mit | 89 | master | 1,017 | ENV['RAILS_ENV'] ||= 'test'
require 'rails'
require 'action_controller/railtie'
require 'rux-rails'
Dir.chdir(File.join(*%w(spec dummy))) do
require File.expand_path(File.join(*%w(dummy config application)), __dir__)
RuxRails::DummyApplication.initialize!
end
require 'rspec/rails'
module RuxRails
module SpecH... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/controllers/home_controller_spec.rb | Ruby | mit | 89 | master | 1,358 | require 'spec_helper'
describe HomeController, type: :request do
describe '#index' do
before(:each) do
# Force a recompile to avoid test pollution
HomeComponent.respond_to?(:__vc_compile) ? HomeComponent.__vc_compile : HomeComponent.compile
end
it 'transpiles the file' do
get '/'
... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rux/component_spec.rb | Ruby | mit | 89 | master | 266 | require 'spec_helper'
describe Rux::Component, type: :component do
it 'renders the given instance' do
render_inline(Rux::Component.new(instance: Image.new(src: "foo.png")))
expect(rendered_content).to include("<img src=\"/images/foo.png\" />")
end
end |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/button_spec.rb | Ruby | mit | 89 | master | 664 | require 'spec_helper'
describe Rails::Button, type: :component do
it 'renders with defaults' do
render_inline(described_class.new)
expect(rendered_content).to eq("<button name=\"button\" type=\"submit\">Button</button>")
end
it 'renders with the given label' do
render_inline(described_class.new(labe... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/content_tag_spec.rb | Ruby | mit | 89 | master | 403 | require 'spec_helper'
describe Rails::ContentTag, type: :component do
it 'renders an empty tag by default' do
render_inline(described_class.new(tag: :div))
expect(rendered_content).to eq("<div></div>")
end
it 'renders content within the tags' do
render_inline(described_class.new(tag: :div)) { 'Hello... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/link_to_spec.rb | Ruby | mit | 89 | master | 505 | require 'spec_helper'
describe Rails::LinkTo, type: :component do
it 'renders with defaults' do
render_inline(described_class.new(url: "http://example.com", label: "foo"))
expect(rendered_content).to eq("<a href=\"http://example.com\">foo</a>")
end
it 'renders the content between the tags' do
render... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/button_to_spec.rb | Ruby | mit | 89 | master | 845 | require 'spec_helper'
describe Rails::ButtonTo, type: :component do
it 'renders with defaults' do
render_inline(described_class.new(url: "http://example.com"))
expect(rendered_content).to include(
/<form .* action=\"http:\/\/example.com".*<button type=\"submit\"><\/button>/
)
end
it 'renders w... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/password_field_spec.rb | Ruby | mit | 89 | master | 338 | require 'spec_helper'
describe Rails::PasswordField, type: :component do
it 'renders with defaults' do
render_inline(Rails::FormWith.new(url: "/foo")) do
described_class.new(name: "bar").render_in(view_context)
end
expect(rendered_content).to include("<input type=\"password\" name=\"bar\" id=\"bar... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/form_with_spec.rb | Ruby | mit | 89 | master | 605 | require 'spec_helper'
describe Rails::FormWith, type: :component do
it 'renders with defaults' do
render_inline(described_class.new(url: "/foo"))
expect(rendered_content).to include("<form action=\"/foo\" accept-charset=\"UTF-8\" method=\"post\"><input type=\"hidden\" name=\"authenticity_token\"")
end
i... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/label_spec.rb | Ruby | mit | 89 | master | 604 | require 'spec_helper'
describe Rails::Label, type: :component do
it 'renders with defaults' do
render_inline(Rails::FormWith.new(url: "/foo")) do
described_class.new(name: "bar").render_in(view_context)
end
expect(rendered_content).to include("<label for=\"bar\">Bar</label>")
end
it 'renders ... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/hidden_field_spec.rb | Ruby | mit | 89 | master | 355 | require 'spec_helper'
describe Rails::HiddenField, type: :component do
it 'renders with defaults' do
render_inline(Rails::FormWith.new(url: "/foo")) do
described_class.new(name: "bar").render_in(view_context)
end
expect(rendered_content).to include("<input autocomplete=\"off\" type=\"hidden\" name... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/components/rails/text_field_spec.rb | Ruby | mit | 89 | master | 330 | require 'spec_helper'
describe Rails::TextField, type: :component do
it 'renders with defaults' do
render_inline(Rails::FormWith.new(url: "/foo")) do
described_class.new(name: "bar").render_in(view_context)
end
expect(rendered_content).to include("<input type=\"text\" name=\"bar\" id=\"bar\" />")
... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | spec/dummy/config/application.rb | Ruby | mit | 89 | master | 397 | # require both of these to support multiple versions of view_component
require 'view_component'
require 'view_component/engine'
module RuxRails
class DummyApplication < ::Rails::Application
if config.respond_to?(:load_defaults)
config.load_defaults(
Gem.loaded_specs['railties'].version.to_s.split('... |
github | camertron/rux-rails | https://github.com/camertron/rux-rails | performance/rux_rails_bench.rb | Ruby | mit | 89 | master | 1,547 | require 'rux'
require 'benchmark/ips'
puts "Booting Rails..."
require 'rails/all'
require 'slim'
require 'view_component'
# Configure Rails Environment
ENV["RAILS_ENV"] = "production"
require File.expand_path("../spec/dummy/config/application.rb", __dir__)
RuxRails::DummyApplication.initialize!
class BenchmarksCon... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | Guardfile | Ruby | mit | 89 | main | 209 | # frozen_string_literal: true
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rake', task: 'test' do
watch(%r{^test/.+$})
watch(%r{^lib/.+$})
watch(%r{^views/.+$})
end |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | Rakefile | Ruby | mit | 89 | main | 230 | # frozen_string_literal: true
require './lib/site-inspector'
require 'rspec/core/rake_task'
desc 'Run specs'
RSpec::Core::RakeTask.new do |t|
t.pattern = 'spec/**/*_spec.rb'
t.rspec_opts = ['--order', 'rand', '--color']
end |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | site-inspector.gemspec | Ruby | mit | 89 | main | 1,904 | # frozen_string_literal: true
require File.expand_path './lib/site-inspector/version', File.dirname(__FILE__)
Gem::Specification.new do |s|
s.name = 'site-inspector'
s.version = SiteInspector::VERSION
s.summary = 'A Ruby port and v2 of Site Inspector (https://github.... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector.rb | Ruby | mit | 89 | main | 2,179 | # frozen_string_literal: true
require 'open-uri'
require 'addressable/uri'
require 'public_suffix'
require 'typhoeus'
require 'parallel'
require 'cliver'
require 'whois'
require 'cgi'
require 'resolv'
require 'dotenv/load'
require 'naughty_or_nice'
require_relative 'cliver/dependency_ext'
class SiteInspector
autolo... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/domain.rb | Ruby | mit | 89 | main | 8,196 | # frozen_string_literal: true
class SiteInspector
class Domain
attr_reader :host
def initialize(host)
@host = DomainParser.parse(host)
if @host&.trd == 'www'
@host.instance_variable_set(:@trd, nil)
elsif @host&.trd&.start_with?('www.')
@host.instance_variable_set(:@trd, @h... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint.rb | Ruby | mit | 89 | main | 7,092 | # frozen_string_literal: true
require 'site-inspector/endpoint/check'
require 'site-inspector/endpoint/accessibility'
require 'site-inspector/endpoint/content'
require 'site-inspector/endpoint/dns'
require 'site-inspector/endpoint/headers'
require 'site-inspector/endpoint/hsts'
require 'site-inspector/endpoint/https'
... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/formatter.rb | Ruby | mit | 89 | main | 2,670 | # frozen_string_literal: true
require 'active_support/core_ext/string/inflections'
require 'nokogiri'
class SiteInspector
module Formatter
ACRONYMS = %w[
acme cdn cms crm dns dnssec dnt hsts http https id ip ipv6 json paas pki sld ssl tld tls trd txt ui uri url whois www xml xss
].freeze
def form... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/disk_cache.rb | Ruby | mit | 89 | main | 1,001 | # frozen_string_literal: true
class SiteInspector
class DiskCache
def initialize(dir = nil, replace = nil)
@dir = dir || ENV.fetch('CACHE', nil)
@replace = replace || ENV.fetch('CACHE_REPLACE', nil)
@memory = {}
end
def get(request)
return unless File.exist?(path(request))
... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/cache.rb | Ruby | mit | 89 | main | 244 | # frozen_string_literal: true
class SiteInspector
class Cache
def memory
@memory ||= {}
end
def get(request)
memory[request]
end
def set(request, response)
memory[request] = response
end
end
end |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/headers.rb | Ruby | mit | 89 | main | 1,251 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Headers < Check
COMMON = %w[
strict-transport-security
content-security-policy
x-frame-options
server
x-xss-protection
].freeze
COMMON.each do |header|
name = header.gsub(/^x-... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/https.rb | Ruby | mit | 89 | main | 753 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Https < Check
def scheme?
scheme == 'https'
end
def valid?
scheme? && response && response.return_code == :ok
end
def bad_chain?
scheme? && response && response.return_code == :ssl_cacer... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/dns.rb | Ruby | mit | 89 | main | 3,175 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Dns < Check
class LocalhostError < StandardError; end
def self.resolver
require 'dnsruby'
@resolver ||= begin
resolver = Dnsruby::Resolver.new
resolver.config.nameserver = ['8.8.8.8', '8.8.4.4'... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/cookies.rb | Ruby | mit | 89 | main | 1,133 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Cookies < Check
def any?(&block)
if cookie_header.nil? || cookie_header.empty?
false
elsif block
all.any?(&block)
else
true
end
end
alias cookies? any?
def... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/check.rb | Ruby | mit | 89 | main | 1,075 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Check
attr_reader :endpoint
# A check is an abstract class that takes an Endpoint object
# and is extended to preform the specific site inspector checks
#
# It is automatically accessable within the endpoint obj... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/whois.rb | Ruby | mit | 89 | main | 1,006 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Whois < Check
def domain
return @domain if defined? @domain
@domain = begin
whois.lookup host
rescue Timeout::Error
nil
end
end
def ip
return @ip if defined? @ip
... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/accessibility.rb | Ruby | mit | 89 | main | 3,293 | # frozen_string_literal: true
require 'json'
require 'open3'
class SiteInspector
class Endpoint
class Accessibility < Check
class Pa11yError < RuntimeError; end
STANDARDS = {
wcag2a: 'WCAG2A', # Default standard
wcag2aa: 'WCAG2AA',
wcag2aaa: 'WCAG2AAA',
section508: '... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/well_known.rb | Ruby | mit | 89 | main | 2,125 | # frozen_string_literal: true
require 'yaml'
class SiteInspector
class Endpoint
class WellKnown < Check
BASE_PATH = './.well-known/'
class << self
def well_knowns
data = File.expand_path '../../data/well-known.yml', File.dirname(__FILE__)
wks = YAML.load_file(data)
... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/hsts.rb | Ruby | mit | 89 | main | 2,479 | # frozen_string_literal: true
class SiteInspector
class Endpoint
# Utility parser for HSTS headers.
# RFC: http://tools.ietf.org/html/rfc6797
class Hsts < Check
STATUS_ENDPOINT = 'https://hstspreload.org/api/v2/status'
def valid?
return false if header.empty?
pairs.none? { |... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/content.rb | Ruby | mit | 89 | main | 3,936 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Content < Check
PATHS = [
'robots.txt', 'sitemap.xml', 'humans.txt', 'vulnerability-disclosure-policy', 'security.txt', '.well-known/security.txt', 'data.json'
].freeze
class << self
def paths
@pat... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/sniffer.rb | Ruby | mit | 89 | main | 1,479 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Sniffer < Check
OPEN_SOURCE_FRAMEWORKS = [
# Sniffles
:drupal,
:joomla,
:movabletype,
:phpbb,
:wordpress,
# Internal
:php,
:expression_engine,
:cowboy
... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/site-inspector/endpoint/wappalyzer.rb | Ruby | mit | 89 | main | 1,756 | # frozen_string_literal: true
class SiteInspector
class Endpoint
class Wappalyzer < Check
class WappalyzerError < RuntimeError; end
class << self
def wappalyzer?
return @wappalyzer_detected if defined? @wappalyzer_detected
@wappalyzer_detected = !!wappalyzer.detect
... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | lib/cliver/dependency_ext.rb | Ruby | mit | 89 | main | 568 | # frozen_string_literal: true
module Cliver
class Dependency
# Memoized shortcut for detect
# Returns the path to the detected dependency
# Raises an error if the dependency was not satisfied
def path
@path ||= detect!
end
# Returns the version of the resolved dependency
def versio... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | spec/site_inspector_spec.rb | Ruby | mit | 89 | main | 1,108 | # frozen_string_literal: true
require 'spec_helper'
describe SiteInspector do
before do
described_class.instance_variable_set(:@cache, nil)
described_class.instance_variable_set(:@timeout, nil)
end
it 'defaults to ephemeral cache' do
with_env 'CACHE', nil do
expect(described_class.cache.class... |
github | benbalter/site-inspector | https://github.com/benbalter/site-inspector | spec/spec_helper.rb | Ruby | mit | 89 | main | 332 | # frozen_string_literal: true
require 'bundler/setup'
require 'webmock/rspec'
require 'fileutils'
require 'site-inspector'
WebMock.disable_net_connect!
def with_env(key, value)
old_env = ENV.fetch(key, nil)
ENV[key] = value
yield
ENV[key] = old_env
end
def tmpdir
File.expand_path '../tmp', File.dirname(__... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.