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 | mattetti/mimetype-fu | https://github.com/mattetti/mimetype-fu | lib/mimetype_fu.rb | Ruby | mit | 83 | master | 869 | require 'tempfile'
require 'extensions_const'
class File
def self.mime_type?(file)
case file
when File, Tempfile
unless RUBY_PLATFORM.include? 'mswin32'
mime = `file --mime -br "#{file.path}"`.strip
else
mime = EXTENSIONS[File.extname(file.path).gsub('.','').downcase.to_sym]
... |
github | mattetti/mimetype-fu | https://github.com/mattetti/mimetype-fu | spec/spec_helper.rb | Ruby | mit | 83 | master | 952 | ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
require 'test_help'
def create_file(filename, mode='w')
@file = File.new(File.dirname(__FILE__) + "/fixtures/#{filename}", mode)
end
def close
@file.close
@file = @file.path
end
def open_file(filename... |
github | mattetti/mimetype-fu | https://github.com/mattetti/mimetype-fu | spec/mime_type_spec.rb | Ruby | mit | 83 | master | 3,041 | require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + '/../lib/mimetype_fu'
# Ideally, the two solutions (`file` command versus simply looking at the extension)
# would return identical results, but thats not the case. `file` differentiates
# between file sizes, and has a tendency to classif... |
github | yegor256/jekyll-github-deploy | https://github.com/yegor256/jekyll-github-deploy | Rakefile | Ruby | mit | 83 | master | 538 | # frozen_string_literal: true
# SPDX-FileCopyrightText: Copyright (c) 2014-2026 Yegor Bugayenko
# SPDX-License-Identifier: MIT
require 'rubygems'
require 'rake'
require 'rake/clean'
CLEAN = FileList['coverage', 'rdoc']
def name
@name ||= File.basename(Dir['*.gemspec'].first, '.*')
end
def version
Gem::Specific... |
github | yegor256/jekyll-github-deploy | https://github.com/yegor256/jekyll-github-deploy | jgd.gemspec | Ruby | mit | 83 | master | 970 | # frozen_string_literal: true
# SPDX-FileCopyrightText: Copyright (c) 2014-2026 Yegor Bugayenko
# SPDX-License-Identifier: MIT
require 'English'
Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.required_ruby_version = '>= 2.3'... |
github | yegor256/jekyll-github-deploy | https://github.com/yegor256/jekyll-github-deploy | Gemfile | Ruby | mit | 83 | master | 425 | # frozen_string_literal: true
# SPDX-FileCopyrightText: Copyright (c) 2014-2026 Yegor Bugayenko
# SPDX-License-Identifier: MIT
source 'https://rubygems.org'
gemspec
gem 'rake', '~>13.2', require: false
gem 'rubocop', '~>1.59', require: false
gem 'rubocop-minitest', '>0', require: false
gem 'rubocop-performance', '>0... |
github | vic/typhon | https://github.com/vic/typhon | Rakefile | Ruby | bsd-3-clause | 83 | master | 1,620 | require 'rubygems/package_task'
task :default => :spec
desc "Run the specs (default)"
task :spec => :build do
sh "mspec spec"
end
desc "Clean generated files"
task :clean do
rm_f FileList["**/*.{pyc,rbc}"]
rm_rf FileList["pkg"]
end
task :build
spec = Gem::Specification.new do |s|
require File.expand_path('... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/main.rb | Ruby | bsd-3-clause | 83 | master | 3,039 | require 'typhon/version'
module Typhon
# Command line interface to Typhon.
#
# It should support the same command line options than the `python'
# program. And additional options specific to Typhon and Rubinius.
#
# But currently we only take a python source name to compile and
# run.
#
class Main
... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment.rb | Ruby | bsd-3-clause | 83 | master | 597 | require 'typhon/environment/python_object'
require 'typhon/environment/type'
# included part-way through type so it can define functions.
# 'typhon/environment/function'
require 'typhon/environment/module'
require 'typhon/environment/built_ins'
Typhon::Environment.set_python_module(Typhon::Environment::BuiltInModule) ... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/version.rb | Ruby | bsd-3-clause | 83 | master | 1,501 | require 'rbconfig'
module Typhon
module Version
extend self
attr_accessor :major, :minor, :tiny, :commit, :codename, :tagline
self.codename = "Snakes on rbx-head"
self.tagline = "Snakes on rbx-head"
self.major = 0
self.minor = 0
self.tiny = 1
def commit
@commit ||= `git rev... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/repl.rb | Ruby | bsd-3-clause | 83 | master | 1,285 | require 'readline'
module Typhon
class ReadEvalPrintLoop
def initialize(compiler_print = Compiler::Print.new, show_lineno = false)
@compiler_print = compiler_print
@show_lineno = show_lineno
end
def prompt(lineno = 1, level = 1, print_line = false)
line = ("%03i " % [line] if print_lin... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/parser.rb | Ruby | bsd-3-clause | 83 | master | 429 | require 'open3'
module Typhon
class Parser
class Error < StandardError; end
def parse(code)
cmd = ['python']
cmd << File.expand_path('../../../bin/pyparse.py', __FILE__)
stdio = Open3.popen3(*cmd) { |stdin, stdout, stderr|
stdin.puts code
stdin.close
#raise Error,... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/code_loader.rb | Ruby | bsd-3-clause | 83 | master | 3,844 | module Typhon
module CodeLoader
# This is really really evil. We want literals from a python
# compiled file to actually be python objects, not ruby objects,
# so we go through the CompileMethod's literal arrays (and all
# child CompiledMethod objects' literals arrays) and replace
# objects as ap... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/compiler/compiler.rb | Ruby | bsd-3-clause | 83 | master | 2,042 | module Typhon
class Compiler < Rubinius::ToolSets::Runtime::Compiler
def self.compiled_filename(filename)
if filename =~ /.py$/
filename + ".rbc"
else
filename + ".compiled.rbc"
end
end
def self.always_recompile=(flag)
@always_recompile = flag
end
def se... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/compiler/stages.rb | Ruby | bsd-3-clause | 83 | master | 4,122 | require 'pp'
require 'typhon/parser'
require 'typhon/ast'
module Typhon
class Generator < Rubinius::ToolSets::Runtime::Generator
def push_typhon_env
push_cpath_top
find_const :Typhon
find_const :Environment
end
def py_send(name, arity)
send name, arity
end
end
class Sta... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/numbers.rb | Ruby | bsd-3-clause | 83 | master | 5,429 | # This requires some special explanation. Normally I wouldn't
# want to reopen the Integer classes like this, but I can't really
# see any way around it since creation of them is disabled (and
# officially they are technically singletons anyways). As such,
# they have to be turned into python objects directly.
module ... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/python_object.rb | Ruby | bsd-3-clause | 83 | master | 6,195 | module Typhon
module Environment
# Default implementation that gets replaced later.
def self.get_python_module()
nil
end
# Defines the behaviour of an instance of a python object.
module PythonObjectMixin
class DictWrapper
def initialize(h)
@h = h
end
... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/string.rb | Ruby | bsd-3-clause | 83 | master | 1,438 | module Typhon
module Environment
class PythonString < String
include PythonObjectMixin
def initialize(obj = '')
if !obj.is_a?(String) && obj.respond_to?(:to_py)
obj = obj.to_py
case obj.py_type
when Type
# python appears to ignore __str__ on type obje... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/dict.rb | Ruby | bsd-3-clause | 83 | master | 330 | module Typhon
module Environment
class Dict
include PythonObjectMixin
def initialize(hash)
@hash = hash
py_init(DictType)
end
end
python_class_c :DictType, [ObjectBase], 'dict', 'dict' do
end
end
end
class Hash
def to_py
Typhon::Environment::Dict.new(self)
... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/singletons.rb | Ruby | bsd-3-clause | 83 | master | 1,467 | module Typhon
module Environment
python_class_c :NoneType, [ObjectBase], 'NoneType', "These aren't the droids you're looking for" do
extend FunctionTools
python_class_method(:__new__) do |c|
return nil
end
python_method(:__repr__) do |c|
return "None"
end
pyth... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/list.rb | Ruby | bsd-3-clause | 83 | master | 337 | module Typhon
module Environment
class List
include PythonObjectMixin
def initialize(rb_list)
@list = rb_list
py_init(ListType)
end
end
python_class_c :ListType, [ObjectBase], 'list', 'list' do
end
end
end
class Array
def to_py
Typhon::Environment::List.new... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/module.rb | Ruby | bsd-3-clause | 83 | master | 1,157 | require 'typhon/environment/type'
module Typhon
module Environment
python_class_c :PythonModule, [ObjectBase], 'module',
"A python source file is represented as a module object " +
"top level expressions are executed on this context." do
extend FunctionTools
# Initializes a new Python m... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/type.rb | Ruby | bsd-3-clause | 83 | master | 6,482 | require 'typhon/environment/python_object'
module Typhon
module Environment
Type = Rubinius::Type
# We need to do some magic to make these two things refer to each
# other in the right way. Type is an ObjectBase of type Type, which has
# several recursive relationships. So we define ObjectBase first,... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/exceptions.rb | Ruby | bsd-3-clause | 83 | master | 6,770 | module Typhon
module Environment
ExceptionsModule = PythonModule.new(nil, 'exceptions', <<-DOC, nil)
Python's standard exception class hierarchy.
Exceptions found here are defined both in the exceptions module and the
built-in namespace. It is recommended that user-defined exceptions
inherit from Exception. Se... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/function.rb | Ruby | bsd-3-clause | 83 | master | 2,932 | module Typhon
module Environment
python_class_c :Function, [ObjectBase], 'function', 'function object' do
# we special case this one because all other code-paths involve calling python.
def invoke(cm = nil, scope = nil, &block)
PythonObject.new(Function) do
self.py_set(:__call__, sel... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/tuple.rb | Ruby | bsd-3-clause | 83 | master | 540 | module Typhon
module Environment
class Tuple
include PythonObjectMixin
attr_reader :tuple
def initialize(rbx_tuple)
@tuple = rbx_tuple
py_init(TupleType)
end
end
python_class_c :TupleType, [ObjectBase], 'tuple', 'tuple' do
extend FunctionTools
pytho... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/environment/built_ins.rb | Ruby | bsd-3-clause | 83 | master | 1,603 | module Typhon
module Environment
BuiltInModule = PythonModule.new(nil, "__builtin__", "Built in objects and methods", nil) do
py_set(:module, PythonModule)
py_set(:object, ObjectBase)
py_set(:type, Type)
py_set(:function, Function)
py_set(:boundfunction, BoundFunction)
py_set(:... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes.rb | Ruby | bsd-3-clause | 83 | master | 1,802 | module Typhon
module AST
Nodes = Hash.new
# Converts a ruby sexp (array literals) into Typhon AST
def self.from_sexp(sexp)
return nil if sexp.nil? || sexp.empty?
name = :"#{sexp.first}Node"
type = Nodes[name]
raise "Unknown sexp type: #{name}" unless type
convert = lambda d... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/control.rb | Ruby | bsd-3-clause | 83 | master | 554 | module Typhon
module AST
class DiscardNode < Node
def bytecode(g)
pos(g)
@expr.bytecode(g)
g.pop # ignore whatever it did.
end
end
class StmtNode < ClosedScope
def discard?
@nodes.last.kind_of? DiscardNode
end
def bytecode(g)
pos(g)
... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/module.rb | Ruby | bsd-3-clause | 83 | master | 1,831 | module Typhon
module AST
class Body < ClosedScope
def initialize(statement, line)
@statement = statement
@line = line
end
def bytecode(g)
pos(g)
@statement.bytecode(g)
g.pop unless @statement.discard?
g.push_self
end
end
class Mod... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/variables.rb | Ruby | bsd-3-clause | 83 | master | 2,762 | module Typhon
module AST
class VarNode < Node
# Finds a normal variable, doesn't go into BuiltIn, though.
def find_normal_var(g, name)
name = name.to_sym
scope = g.state.scope
# First try to find it in a function scope.
scope_depth = 0
while (scope.kind_of?(Exec... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/literal.rb | Ruby | bsd-3-clause | 83 | master | 1,212 | module Typhon
module AST
class ConstNode < Node
def bytecode(g)
pos(g)
if (@value.respond_to?(:to_py))
g.push_literal(@value.to_py)
else
g.push_literal(@value)
end
end
end
class TupleNode < Node
def bytecode(g)
pos(g)
... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/class.rb | Ruby | bsd-3-clause | 83 | master | 686 | module Typhon
module AST
class ClassNode < ClosedScope
def bytecode(g)
pos(g);
@name = @name.to_sym
g.push_const(:ObjectClass)
@bases.each do |base|
base.bytecode(g)
end
g.make_array(@bases.count)
g.push_literal(@name)
g.push... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/function.rb | Ruby | bsd-3-clause | 83 | master | 6,682 | module Typhon
module AST
class Arguments
attr_reader :argnames, :defaults
def initialize(argnames, defaults)
@argnames = argnames
@defaults = defaults
end
def required_args
@argnames.length - @defaults.length
end
def total_args
@argnames.lengt... |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/utility.rb | Ruby | bsd-3-clause | 83 | master | 304 | module Typhon
module AST
class PrintnlNode < Node
def bytecode(g)
pos(g)
g.push_const(:Typhon)
g.find_const(:Environment)
@nodes.each do |node|
node.bytecode(g)
end
g.send :__py_print, @nodes.count
end
end
end
end |
github | vic/typhon | https://github.com/vic/typhon | lib/typhon/ast/nodes/operators.rb | Ruby | bsd-3-clause | 83 | master | 1,683 | module Typhon
module AST
class SubscriptNode < Node
def bytecode(g)
pos(g)
@expr.bytecode(g)
@subs.each do |sub|
sub.bytecode(g)
end
g.send(:[], @subs.count) # in the end this is wrong, just this way temporarily to expose __dict__
end
end
... |
github | vic/typhon | https://github.com/vic/typhon | spec/examples_spec.rb | Ruby | bsd-3-clause | 83 | master | 1,114 | require 'open3'
require 'strscan'
base = File.expand_path("..", File.dirname(__FILE__))
Dir.glob(File.expand_path("**/*.out", File.dirname(__FILE__))) do |file|
scanner = StringScanner.new(File.read file)
runner_re = /^#!\s*(typhon|python)\s+(.*)(\n|\r\n)/
runners = {}
runners[scanner[1]] = scanner[2] while... |
github | vic/typhon | https://github.com/vic/typhon | spec/custom/utils/script.rb | Ruby | bsd-3-clause | 83 | master | 384 | # Custom options for mspec-run
#
class MSpecRun
def custom_options(options)
options.compiler
options.parser
end
end
# Custom options for mspec-ci
#
class MSpecCI
def custom_options(options)
options.compiler
options.parser
end
end
# Custom options for mspec-tag
#
class MSpecTag
def custom_opt... |
github | vic/typhon | https://github.com/vic/typhon | spec/custom/utils/options.rb | Ruby | bsd-3-clause | 83 | master | 638 | # Custom MSpec options
#
class MSpecOptions
def compiler
# The require is inside the method because this file has to be able to be
# loaded in MRI and there are parts of the custom ensemble that are
# Rubinius specific (primarily iseq, which could potentially be fixed by
# better structuring the compi... |
github | vic/typhon | https://github.com/vic/typhon | spec/custom/runner/relates.rb | Ruby | bsd-3-clause | 83 | master | 2,673 | # NOTE: Copied from Rubinius
#
# SpecDataRelation enables concise specs that involve several different forms
# of the same data. This is specifically useful for the parser and compiler
# specs where the output of each stage is essentially related to the input
# Ruby source. Together with the #relates spec method, it en... |
github | vic/typhon | https://github.com/vic/typhon | spec/custom/matchers/parse_as.rb | Ruby | bsd-3-clause | 83 | master | 367 | class ParseAsMatcher
def initialize(expected)
@expected = expected
end
def matches?(actual)
@actual = Typhon::Parser.new.parse(actual)
@actual == @expected
end
def failure_message
["Expected:\n#{@actual.inspect}\n",
"to equal:\n#{@expected.inspect}"]
end
end
class Object
def parse_... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | can_flag.gemspec | Ruby | mit | 49 | master | 748 | Gem::Specification.new do |s|
s.name = %q{can_flag}
s.version = "1.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Courtenay Gasking"]
s.email = ["courtenay@entp.com"]
s.extra_rdoc_files = ["MIT-LICENSE"]
s.files = Dir["lib/**/*.rb... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | Rakefile | Ruby | mit | 49 | master | 552 | require 'rake'
require 'rake/testtask'
require 'rdoc/task'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the can_flag plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/*_test.rb'
t.verbose = true
t.warning = false
end
desc 'Generate documentation for the can_fla... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | lib/can_flag.rb | Ruby | mit | 49 | master | 5,865 | # CanFlag
require 'can/flag/flag'
module Caboose
module Can
module Flag
extend ActiveSupport::Concern
included do
extend ClassMethods
include ActiveSupport::Callbacks
end
module ClassMethods
# Call can_be_flagged from your content model, or from anything
... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | lib/can/flag/flag.rb | Ruby | mit | 49 | master | 2,831 | module Caboose
module Can
module Flag
class Flag < ActiveRecord::Base
set_table_name 'flags'
# serialize :flag, Symbol
belongs_to :flaggable, :polymorphic => true
# This will contain the names of all models that can_be_flagged
cattr_accessor :flaggable_models
... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | lib/can_flag/rails_commands.rb | Ruby | mit | 49 | master | 1,041 | # Stolen from Technoweenie's restful_authentication
Rails::Generator::Commands::Create.class_eval do
def route_resource(*resources)
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
sentinel = 'ActionController::Routing::Routes.draw do |map|'
logger.route "map.resource #{resource_list}"
... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | test/can_be_flagged_options_test.rb | Ruby | mit | 49 | master | 667 | require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class Article < ActiveRecord::Base
end
class Content < ActiveRecord::Base
set_table_name 'articles' # cheater
end
class CanBeFlaggedOptionsTest < Test::Unit::TestCase
def setup
Article.class_eval do
can_be_flagged :reasons => [:p... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | test/test_helper.rb | Ruby | mit | 49 | master | 1,144 | $:.unshift(File.dirname(__FILE__) + '/../lib')
ENV['RAILS_ENV'] = 'test'
# ENV['Rails.root'] ||= '~/dev/oss/altered_beast/' #File.dirname(__FILE__) + '/../../../..'
require 'test/unit'
require 'rubygems'
require 'active_record'
require 'active_support'
require 'can_flag'
# require File.expand_path(File.join(ENV['Ra... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | test/content_association_test.rb | Ruby | mit | 49 | master | 638 | require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class Article < ActiveRecord::Base
end
class ContentAssociationTest < Test::Unit::TestCase
def test_article_can_has_flag
Article.class_eval {
can_be_flagged
}
assert_not_nil Article.reflect_on_association(:flags)
ass... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | test/user_association_test.rb | Ruby | mit | 49 | master | 1,170 | require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class User < ActiveRecord::Base; end
class UserAssociationTest < Test::Unit::TestCase
def test_creates_user_association_in_flag
assert_nil Caboose::Can::Flag::Flag.reflect_on_association(:user)
User.class_eval do
can_flag
e... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | test/flag_test.rb | Ruby | mit | 49 | master | 1,211 | require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class Article < ActiveRecord::Base
can_be_flagged
attr_accessor :called_back
def after_flagged
@called_back = true
end
end
class FlagTest < Test::Unit::TestCase
def test_calls_back_to_article
article = Article.create :t... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | test/content_attributes_test.rb | Ruby | mit | 49 | master | 621 | require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class Article < ActiveRecord::Base
can_be_flagged
end
class ContentAttributesTest < Test::Unit::TestCase
def test_article_cab_has_attributes_like_states
a = Article.new
assert a.respond_to?(:flagged?), "Should have the 'flagged?' m... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | test/schema.rb | Ruby | mit | 49 | master | 381 | ActiveRecord::Schema.define(:version => 0) do
create_table :articles do |t|
t.string :title
t.string :body
t.string :user_id
end
create_table :users do |t|
t.string :login
end
create_table :flags do |t|
t.integer :user_id
t.integer :flaggable_id
t.string :flaggable_type
... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | generators/can_flag/can_flag_generator.rb | Ruby | mit | 49 | master | 11,318 | require 'can_flag/rails_commands'
class CanFlagGenerator < Rails::Generator::NamedBase
default_options :skip_migration => false
# :include_activation => false
attr_reader :controller_name,
:controller_class_path,
:controller_file_path,
... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | generators/can_flag/templates/migration.rb | Ruby | mit | 49 | master | 453 | class <%= migration_name %> < ActiveRecord::Migration
def self.up
create_table "flags", :force => true do |t|
t.integer :user_id
t.integer :flaggable_id
t.string :flaggable_type
t.integer :flaggable_user_id
t.string :reason
t.timestamps
end
# todo: add index on reason... |
github | courtenay/can_flag | https://github.com/courtenay/can_flag | generators/can_flag/templates/simple_controller.rb | Ruby | mit | 49 | master | 1,171 | # This controller handles the 'flag as inappropriate' functionality
class <%= controller_class_name %>Controller < ApplicationController
before_filter :login_required
# You probably have your own 'admin' filter
before_filter :admin_required, :only => :index
protected
def admin_required
raise AccessDenied unle... |
github | org-binbab/gem-vagrant-wrapper | https://github.com/org-binbab/gem-vagrant-wrapper | vagrant-wrapper.gemspec | Ruby | mit | 49 | master | 1,147 | $:.unshift(File.dirname(__FILE__) + '/lib')
require 'vagrant-wrapper/version'
Gem::Specification.new do |s|
s.name = 'vagrant-wrapper'
s.version = VagrantWrapper::VERSION
s.date = VagrantWrapper::RELEASE_DATE
s.summary = "Wrapper/binstub for os packaged version of Vagrant."
s.descripti... |
github | org-binbab/gem-vagrant-wrapper | https://github.com/org-binbab/gem-vagrant-wrapper | spec/vagrant_wrapper_spec.rb | Ruby | mit | 49 | master | 7,290 | # Some of these tests require that vagrant be installed on the local system
require 'spec_helper'
describe VagrantWrapper do
let(:version_regex) { Regexp.new('^Vagrant (version)?') }
before :all do
@tmp_dir = "#{Dir.tmpdir}/vagrant-wrapper_gemtest"
@tmp_old_vagrant = "#{@tmp_dir}/vagrant.old"
@tmp_n... |
github | org-binbab/gem-vagrant-wrapper | https://github.com/org-binbab/gem-vagrant-wrapper | lib/vagrant-wrapper.rb | Ruby | mit | 49 | master | 4,812 | #
# Author:: BinaryBabel OSS (<projects@binarybabel.org>)
# Homepage:: http://www.binarybabel.org
# License:: MIT
#
# For bugs, docs, updates:
#
# http://code.binbab.org
#
# Copyright 2013 sha1(OWNER) = df334a7237f10846a0ca302bd323e35ee1463931
#
# See LICENSE file for more details.
#
require 'vagrant-wrapper/excep... |
github | org-binbab/gem-vagrant-wrapper | https://github.com/org-binbab/gem-vagrant-wrapper | lib/vagrant-wrapper/version.rb | Ruby | mit | 49 | master | 369 | #
# Author:: BinaryBabel OSS (<projects@binarybabel.org>)
# Homepage:: http://www.binarybabel.org
# License:: MIT
#
# For bugs, docs, updates:
#
# http://code.binbab.org
#
# Copyright 2013 sha1(OWNER) = df334a7237f10846a0ca302bd323e35ee1463931
#
# See LICENSE file for more details.
#
class VagrantWrapper
VERSION... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | rapporteur.gemspec | Ruby | mit | 49 | main | 1,475 | # frozen_string_literal: true
require_relative 'lib/rapporteur/version'
Gem::Specification.new do |spec|
spec.name = 'rapporteur'
spec.version = Rapporteur::VERSION
spec.authors = ['Envy Labs']
spec.email = ['']
spec.description = 'An engine that provides common status polling... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | Appraisals | Ruby | mit | 49 | main | 482 | # frozen_string_literal: true
appraise 'rails7.1' do
gem 'rails', '~> 7.1.0'
gem 'rspec-rails', '~> 7.0'
end
appraise 'rails7' do
gem 'rails', '~> 7.1'
end
appraise 'rails8.0' do
gem 'rails', '~> 8.0.0'
end
appraise 'rails-latest' do
gem 'rails'
end
appraise 'sinatra2.x' do
gem 'sinatra', '~> 2.0'
end
... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | config/routes.rb | Ruby | mit | 49 | main | 735 | # frozen_string_literal: true
Rapporteur::Engine.routes.draw do
get '/(.:format)', to: 'statuses#show', as: :status
end
explicitly_mounted = Rails.application.routes.routes.any? { |r|
(Rapporteur::Engine == r.app) || (r.app.respond_to?(:app) && Rapporteur::Engine == r.app.app)
}
unless explicitly_mounted
Activ... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/spec_helper.rb | Ruby | mit | 49 | main | 712 | # frozen_string_literal: true
require 'bundler/setup'
require 'combustion'
ENV['RAILS_ENV'] ||= 'test'
Combustion.initialize! :action_controller, :active_record
require 'rspec/rails'
require 'rspec/collection_matchers'
require 'rapporteur/rspec3'
require 'route_helper'
RSpec.configure do |config|
config.disable_m... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/requests/sinatra_spec.rb | Ruby | mit | 49 | main | 1,365 | # frozen_string_literal: true
ENV['RACK_ENV'] = 'test'
begin
require 'sinatra/base'
require 'rack/test'
RSpec.describe 'Sinatra' do
include Rack::Test::Methods
class TestApp < Sinatra::Base
set :host_authorization, { permitted_hosts: [] }
get '/status.json' do
content_type :json
... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/requests/revision_check_spec.rb | Ruby | mit | 49 | main | 560 | # frozen_string_literal: true
RSpec.describe 'A status request with a RevisionCheck', type: :request do
before do
allow(Rapporteur::Revision).to receive(:current).and_return('revisionidentifier')
Rapporteur.add_check(Rapporteur::Checks::RevisionCheck)
get(rapporteur.status_path(format: 'json'))
end
... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/requests/active_record_check_spec.rb | Ruby | mit | 49 | main | 927 | # frozen_string_literal: true
RSpec.describe 'A status request with an ActiveRecordCheck', type: :request do
context 'with an unerring ActiveRecord connection' do
before do
Rapporteur.add_check(Rapporteur::Checks::ActiveRecordCheck)
get(rapporteur.status_path(format: 'json'))
end
it_behaves_... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/requests/time_check_spec.rb | Ruby | mit | 49 | main | 529 | # frozen_string_literal: true
RSpec.describe 'A status request with a TimeCheck', type: :request do
before do
Rapporteur.add_check(Rapporteur::Checks::TimeCheck)
allow(Time).to receive(:now).and_return(Time.gm(2013, 8, 23))
get(rapporteur.status_path(format: 'json'))
end
it_behaves_like 'a success... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/requests/halt_spec.rb | Ruby | mit | 49 | main | 713 | # frozen_string_literal: true
RSpec.describe 'A check calling #halt!', type: :request do
let(:parsed_response) { JSON.parse(response.body) }
before do
Rapporteur.add_check { |checker| checker.add_message(:one, 1) }
Rapporteur.add_check { |checker| checker.add_message(:two, 2).halt! }
Rapporteur.add_ch... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/requests/messsage_addition_spec.rb | Ruby | mit | 49 | main | 1,394 | # frozen_string_literal: true
RSpec.describe 'A status request with a check that modifies messages', type: :request do
context 'creating a message with a block' do
context 'with an unerring response' do
before do
Rapporteur.add_check { |checker| checker.add_message('git_repo', 'git@github.com:organ... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/requests/no_checks_spec.rb | Ruby | mit | 49 | main | 219 | # frozen_string_literal: true
RSpec.describe 'A status request with no checks', type: :request do
before do
get(rapporteur.status_path(format: 'json'))
end
it_behaves_like 'a successful status response'
end |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/models/check_list_spec.rb | Ruby | mit | 49 | main | 1,381 | # frozen_string_literal: true
RSpec.describe Rapporteur::CheckList, type: :model do
let(:list) { described_class.new }
context '#add' do
it 'adds the given object to the list' do
list.add(check = double)
expect(list.to_a).to include(check)
end
it 'does not return duplicate entries' do
... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/models/message_list_spec.rb | Ruby | mit | 49 | main | 3,169 | # frozen_string_literal: true
RSpec.describe Rapporteur::MessageList, type: :model do
let(:list) { Rapporteur::MessageList.new(:errors) }
before do I18n.backend.reload! end
context '#add' do
it 'returns the MessageList instance.' do
expect(list.add(:test, 'message')).to equal(list)
end
it 'a... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | spec/routing/routes_spec.rb | Ruby | mit | 49 | main | 258 | # frozen_string_literal: true
RSpec.describe 'status route', type: :routing do
it 'routes / to rapporteur/statuses#show' do
expect(get: '/').to route_to(action: 'show',
controller: 'rapporteur/statuses')
end
end |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur.rb | Ruby | mit | 49 | main | 2,164 | # frozen_string_literal: true
require 'rapporteur/engine' if defined?(Rails)
require 'rapporteur/version'
# Rapporteur is a Rails Engine which provides your application with an
# application status endpoint.
#
module Rapporteur
autoload :CheckList, 'rapporteur/check_list'
autoload :Checker, 'rapporteur/checker'
... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/checker.rb | Ruby | mit | 49 | main | 5,705 | # frozen_string_literal: true
module Rapporteur
# The center of the Rapporteur library, Checker manages holding and running
# the custom checks, holding any application error messages, and provides the
# controller with that data for rendering.
#
class Checker
extend CheckerDeprecations
def initiali... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/rspec3.rb | Ruby | mit | 49 | main | 2,224 | # frozen_string_literal: true
require 'rapporteur'
shared_examples_for 'a successful status response' do
let(:parsed_body) { JSON.parse(response.body) }
it 'responds with HTTP 200' do
expect(response.response_code).to(eq(200))
end
context 'the response headers' do
it 'contains a Content-Type JSON he... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/revision.rb | Ruby | mit | 49 | main | 1,728 | # frozen_string_literal: true
module Rapporteur
# Manages memoizing and maintaining the current application revision.
#
class Revision
class_attribute :_current
# Public: Returns the current revision as a String.
#
def self.current
self._current ||= calculate_current
end
# Public:... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/checks.rb | Ruby | mit | 49 | main | 918 | # frozen_string_literal: true
module Rapporteur
module Checks
autoload :ActiveRecordCheck, 'rapporteur/checks/active_record_check'
# A check which simply reports the current clock time in UTC. This check is
# useful because it shows that the status end point is not being cached and
# allows you to d... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/check_list.rb | Ruby | mit | 49 | main | 1,449 | # frozen_string_literal: true
module Rapporteur
# Manages a list of checks.
#
# The goals of this object are to store and return the check objects given to
# it in the same order they were given (in Ruby 1.8 and newer). And, to
# ensure that the same check is not added twice to be run.
#
# Previously, a ... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/checker_deprecations.rb | Ruby | mit | 49 | main | 523 | # frozen_string_literal: true
require 'active_support/deprecation'
module Rapporteur
module CheckerDeprecations
def add_check(*args, &block)
ActiveSupport::Deprecation.warn('use Rapporteur.add_check', caller)
Rapporteur.add_check(*args, &block)
end
def clear
ActiveSupport::Deprecation... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/message_list.rb | Ruby | mit | 49 | main | 4,020 | # frozen_string_literal: true
require 'forwardable'
require 'set'
module Rapporteur
# A container of keys and one or more messages per key. This acts similarly
# to an ActiveModel::Errors collection from Ruby on Rails.
#
class MessageList
extend Forwardable
def_delegator :@messages, :clear
def_de... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/rspec.rb | Ruby | mit | 49 | main | 2,378 | # frozen_string_literal: true
require 'rapporteur'
shared_examples_for 'a successful status response' do
let(:parsed_body) { JSON.parse(response.body) }
it 'responds with HTTP 200' do
expect(response.response_code).to(eq(200))
end
context 'the response headers' do
it 'contains a Content-Type JSON he... |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | lib/rapporteur/checks/active_record_check.rb | Ruby | mit | 49 | main | 310 | # frozen_string_literal: true
module Rapporteur
module Checks
class ActiveRecordCheck
def self.call(checker)
ActiveRecord::Base.connection.select_value('SELECT current_time AS time')
rescue StandardError
checker.add_error(:database, :unavailable)
end
end
end
end |
github | envylabs/rapporteur | https://github.com/envylabs/rapporteur | app/controllers/rapporteur/statuses_controller.rb | Ruby | mit | 49 | main | 597 | # frozen_string_literal: true
require_relative 'application_controller'
module Rapporteur
class StatusesController < ApplicationController
def show
expires_now
respond_to do |format|
format.json do
resource = Rapporteur.run
if resource.errors.empty?
render(js... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | Rakefile | Ruby | mit | 49 | master | 457 | #!/usr/bin/env rake
require "bundler/gem_tasks"
require 'bundler'
begin
Bundler.setup(:default, :development, :test)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'rake/testtask'
Rake::TestTa... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | rails_serve_static_assets.gemspec | Ruby | mit | 49 | master | 1,032 | # -*- encoding: utf-8 -*-
require File.expand_path('../lib/rails_serve_static_assets/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Pedro Belo", "Jonathan Dance"]
gem.email = ["pedro@heroku.com", "jd@heroku.com"]
gem.description = %q{Force Rails to serve static assets}
gem.... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | Gemfile | Ruby | mit | 49 | master | 332 | source 'https://rubygems.org'
# Specify your gem's dependencies in rails_serve_static_assets.gemspec
gemspec :path => File.expand_path("../.", __FILE__)
group :development, :test do
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
gem "activerecord-jdbcsqlite3-adapter", '~> 1.3.13', :platform => :jruby
end
ge... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | lib/rails_serve_static_assets/railtie.rb | Ruby | mit | 49 | master | 468 | module RailsServeStaticAssets
class Railtie < Rails::Railtie
config.before_initialize do
version = Rails.version
if version >= "5.0.0"
::Rails.configuration.public_file_server.enabled = true
elsif version >= "4.2.0"
::Rails.configuration.serve_static_files = true
else
... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | test/test_helper.rb | Ruby | mit | 49 | master | 1,473 | ENV["RAILS_ENV"] = "test"
require 'rails'
require File.expand_path("../rails_app/config/environment.rb", __FILE__)
require "rails/test_help"
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default_url_options[:host] = "test.com"
Rails.backtrace_cleaner.rem... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | test/rails_app/app/controllers/authenticated_controller.rb | Ruby | mit | 49 | master | 221 | class AuthenticatedController < ApplicationController
if respond_to?(:before_filter)
class << self
alias :before_action :before_filter
end
end
before_action :authenticate_user!
def index
end
end |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | test/rails_app/app/controllers/application_controller.rb | Ruby | mit | 49 | master | 205 | class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :pull_out_locale
def pull_out_locale
I18n.locale = params[:locale] if params[:locale].present?
end
end |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | test/rails_app/config/routes.rb | Ruby | mit | 49 | master | 1,863 | Dummy::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'product... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | test/rails_app/config/application.rb | Ruby | mit | 49 | master | 2,039 | require File.expand_path('../boot', __FILE__)
require "active_model/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_view/railtie"
require "action_mailer/railtie"
Bundler.require :default
require "rails_serve_static_assets"
require 'sprockets/railtie'
module Dummy
class... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | test/rails_app/config/environments/production.rb | Ruby | mit | 49 | master | 889 | Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
... |
github | heroku/rails_serve_static_assets | https://github.com/heroku/rails_serve_static_assets | test/integration/static_file_service_test.rb | Ruby | mit | 49 | master | 632 | require 'test_helper'
class StaticFileServiceTest < ActiveSupport::IntegrationCase
test 'renders CSS' do
visit "/assets/application-5f55f638b632759d9c9113417c3ac6bd.css"
assert_equal 200, page.status_code
end
test 'renders JS' do
visit "/assets/application-89f8f774b6fb6783dfccc79d4103f256.js"
as... |
github | jamesgolick/conductor | https://github.com/jamesgolick/conductor | app/models/ec2.rb | Ruby | mit | 49 | master | 3,030 | class Ec2
cattr_accessor :mode, :test_responses, :test_mode_calls
self.mode = :production
self.test_responses = {
:run_instances => {
:aws_image_id => "ami-e444444d",
:aws_reason => "",
:aws_state_code => "0",
:aws_owner => "000000000888",
... |
github | jamesgolick/conductor | https://github.com/jamesgolick/conductor | app/models/address.rb | Ruby | mit | 49 | master | 261 | class Address < ActiveRecord::Base
belongs_to :environment
belongs_to :instance
before_create :allocate_address
protected
def allocate_address
self.address = ec2.allocate_address
end
def ec2
@ec2 ||= Ec2.new
end
end |
github | jamesgolick/conductor | https://github.com/jamesgolick/conductor | app/models/ssh.rb | Ruby | mit | 49 | master | 2,029 | require 'net/ssh'
require 'net/sftp'
class Ssh
class ResultProxy < Array
def initialize(results)
push *results
first.respond_to?(:successful?) || map! { |c| Result.new(c.properties) }
end
def successful?
all? { |r| r.successful? }
end
def failures
reject { |r| r.successf... |
github | jamesgolick/conductor | https://github.com/jamesgolick/conductor | app/models/environment.rb | Ruby | mit | 49 | master | 2,038 | class Environment < ActiveRecord::Base
belongs_to :application
has_many :instances do
def to_dna
running.inject({}) do |memo, instance|
memo[instance.role.to_sym] ||= []
memo[instance.role.to_sym] << instance.private_dns_name
memo
end
end
end
has_one :address
be... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.