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 | sensu/sensu-docs-legacy | https://github.com/sensu/sensu-docs-legacy | legacy/0.18/files/check-procs.rb | Ruby | mit | 47 | master | 8,963 | #!/usr/bin/env ruby
#
# Check Procs
# ===
#
# Finds processes matching various filters (name, state, etc). Will not
# match itself by default. The number of processes found will be tested
# against the Warning/critical thresholds. By default, fails with a
# CRITICAL if more than one process matches -- you must specify ... |
github | sensu/sensu-docs-legacy | https://github.com/sensu/sensu-docs-legacy | legacy/0.18/files/check-data.rb | Ruby | mit | 47 | master | 7,473 | #! /usr/bin/env ruby
#
# check-data
#
# DESCRIPTION:
# This plugin checks values within graphite
#
# OUTPUT:
# plain text
#
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
# gem: sensu-plugin
# gem: json
# gem: open-uri
# gem: openssl
#
# USAGE:
# #YELLOW
#
# NOTES:
#
# LICENSE:
# Copyright 2014 Sonian, Inc.... |
github | stuartlynn/puffin_facts | https://github.com/stuartlynn/puffin_facts | Gemfile | Ruby | mit | 47 | master | 1,774 | source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as co... |
github | stuartlynn/puffin_facts | https://github.com/stuartlynn/puffin_facts | app/controllers/facts_controller.rb | Ruby | mit | 47 | master | 2,039 | class FactsController < ApplicationController
def index
puffin_facts = ["Nicknamed 'sea parrots' - and sometimes 'clowns of the sea'! - Atlantic puffins have black and white feathers and a large parrot-like beak. They are small seabirds measuring around 25cm in length.", "Puffins spend most of their lives out at s... |
github | stuartlynn/puffin_facts | https://github.com/stuartlynn/puffin_facts | spec/rails_helper.rb | Ruby | mit | 47 | master | 2,674 | # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
requ... |
github | stuartlynn/puffin_facts | https://github.com/stuartlynn/puffin_facts | spec/controllers/facts_controller_spec.rb | Ruby | mit | 47 | master | 358 | require_relative '../../app/controllers/facts_controller'
describe FactsController do
context 'the index is accessed' do
it 'returns one of ten different puffin facts' do
controller = FactsController.new
facts = []
100.times do
facts << controller.index
end
expect(facts.... |
github | stuartlynn/puffin_facts | https://github.com/stuartlynn/puffin_facts | config/application.rb | Ruby | mit | 47 | master | 488 | require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module PuffinFacts
class Application < Rails::Application
# Settings in config/environments/* take precedence over those s... |
github | stuartlynn/puffin_facts | https://github.com/stuartlynn/puffin_facts | config/environments/production.rb | Ruby | mit | 47 | master | 3,585 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web serve... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | grape-swagger-entity.gemspec | Ruby | mit | 47 | master | 954 | # frozen_string_literal: true
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'grape-swagger/entity/version'
Gem::Specification.new do |s|
s.name = 'grape-swagger-entity'
s.version = GrapeSwagger::Entity::VERSION
s.authors = ['Kirill Za... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | Gemfile | Ruby | mit | 47 | master | 1,605 | # frozen_string_literal: true
source 'https://rubygems.org'
# Specify your gem's dependencies in grape-swagger-entity.gemspec
gemspec
grape_version = ENV.fetch('GRAPE_VERSION', '< 3.0')
grape_swagger_version = ENV.fetch('GRAPE_SWAGGER_VERSION', '< 3.0')
grape_entity_version = ENV.fetch('GRAPE_ENTITY_VERSION', '< 2.0... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | lib/grape-swagger/entity.rb | Ruby | mit | 47 | master | 371 | # frozen_string_literal: true
require 'grape-swagger'
require 'grape-entity'
require 'grape-swagger/entity/version'
require 'grape-swagger/entity/helper'
require 'grape-swagger/entity/attribute_parser'
require 'grape-swagger/entity/parser'
module GrapeSwagger
module Entity
end
end
GrapeSwagger.model_parsers.reg... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | lib/grape-swagger/entity/attribute_parser.rb | Ruby | mit | 47 | master | 5,552 | # frozen_string_literal: true
module GrapeSwagger
module Entity
class AttributeParser
attr_reader :endpoint
def initialize(endpoint)
@endpoint = endpoint
end
def call(entity_options)
param = if (entity_model = model_from(entity_options))
name = GrapeSwa... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | lib/grape-swagger/entity/parser.rb | Ruby | mit | 47 | master | 6,370 | # frozen_string_literal: true
module GrapeSwagger
module Entity
class Parser
attr_reader :model, :endpoint, :attribute_parser
def initialize(model, endpoint)
@model = model
@endpoint = endpoint
@attribute_parser = AttributeParser.new(endpoint)
end
def call
... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | lib/grape-swagger/entity/helper.rb | Ruby | mit | 47 | master | 1,032 | # frozen_string_literal: true
module GrapeSwagger
module Entity
# Helper methods for DRY
class Helper
class << self
def model_name(entity_model, endpoint)
if endpoint.nil?
entity_model.to_s.demodulize
else
endpoint.send(:expose_params_from_model, enti... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/spec_helper.rb | Ruby | mit | 47 | master | 513 | # frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'grape-swagger/entity'
require 'grape'
Bundler.setup :default, :test
require 'rack'
require 'rack/test'
RSpec.configure do |config|
require 'rspec/expectations'
config.include RSpec::Matchers
config.mock_with :rspec
c... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/issues/962_polymorphic_entity_with_custom_documentation_spec.rb | Ruby | mit | 47 | master | 3,652 | # frozen_string_literal: true
describe '#962 empty entity with custom documentation type' do
# grape-swagger < 2.1.3 doesn't support empty model definitions (PR #963)
let(:supports_empty_models?) { Gem::Version.new(GrapeSwagger::VERSION) >= Gem::Version.new('2.1.3') }
context 'when entity has no properties' do
... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/issues/44_desc_in_entity_type_spec.rb | Ruby | mit | 47 | master | 3,123 | # frozen_string_literal: true
describe '#44 desc not rendered for non-array entity references' do
subject(:swagger_doc) do
get '/swagger_doc'
JSON.parse(last_response.body)
end
let(:app) do
Class.new(Grape::API) do
namespace :issue44 do
class Address < Grape::Entity
expose :s... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/support/shared_contexts/custom_type_parser.rb | Ruby | mit | 47 | master | 456 | # frozen_string_literal: true
class CustomType
end
class CustomTypeParser
attr_reader :model, :endpoint
def initialize(model, endpoint)
@model = model
@endpoint = endpoint
end
def call
{
model.name.to_sym => {
type: 'custom_type',
description: "it's a custom type",
... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/support/shared_contexts/this_api.rb | Ruby | mit | 47 | master | 3,423 | # frozen_string_literal: true
shared_context 'this api' do
before :all do
module ThisApi
module Entities
class Kind < Grape::Entity
expose :title, documentation: { type: 'string', desc: 'Title of the kind.' }
expose :content, documentation: { type: 'string', desc: 'Content', x: ... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/support/shared_contexts/inheritance_api.rb | Ruby | mit | 47 | master | 478 | # frozen_string_literal: true
shared_context 'inheritance api' do
before :all do
module InheritanceApi
module Entities
class Parent < Grape::Entity
expose :type, documentation: { type: 'string', is_discriminator: true, required: true }
expose :id, documentation: { type: 'integer... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/grape-swagger/entity_spec.rb | Ruby | mit | 47 | master | 332 | # frozen_string_literal: true
require 'spec_helper'
describe GrapeSwagger::Entity do
it 'has a version number' do
expect(GrapeSwagger::Entity::VERSION).not_to be_nil
end
it 'parser should be registred' do
expect(GrapeSwagger.model_parsers.to_a).to include([GrapeSwagger::Entity::Parser, 'Grape::Entity']... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/grape-swagger/entities/response_model_spec.rb | Ruby | mit | 47 | master | 21,265 | # frozen_string_literal: true
require 'spec_helper'
describe 'responseModel' do
subject do
get '/swagger_doc/something'
JSON.parse(last_response.body)
end
include_context 'this api'
def app
ThisApi::ResponseModelApi
end
it 'documents index action' do
expect(subject['paths']['/something'... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/grape-swagger/entity/parser_spec.rb | Ruby | mit | 47 | master | 2,871 | # frozen_string_literal: true
require 'spec_helper'
require_relative '../../../spec/support/shared_contexts/this_api'
describe GrapeSwagger::Entity::Parser do
context 'this api' do
include_context 'this api'
describe '#call' do
let(:parsed_entity) { described_class.new(ThisApi::Entities::Something, e... |
github | ruby-grape/grape-swagger-entity | https://github.com/ruby-grape/grape-swagger-entity | spec/grape-swagger/entity/attribute_parser_spec.rb | Ruby | mit | 47 | master | 12,768 | # frozen_string_literal: true
require 'spec_helper'
require_relative '../../../spec/support/shared_contexts/this_api'
describe GrapeSwagger::Entity::AttributeParser do
include_context 'this api'
describe '#call' do
subject { described_class.new(endpoint).call(entity_options) }
let(:endpoint) {}
con... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | Rakefile | Ruby | mit | 47 | master | 1,789 | require 'rake/clean'
CLEAN.include ["rdoc", "spec/db/fd_spec.sqlite3", "coverage", "*.gem"]
desc "Generate rdoc"
task :rdoc do
rdoc_dir = "rdoc"
rdoc_opts = ["--line-numbers", "--inline-source", '--title', 'fixture_dependencies: Sequel/ActiveRecord fixture loader that handles dependency graphs']
begin
gem ... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | fixture_dependencies.gemspec | Ruby | mit | 47 | master | 958 | Gem::Specification.new do |s|
s.name = "fixture_dependencies"
s.version = "1.11.0"
s.author = "Jeremy Evans"
s.email = "code@jeremyevans.net"
s.platform = Gem::Platform::RUBY
s.summary = "Sequel/ActiveRecord fixture loader that handles dependency graphs"
s.files = ["README.md", "MIT-LICENSE", "CHANGELOG"... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/fd_spec.rb | Ruby | mit | 47 | master | 47,221 | require_relative 'spec_helper'
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
gem 'minitest'
require 'minitest/global_expectations/autorun'
Foo = Class.new(defined?(Sequel::Model) ? Sequel::Model : ActiveRecord::Base)
def Foo.table_name; :foos end
class Bar; def self.table_name() :bars end end... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/sequel_spec_helper.rb | Ruby | mit | 47 | master | 3,129 | require 'sequel'
DB = Sequel.connect(RUBY_ENGINE == 'jruby' ? 'jdbc:sqlite:spec/db/fd_spec.sqlite3' : 'sqlite://spec/db/fd_spec.sqlite3')
class Artist < Sequel::Model
one_to_many :albums
end
class ArtistCustomFixture < Artist
def self.fixture_filename
:artists_custom_fixture_file
end
one_to_one :first_al... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/spec_helper.rb | Ruby | mit | 47 | master | 857 | if coverage = ENV.delete('COVERAGE')
require 'simplecov'
SimpleCov.start do
enable_coverage :branch
command_name coverage
add_filter{|f| f.filename.match(%r{\A#{Regexp.escape(File.dirname(__FILE__))}/})}
add_group('Missing'){|src| src.covered_percent < 100}
add_group('Covered'){|src| src.covere... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/ar_spec_helper.rb | Ruby | mit | 47 | master | 1,760 | require 'active_record'
ActiveRecord::Base.establish_connection(:adapter=>'sqlite3', :database=>File.join(File.dirname(File.expand_path(__FILE__)), 'db', 'fd_spec.sqlite3'))
class Artist < ActiveRecord::Base
has_many :albums
end
class ArtistCustomFixture < Artist
def self.fixture_filename
:artists_custom_fix... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/migrate/002_com_tables.rb | Ruby | mit | 47 | master | 836 | Sequel.migration do
change do
create_table(:com_artists){Integer :id1; Integer :id2; String :name; primary_key [:id1, :id2]}
create_table(:com_albums){Integer :id1; Integer :id2; String :name; Integer :artist_id1; Integer :artist_id2; primary_key [:id1, :id2]; foreign_key [:artist_id1, :artist_id2], :com_arti... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/migrate/001_tables.rb | Ruby | mit | 47 | master | 456 | Sequel.migration do
change do
create_table(:artists){primary_key :id; String :name}
create_table(:albums){primary_key :id; String :name; foreign_key :artist_id, :artists}
create_table(:tags){primary_key :id; String :name}
create_table(:albums_tags){foreign_key :album_id, :albums; foreign_key :tag_id, ... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/migrate/004_cti_tables.rb | Ruby | mit | 47 | master | 429 | Sequel.migration do
change do
create_table(:ctis) do
primary_key :id
String :kind
Integer :number
end
create_table(:cti_subs) do
primary_key :id
Integer :extra_number
end
create_table(:cti_mms) do
primary_key :id
Integer :kind_id
Integer :number
... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | spec/migrate/005_poly_tables.rb | Ruby | mit | 47 | master | 301 | Sequel.migration do
change do
create_table(:accounts) do
primary_key :id
String :name
end
create_table(:addresses) do
primary_key :id
column :addressable_id, Integer
column :addressable_type, String
String :street
String :city
end
end
end |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | lib/fixture_dependencies.rb | Ruby | mit | 47 | master | 12,876 | require('sequel/extensions/inflector') unless [:singularize, :camelize, :underscore, :constantize].all?{|meth| "".respond_to?(meth)}
require 'erb'
require 'yaml'
class FixtureDependencies
@fixtures = {}
@loaded = {}
@class_map = {}
@verbose = 0
@use_unsafe_load = false
# Load all record arguments into t... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | lib/fixture_dependencies/active_record.rb | Ruby | mit | 47 | master | 973 | class << FixtureDependencies
private
def add_associated_object_AR(reflection, attr, object, assoc)
if reflection.macro == :has_one
object.send("#{attr}=", assoc)
elsif !object.send(attr).include?(assoc)
object.send(attr) << assoc
end
end
def model_find_AR(model, pk)
model.find(... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | lib/fixture_dependencies/sequel.rb | Ruby | mit | 47 | master | 969 | class << FixtureDependencies
private
def add_associated_object_S(reflection, attr, object, assoc)
if reflection[:type] == :one_to_one
object.send("#{reflection[:name]}=", assoc)
else
object.send("add_#{attr.to_s.singularize}", assoc) unless object.send(attr).include?(assoc)
end
end
... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | lib/fixture_dependencies/helper_methods.rb | Ruby | mit | 47 | master | 385 | require_relative '../fixture_dependencies'
class FixtureDependencies
module HelperMethods
# Load given fixtures using FixtureDependencies
def load(*fixture)
FixtureDependencies.load(*fixture)
end
def load_attributes(*args)
FixtureDependencies.load_attributes(*args)
end
def build... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | lib/fixture_dependencies/test_unit/rails.rb | Ruby | mit | 47 | master | 843 | require_relative '../test_unit'
FixtureDependencies.fixture_path = Test::Unit::TestCase.fixture_path
module Test
module Unit
class TestCase
class << self
alias_method :stupid_method_added, :method_added
end
def self.method_added(x)
end
# Load fixtures using FixtureDep... |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | lib/fixture_dependencies/test_unit/sequel.rb | Ruby | mit | 47 | master | 311 | require_relative '../test_unit'
class FixtureDependencies::SequelTestCase < Test::Unit::TestCase
# Work around for Rails stupidity
undef_method :default_test if method_defined?(:default_test)
def run(*args, &block)
Sequel::Model.db.transaction(:rollback=>:always) do
super
end
end
end |
github | jeremyevans/fixture_dependencies | https://github.com/jeremyevans/fixture_dependencies | lib/fixture_dependencies/rspec/sequel.rb | Ruby | mit | 47 | master | 921 | require_relative '../helper_methods'
if defined?(RSpec)
example_group = RSpec::Core::ExampleGroup
use_rspec_configure = begin
require 'rspec/core/version'
rescue LoadError
require 'rspec/version'
RSpec::Version::STRING >= '2.8.0'
end
if use_rspec_configure
RSpec.configure do |c|
c.arou... |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | outlaw.gemspec | Ruby | mit | 47 | master | 1,630 | # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
require "outlaw/version"
module ::Gem
post_install {|gem_installer| puts 'in hook'; Outlaw.post_install(gem_installer) }
end
Gem::Specification.new do |s|
s.name = "outlaw"
s.version = Outlaw::... |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | Rakefile | Ruby | mit | 47 | master | 251 | #!/usr/bin/env rake
if Regexp.new('RUBYARCHDIR') === ARGV[0]
require_relative "lib/outlaw/post_install"
Outlaw::PostInstall.new(ARGV[0])
end
task :default => 'test'
task :test do
sh "ruby test/outlaw_test.rb"
sh "ruby test/debt_test.rb"
end |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | test/outlaw_test.rb | Ruby | mit | 47 | master | 4,139 | require_relative 'test_helper'
module Outlaw
describe LawParser do
it "returns a Rule which is called on code and returns true or false" do
end
before do
@okay_file = %{
class Whatever < Set
def okaything(here)
@here = here
end
end
... |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | lib/outlaw.rb | Ruby | mit | 47 | master | 1,446 | require 'ripper'
require_relative 'outlaw/law_parser'
require_relative 'outlaw/enforcement'
require_relative 'outlaw/rule'
require_relative 'outlaw/rule_methods'
require_relative 'outlaw/post_install'
module Outlaw
extend self
attr_accessor :ignore_types, :param_types
def outlaw(pattern, message=nil, options=... |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | lib/outlaw/post_install.rb | Ruby | mit | 47 | master | 441 | module Outlaw
class PostInstall
def initialize(gem_installer)
cmd = if system("which rvm > /dev/null")
"rvm default do gem"
elsif system("which rbenv > /dev/null")
"rbenv exec gem"
else
"gem"
end
system(%Q{#{cmd} install pre-commit})
system(%Q{pre-commi... |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | lib/outlaw/rule_methods.rb | Ruby | mit | 47 | master | 217 | module Outlaw
def trailing_whitespace
Rule.new("Trailing whitespace",
"Trailing whitespace is ugly and can mess up version history") do |file|
file.match(/ \n/)
end
end
end |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | lib/outlaw/enforcement.rb | Ruby | mit | 47 | master | 1,439 | module Outlaw
class Enforcement
class << self
attr_reader :rules
def add(rule)
@rules ||= []
@rules << rule
end
def process_directory(path, output=:destructured)
results = {error: nil, output:""}
Dir.foreach(path) do |entry|
next if entry == '.' o... |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | lib/outlaw/law_parser.rb | Ruby | mit | 47 | master | 1,928 | module Outlaw
module LawParser
extend self
def parse(restriction, rule)
tokens = restriction.split
parsed_restriction = []
tokens.each do |token|
case
when special_case?(string_to_sym(token))
handle_special(token, rule)
when multipart?(token) #this handles ... |
github | bglusman/Outlaw | https://github.com/bglusman/Outlaw | lib/outlaw/rule.rb | Ruby | mit | 47 | master | 3,621 | module Outlaw
class Rule
attr_reader :message, :pattern, :detection_block, :warning
attr_accessor :modifications
def initialize(pattern, message=nil, options={}, &detection_block)
@pattern = pattern
@message = message ? message : "Don't do this: #{pattern}"
@warning ... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | ruby-stackoverflow.gemspec | Ruby | mit | 47 | master | 1,169 | # coding: utf-8
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "ruby-stackoverflow/version"
Gem::Specification.new do |spec|
spec.name = "ruby-stackoverflow"
spec.version = RubyStackoverflow::VERSION
spec.authors = ["Rashmi Yadav"]
... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | spec/spec_helper.rb | Ruby | mit | 47 | master | 317 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require "bundler/setup"
require "webmock/rspec"
require "vcr"
require "helper"
require "ruby-stackoverflow"
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.fail_fast = true
config.order = "random"
end |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | spec/helper.rb | Ruby | mit | 47 | master | 965 | VCR.configure do |c|
c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
c.allow_http_connections_when_no_cassette = true
c.hook_into :webmock # or :fakeweb
end
def configure_stackoverflow
RubyStackoverflow.configure do |config|
config.client_key = "pfllsDjWHeLGWoWIT5rRdA(("
config.access_token = "L... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | spec/ruby-stackoverflow/badges_spec.rb | Ruby | mit | 47 | master | 2,411 | require "spec_helper"
module RubyStackoverflow
describe Client::BadgesHelper do
before(:each) do
configure_stackoverflow
@user_basic_url = "badges/"
end
it "should find badges" do
VCR.use_cassette("badges") do
response = RubyStackoverflow.badges(min: "gold", max: "bronze", sort:... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | spec/ruby-stackoverflow/user_spec.rb | Ruby | mit | 47 | master | 11,358 | require "spec_helper"
module RubyStackoverflow
describe Client::UserHelper do
before(:each) do
configure_stackoverflow
@user_basic_url = "users/"
end
it "should find users" do
VCR.use_cassette("users") do
response = RubyStackoverflow.users(inname: "raysrashmi", sort: "reputation... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | spec/ruby-stackoverflow/comments_spec.rb | Ruby | mit | 47 | master | 990 | require "spec_helper"
module RubyStackoverflow
describe Client::CommentsHelper do
before(:each) do
configure_stackoverflow
@comments_basic_url = "users/"
WebMock.allow_net_connect!
end
it "should fetch comments" do
VCR.use_cassette("comments") do
response = RubyStackoverfl... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | spec/ruby-stackoverflow/question_spec.rb | Ruby | mit | 47 | master | 3,213 | require "spec_helper"
module RubyStackoverflow
describe Client::QuestionHelper do
before(:each) do
configure_stackoverflow
@question_basic_url = "questions/"
end
it "should get questions" do
VCR.use_cassette("questions") do
response = RubyStackoverflow.questions
expect... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow.rb | Ruby | mit | 47 | master | 778 | require "httparty"
require "ruby-stackoverflow/version"
require "ruby-stackoverflow/client"
require "ruby-stackoverflow/configuration"
module RubyStackoverflow
include HTTParty
class << self
def client
@client ||= RubyStackoverflow::Client.new
end
# @private
def respond_to_missing?(method_n... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/generators/ruby_stackoverflow/ruby_stackoverflow_generator.rb | Ruby | mit | 47 | master | 824 | require "rails/generators"
class RubyStackoverflowGenerator < Rails::Generators::Base
desc "Creates the ruby-stackoverflow initializer file at config/initialize/ruby-stackoverflow.rb"
class_option :client_key, aliases: "-k", type: :string, desc: "Your Stackoverflow Client key"
class_option :access_token, aliases... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client.rb | Ruby | mit | 47 | master | 2,333 | require "json"
require "ruby-stackoverflow/client/response_data"
require "ruby-stackoverflow/client/resource/resource"
require "ruby-stackoverflow/client/resource/user"
require "ruby-stackoverflow/client/resource/question"
require "ruby-stackoverflow/client/resource/answer"
require "ruby-stackoverflow/client/resource/n... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/ruby-stackoverflow_generator.rb | Ruby | mit | 47 | master | 827 | require "rails/generators"
require "ruby-stackoverflow"
class RubyStackoverflowGenerator < Rails::Generators::Base
desc "Creates the ruby-stackoverflow initializer file at config/initialize/ruby-stackoverflow.rb"
class_option :client_key, aliases: "-k", type: :string, desc: "Your Stackoverflow Client key"
class_o... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/configuration.rb | Ruby | mit | 47 | master | 258 | module RubyStackoverflow
class Configuration
attr_accessor(
:site,
:client_id,
:client_secret,
:client_key,
:access_token,
:api_url)
def self.api_url
"https://api.stackexchange.com/2.2/"
end
end
end |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/comments_helper.rb | Ruby | mit | 47 | master | 434 | module RubyStackoverflow
class Client
module CommentsHelper
def comments(options = {})
comments_response(options)
end
def comments_by_ids(ids, options = {})
url = join_ids(ids)
comments_response(options, url)
end
private
def comments_response(options ... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/response_data.rb | Ruby | mit | 47 | master | 505 | module RubyStackoverflow
class Client
class ResponseData
attr_reader :data, :has_more, :error
def initialize(response, klass)
if response[:items].nil?
@error = StackoverflowError.new(response)
else
@data = format_data(response[:items], klass)
@has_more = ... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/parse_options.rb | Ruby | mit | 47 | master | 477 | module RubyStackoverflow
class Client
module ParseOptions
def parse_options(options = {})
options.each do |k, v|
case k
when :fromdate, :todate, :min, :max
begin
options[k] = Time.parse(v).to_i
rescue
options[k] = v
... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/user_helper.rb | Ruby | mit | 47 | master | 4,160 | module RubyStackoverflow
class Client
module UserHelper
def users(options = {})
user_response(options)
end
def users_by_ids(ids, options = {})
ids = join_ids(ids)
user_response(options, ids)
end
def users_with_answers(ids, options = {})
ids = join_id... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/badges_helper.rb | Ruby | mit | 47 | master | 928 | module RubyStackoverflow
class Client
module BadgesHelper
def badges(options = {})
badges_response(options)
end
def badges_by_ids(ids, options = {})
url = join_ids(ids)
badges_response(options, url)
end
def badges_by_name(options = {})
url = "/name"
... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/question_helper.rb | Ruby | mit | 47 | master | 1,473 | module RubyStackoverflow
class Client
module QuestionHelper
def questions(options = {})
question_response(options)
end
def questions_by_ids(ids, options = {})
url = join_ids(ids)
question_response(options, url)
end
def answers_of_questions(ids, options = {})... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/resource/resource.rb | Ruby | mit | 47 | master | 656 | module RubyStackoverflow
class Client
class Resource
def initialize(attributes_hash)
attributes_hash.each do |k, v|
self.class.send :attr_accessor, k
var = "@#{k}"
case k.to_sym
when :creation_date, :last_activity_date, :launch_date, :last_edit_date
... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/resource/user.rb | Ruby | mit | 47 | master | 4,129 | module RubyStackoverflow
class Client
class User < Resource
attr_reader :badges, :answers, :comments,
:questions, :reputations,
:suggested_edits, :tags, :posts, :permissions
def initialize(attributes_hash)
@badges = []
@answers = []
@commen... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/resource/question.rb | Ruby | mit | 47 | master | 2,023 | module RubyStackoverflow
class Client
class Question < Resource
attr_reader :answers, :comments, :user, :posts
def initialize(attributes_hash = {})
@answers = []
@comments = []
@posts = []
super
end
class << self
def parse_data(data)
quest... |
github | raysrashmi/ruby-stackoverflow | https://github.com/raysrashmi/ruby-stackoverflow | lib/ruby-stackoverflow/client/resource/stackoverflow_error.rb | Ruby | mit | 47 | master | 316 | module RubyStackoverflow
class Client
class StackoverflowError
attr_reader :error_code, :error_message, :error_name
def initialize(params)
@error_name = params[:error_name]
@error_code = params[:error_id]
@error_message = params[:error_message]
end
end
end
end |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | Gemfile | Ruby | mit | 47 | main | 327 | source 'https://rubygems.org'
gemspec
group :development do
gem 'rake'
gem 'rubygems-tasks', '~> 0.2'
gem 'rspec', '~> 3.0'
gem 'simplecov', '~> 0.20', require: false
gem 'kramdown'
gem 'redcarpet', platform: :mri
gem 'yard', '~> 0.9'
gem 'yard-spellcheck', require: fal... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | combinatorics.gemspec | Ruby | mit | 47 | main | 1,965 | # encoding: utf-8
require 'yaml'
Gem::Specification.new do |gem|
gemspec = YAML.load_file('gemspec.yml')
gem.name = gemspec.fetch('name')
gem.version = gemspec.fetch('version') do
require_relative 'lib/combinatorics/version'
Combinatorics::VERSION
end
g... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | Rakefile | Ruby | mit | 47 | main | 264 | require 'rubygems/tasks'
Gem::Tasks.new
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
task :test => :spec
task :default => :spec
require 'yard'
YARD::Rake::YardocTask.new
task :benchmark do
Dir.glob('benchmarks/*.rb') { |script| ruby(script) }
end |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | benchmarks/cartesian_product.rb | Ruby | mit | 47 | main | 414 | #!/usr/bin/env ruby
root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
lib_dir = File.join(root_dir,'lib')
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
require 'benchmark'
require 'combinatorics/cartesian_product'
Benchmark.bm(13) do |b|
[100, 200, 400, 800].each do |i|
n = (1..i)... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | benchmarks/choose.rb | Ruby | mit | 47 | main | 394 | #!/usr/bin/env ruby
root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
lib_dir = File.join(root_dir,'lib')
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
require 'benchmark'
require 'combinatorics/choose'
Benchmark.bm do |b|
n = 20
array = (1..n).to_a
(1..n).each do |i|
b.r... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | benchmarks/power_set.rb | Ruby | mit | 47 | main | 381 | #!/usr/bin/env ruby
root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
lib_dir = File.join(root_dir,'lib')
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
require 'benchmark'
require 'combinatorics/power_set'
Benchmark.bm do |b|
(10..20).each do |n|
array = (1..n).to_a
b.report(... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | benchmarks/permute.rb | Ruby | mit | 47 | main | 378 | #!/usr/bin/env ruby
root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
lib_dir = File.join(root_dir,'lib')
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
require 'benchmark'
require 'combinatorics/permute'
Benchmark.bm do |b|
array = (1..10).to_a
(1..10).each do |n|
b.report("r=#... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | benchmarks/list_comprehension.rb | Ruby | mit | 47 | main | 692 | root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
lib_dir = File.join(root_dir,'lib')
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
require 'benchmark'
require 'combinatorics/list_comprehension'
Benchmark.bm(12) do |b|
singleton_list = ([1] * 500)
single_enum_list = [1..100, 1]
dep... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | benchmarks/derange.rb | Ruby | mit | 47 | main | 376 | #!/usr/bin/env ruby
root_dir = File.expand_path(File.join(File.dirname(__FILE__),'..'))
lib_dir = File.join(root_dir,'lib')
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
require 'benchmark'
require 'combinatorics/derange'
Benchmark.bm do |b|
(1..10).each do |n|
array = (1..n).to_a
b.report("n=... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics.rb | Ruby | mit | 47 | main | 481 | # frozen_string_literal: true
require_relative 'combinatorics/cartesian_product'
require_relative 'combinatorics/choose'
require_relative 'combinatorics/derange'
require_relative 'combinatorics/extensions'
require_relative 'combinatorics/list_comprehension'
require_relative 'combinatorics/power_set'
require_relative '... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/list_comprehension.rb | Ruby | mit | 47 | main | 2,108 | # frozen_string_literal: true
require_relative 'enumerator'
class Array
#
# Iterates over each permutation of the enumerable values within the
# {Array}.
#
# @yield [list]
# The given block will be passed each permutation of the enumerable
# values in the {Array}.
#
# @yieldparam [Array] list
... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/enumerator.rb | Ruby | mit | 47 | main | 403 | # frozen_string_literal: true
require 'enumerator'
module Combinatorics
# auto-detects the `Enumerator` class.
Enumerator = if defined?(::Enumerator) # 1.9
::Enumerator
elsif defined?(::Enumerable::Enumerator) # 1.8.7
::Enumerable::Enumerator
else
... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/generator.rb | Ruby | mit | 47 | main | 449 | # frozen_string_literal: true
require 'enumerator'
require 'generator' if RUBY_VERSION < '1.9'
module Combinatorics
# auto-detects the `Generator` class.
Generator = if defined?(::Generator) # 1.8.7
::Generator
elsif defined?(::Enumerator::Generator) # >= 1.9.1
::Enum... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/power_set/mixin.rb | Ruby | mit | 47 | main | 1,227 | # frozen_string_literal: true
module Combinatorics
module PowerSet
#
# @author postmodern <postmodern.mod3@gmail.com>
#
module Mixin
#
# Calculates the power-set of an Enumerable object.
#
# @yield [subset]
# If a block is given, it will be passed each sub-set from the... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/power_set/cardinality.rb | Ruby | mit | 47 | main | 878 | # frozen_string_literal: true
require_relative '../extensions/math'
module Combinatorics
module PowerSet
#
# Get number of elements in power set from number of elements in input
# set.
#
# @param [Fixnum] n
# Number of elements input set.
#
# @return [Fixnum]
# Number of elem... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/cartesian_product/mixin.rb | Ruby | mit | 47 | main | 1,765 | # frozen_string_literal: true
require_relative '../list_comprehension'
module Combinatorics
module CartesianProduct
#
# @author duper <super@manson.vistech.net>
#
# @since 0.4.0
#
module Mixin
#
# Calculates the Cartesian product of an Enumerable object.
#
# @yield [s... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/cartesian_product/cardinality.rb | Ruby | mit | 47 | main | 1,014 | # frozen_string_literal: true
module Combinatorics
#
# @author duper <super@manson.vistech.net>
#
# @since 0.4.0
#
module CartesianProduct
#
# Wrapper for Cartesian product cardinality method defined above
#
# @param [Fixnum] a
# Cardinality of first set.
#
# @param [Fixnum] b... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/derange/mixin.rb | Ruby | mit | 47 | main | 1,270 | # frozen_string_literal: true
module Combinatorics
module Derange
#
# @author duper <super@manson.vistech.net>
#
# @since 0.4.0
#
module Mixin
#
# Calculate all derangements for an Enumerable object.
#
# @yield [derangement]
# If a block is given, it will be p... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/derange/cardinality.rb | Ruby | mit | 47 | main | 504 | # frozen_string_literal: true
require_relative '../extensions/math'
module Combinatorics
module Derange
#
# Compute the number of derangements for a data structure of given size
#
# @see Math.subfactorial
#
def self.cardinality(n)
Math.subfactorial(n)
end
#
# Wrapper for d... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/choose/cardinality.rb | Ruby | mit | 47 | main | 2,464 | # frozen_string_literal: true
require_relative '../extensions/math'
module Combinatorics
#
# @author duper <super@manson.vistech.net>
#
# @since 0.4.0
#
module Choose
#
# Compute the number of elements in a subset of given size
#
# @param [Fixnum] n
# The number of elements in the in... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/choose/mixin.rb | Ruby | mit | 47 | main | 1,343 | # frozen_string_literal: true
require 'set'
module Combinatorics
module Choose
#
# @author duper <super@manson.vistech.net>
#
# @since 0.4.0
#
module Mixin
#
# Get combinations with a specified number of elements from an input
# set.
#
# @param [Fixnum] k
... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/extensions/range.rb | Ruby | mit | 47 | main | 2,172 | # frozen_string_literal: true
class Range
#
# Finds the intersecting sub-range.
#
# @param [Range] other
# The other range.
#
# @return [Range]
# The intersecting sub-range.
#
# @example
# (1..100) & (20..200)
# # => 20..100
#
# @since 0.2.0
#
def &(other)
Range.new(
... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/extensions/math.rb | Ruby | mit | 47 | main | 3,479 | # frozen_string_literal: true
#
# @author duper <super@manson.vistech.net>
#
module Math
#
# Mathematical summation (invokes a block for k = 1 until ++k = n).
#
# @param [Range] r
# Range containing the number of times to yield.
#
# @yield [i]
# The given block is expected to return an Integer, whi... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/permute/mixin.rb | Ruby | mit | 47 | main | 1,288 | # frozen_string_literal: true
module Combinatorics
module Permute
#
# @author duper <super@manson.vistech.net>
#
# @since 0.4.0
#
module Mixin
#
# Enumerate distinct r-permutations for a particular sequence of
# elements.
#
# @param [Fixnum] r
# Length of... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | lib/combinatorics/permute/cardinality.rb | Ruby | mit | 47 | main | 2,642 | # frozen_string_literal: true
require_relative '../extensions/math'
module Combinatorics
#
# @author duper <super@manson.vistech.net>
#
# @since 0.4.0
#
module Permute
#
# Mathematically determine the number of elements in a r-permutations
# set.
#
# @param [Fixnum] n
# The numb... |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | spec/generator_spec.rb | Ruby | mit | 47 | main | 204 | require 'spec_helper'
require 'combinatorics/generator'
describe Combinatorics::Generator do
it "should auto-detect the Generator class" do
expect(Combinatorics::Generator).not_to be_nil
end
end |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | spec/enumerator_spec.rb | Ruby | mit | 47 | main | 208 | require 'spec_helper'
require 'combinatorics/enumerator'
describe Combinatorics::Enumerator do
it "should auto-detect the Enumerator class" do
expect(Combinatorics::Enumerator).not_to be_nil
end
end |
github | postmodern/combinatorics.rb | https://github.com/postmodern/combinatorics.rb | spec/list_comprehension_spec.rb | Ruby | mit | 47 | main | 1,742 | require 'spec_helper'
require 'combinatorics/list_comprehension'
require 'combinatorics/generator'
describe "Array#comprehension" do
it "should return an Enumerator object if no block is given" do
a = [1..5]
expect(a.comprehension).not_to be_kind_of(Array)
end
it "should yield iterations to the given b... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.