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 | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parse_spec.rb | Ruby | mit | 89 | master | 27,755 | # frozen_string_literal: true
require "date"
require "pathname"
require "uri"
RSpec.describe TTY::Option do
context "argument" do
it "doesn't allow to register same name parameter" do
expect {
command do
argument :foo
keyword :foo
end
}.to raise_error(TTY::Option... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/sections_spec.rb | Ruby | mit | 89 | master | 1,664 | # frozen_string_literal: true
RSpec.describe TTY::Option::Sections do
it "adds a section with content" do
sections = described_class.new
sections.add(:foo, "Foo content")
sections.add(:bar, "Bar content")
sections.add(:baz, "Baz content")
expect(sections.size).to eq(3)
expect(sections[:foo]... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/help_spec.rb | Ruby | mit | 89 | master | 31,721 | # frozen_string_literal: true
RSpec.describe TTY::Option::Formatter do
context "Usage header & footer" do
it "includes header and footer in help display" do
cmd = new_command do
header "CLI app"
footer "Run --help to see more info."
end
expected_output = unindent(<<-EOS)
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/deep_dup_spec.rb | Ruby | mit | 89 | master | 8,427 | # frozen_string_literal: true
require "bigdecimal"
require "date"
require "pathname"
require "set"
require "uri"
RSpec.describe TTY::Option::DeepDup do
[
"foo",
*(/foo/ unless RSpec::Support::Ruby.truffleruby?),
%w[foo bar],
(1..10),
{"foo" => "bar"},
Date.parse("11/02/2023"),
Pathname.n... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/result_spec.rb | Ruby | mit | 89 | master | 511 | # frozen_string_literal: true
RSpec.describe TTY::Option::Result do
it "wraps a value in success" do
result = described_class.success("11")
expect(result.success?).to eq(true)
expect(result.value).to eq("11")
expect(result.error).to eq(nil)
end
it "wraps an error in failure" do
error = Argu... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/pipeline_spec.rb | Ruby | mit | 89 | master | 834 | # frozen_string_literal: true
RSpec.describe TTY::Option::Pipeline do
it "processes a param value through various transformation" do
param = TTY::Option::Parameter::Option.create(:foo, convert: :int,
validate: '\d+')
aggregator = ->(error) { errors << error }... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/param_permitted_spec.rb | Ruby | mit | 89 | master | 3,080 | # frozen_string_literal: true
RSpec.describe TTY::Option::ParamPermitted do
it "skips check when no permit setting" do
param = TTY::Option::Parameter::Option.create(:foo)
expect(described_class[param, "a"].value).to eq("a")
end
it "skips checking nil value" do
param = TTY::Option::Parameter::Option... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/inflection_spec.rb | Ruby | mit | 89 | master | 994 | # frozen_string_literal: true
RSpec.describe TTY::Option::Inflection do
context "demodulize" do
{
"A::B::C::Name" => "Name",
"::Name" => "Name",
"Name" => "Name"
}.each do |with_modules, bare_class|
it "removes all preceding modules from #{with_modules.inspect}" do
expect(desc... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/params_spec.rb | Ruby | mit | 89 | master | 3,998 | # frozen_string_literal: true
RSpec.describe TTY::Option::Params do
context "indifferent access" do
it "allows indifferent access to keys via has like syntax" do
params = described_class.new({foo: "bar", "baz" => :qux})
expect(params[:foo]).to eq("bar")
expect(params["foo"]).to eq("bar")
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/aggregate_errors_spec.rb | Ruby | mit | 89 | master | 3,380 | # frozen_string_literal: true
RSpec.describe TTY::Option::AggregateErrors do
context "checks presence" do
it "is empty by default" do
errors = described_class.new
expect(errors.empty?).to eq(true)
expect(errors.any?).to eq(false)
end
it "is not empty" do
errors = described_class... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/conversions_spec.rb | Ruby | mit | 89 | master | 8,851 | # frozen_string_literal: true
require "date"
require "pathname"
require "uri"
RSpec.describe TTY::Option::Conversions do
let(:undefined) { TTY::Option::Const::Undefined }
context "when :bool" do
{
1 => true,
0 => false,
:yes => true,
:no => false,
true => true,
false => fa... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/param_validation_spec.rb | Ruby | mit | 89 | master | 3,532 | # frozen_string_literal: true
RSpec.describe TTY::Option::ParamValidation do
it "skips validation when no validate setting" do
param = TTY::Option::Parameter::Option.create(:foo)
expect(described_class[param, "12"].value).to eq("12")
end
it "skips validation when the value is nil" do
param = TTY::O... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/usage_wrapper_spec.rb | Ruby | mit | 89 | master | 2,309 | # frozen_string_literal: true
RSpec.describe TTY::Option::UsageWrapper do
it "doesn't wrap a line that fits the width" do
text = "There is no stready"
wrapped = described_class.wrap(text, width: 30, indent: 2)
expect(wrapped).to eq(text)
end
it "wraps content shorter than width around newlines" do
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/error_aggregator_spec.rb | Ruby | mit | 89 | master | 1,523 | # frozen_string_literal: true
RSpec.describe TTY::Option::ErrorAggregator do
it "raises error by default" do
aggregator = described_class.new(raise_on_parse_error: true)
expect {
aggregator.(TTY::Option::MissingParameter, "boom")
}.to raise_error(TTY::Option::MissingParameter, "boom")
end
it "... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parameters_spec.rb | Ruby | mit | 89 | master | 6,003 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parameters do
context "accessors" do
it "provides access to stored arguments" do
param_list = described_class.new
expect(param_list.arguments?).to eq(false)
argument_foo = new_parameter("argument", :foo)
argument_bar = new_paramet... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/param_conversion_spec.rb | Ruby | mit | 89 | master | 1,257 | # frozen_string_literal: true
RSpec.describe TTY::Option::ParamConversion do
it "converts parameter value to expected type" do
param = TTY::Option::Parameter::Argument.create(:foo, convert: :int)
expect(described_class[param, "12"].value).to eq(12)
end
it "skips parameter conversion when the value is n... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parser/arity_check_spec.rb | Ruby | mit | 89 | master | 790 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parser::ArityCheck do
it "passes arity check" do
param = TTY::Option::Parameter::Option.create(:foo, arity: 2)
errors = []
aggregator = ->(err) { errors << err }
arity_check = described_class.new(aggregator)
arity_check << param
arity... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parser/options_spec.rb | Ruby | mit | 89 | master | 22,398 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parser::Options do
def option(name, **settings)
TTY::Option::Parameter::Option.create(name, **settings)
end
def parse(argv, options, **config)
parser = TTY::Option::Parser::Options.new(Array(options), **config)
parser.parse(argv)
end
it ... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parser/arguments_spec.rb | Ruby | mit | 89 | master | 4,039 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parser::Arguments do
def arg(name, **settings)
TTY::Option::Parameter::Argument.create(name, **settings)
end
def parse(argv, args, **config)
parser = described_class.new(Array(args), **config)
parser.parse(argv)
end
it "parses one argume... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parser/keywords_spec.rb | Ruby | mit | 89 | master | 8,248 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parser::Keywords do
def keyword(name, **settings)
TTY::Option::Parameter::Keyword.create(name, **settings)
end
def parse(argv, kwargs, **config)
parser = described_class.new(Array(kwargs), **config)
parser.parse(argv)
end
it "parses a si... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parser/required_check_spec.rb | Ruby | mit | 89 | master | 795 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parser::RequiredCheck do
it "passes required check" do
param = TTY::Option::Parameter::Option.create(:foo, required: true)
errors = []
aggregator = ->(err) { errors << err }
required_check = described_class.new(aggregator)
required_check <... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parser/param_types_spec.rb | Ruby | mit | 89 | master | 1,613 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parser::ParamTypes do
def type
stub_const("Types", Class.new do
extend TTY::Option::Parser::ParamTypes
end)
end
context "argument?" do
{
"--foo" => false,
"-f" => false,
"foo=bar" => false,
"foo" => tr... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parser/environments_spec.rb | Ruby | mit | 89 | master | 8,273 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parser::Environments do
def env(name, **settings)
TTY::Option::Parameter::Environment.create(name, **settings)
end
def parse(argv, env, envs, **config)
parser = described_class.new(Array(envs), **config)
parser.parse(argv, env)
end
it "d... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parameter/environment_spec.rb | Ruby | mit | 89 | master | 962 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parameter::Environment do
context "name" do
it "infers env name from the param key" do
env = described_class.new(:foo_bar)
expect(env.arity).to eq(1)
expect(env.name).to eq("FOO_BAR")
end
it "specifies custom env var name via a... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parameter/option_spec.rb | Ruby | mit | 89 | master | 12,258 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parameter::Option do
it "generates a default optional long name" do
option = described_class.new(:foo)
expect(option.key).to eq(:foo)
expect(option.short).to eq(nil)
expect(option.short?).to eq(false)
expect(option.long).to eq("--foo")
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parameter/keyword_spec.rb | Ruby | mit | 89 | master | 833 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parameter::Keyword do
context "required/optional setting" do
it "sets keyword presence optional by default" do
kwarg = described_class.new(:foo)
expect(kwarg.required?).to eq(false)
expect(kwarg.optional?).to eq(true)
end
end
c... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | spec/unit/parameter/argument_spec.rb | Ruby | mit | 89 | master | 12,209 | # frozen_string_literal: true
RSpec.describe TTY::Option::Parameter::Argument do
it "converts class to symbol name" do
arg = described_class.new(:foo)
expect(arg.to_sym).to eq(:argument)
end
it "has no settings by default" do
arg = described_class.new(:foo)
expect(arg.to_h).to eq({})
end
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | examples/nested.rb | Ruby | mit | 89 | master | 888 | # frozen_string_literal: true
require_relative "../lib/tty-option"
module Network
class Command
include TTY::Option
usage do
program "network"
end
flag :force do
short "-f"
long "--force"
desc "Do not prompt for confirmation"
end
option :help do
short "-h"
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | examples/run.rb | Ruby | mit | 89 | master | 1,577 | # frozen_string_literal: true
require_relative "../lib/tty-option"
class RunImage
include TTY::Option
usage do
program "dock"
command "run"
desc "Run a command in a new container"
example "Set working directory (-w)",
" $ dock run -w /path/to/dir/ ubuntu pwd"
example <<~EOS
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | examples/network.rb | Ruby | mit | 89 | master | 1,746 | # frozen_string_literal: true
require_relative "../lib/tty-option"
module Network
class Create
include TTY::Option
usage do
header "CLI app v1.2.3"
command "create"
desc "Create a network"
example "The following creates a bridge network:",
" $ network create -d bri... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | examples/map.rb | Ruby | mit | 89 | master | 402 | # frozen_string_literal: true
require_relative "../lib/tty-option"
class Command
include TTY::Option
argument :bar do
arity at_least(2)
end
option :foo do
arity one_or_more
short "-f"
long "--foo list"
convert map_of(Integer)
end
def run
p params[:bar]
p params[:foo]
end
e... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | examples/errors.rb | Ruby | mit | 89 | master | 496 | # frozen_string_literal: true
require_relative "../lib/tty-option"
class Command
include TTY::Option
argument :foo do
arity at_least(2)
convert :int
end
option :bar do
arity one_or_more
short "-b"
long "--bar int"
convert map_of(:int)
end
keyword :baz do
required
convert... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option.rb | Ruby | mit | 89 | master | 1,866 | # frozen_string_literal: true
require_relative "option/conversions"
require_relative "option/dsl"
require_relative "option/errors"
require_relative "option/parser"
require_relative "option/formatter"
require_relative "option/version"
module TTY
module Option
# Enhance object with command line option parsing
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/param_conversion.rb | Ruby | mit | 89 | master | 919 | # frozen_string_literal: true
require_relative "conversions"
require_relative "result"
module TTY
module Option
module ParamConversion
# Convert parameter value to another type
#
# @example
# param = Parameter::Argument.create(:foo, convert: :int)
# result = ParamConversion[par... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/usage_wrapper.rb | Ruby | mit | 89 | master | 1,542 | # frozen_string_literal: true
module TTY
module Option
module UsageWrapper
# Wrap a string to a maximum width with indentation
#
# @param [String] text
# @param [Integer] width
# @param [Integer] indent
# @param [Boolean] indent_first
#
# @api public
def wrap... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/sections.rb | Ruby | mit | 89 | master | 1,237 | # frozen_string_literal: true
require "forwardable"
require_relative "section"
module TTY
module Option
class Sections
include Enumerable
extend Forwardable
def_delegators :@sections, :size, :to_a
def initialize
@sections = []
end
def [](name)
@sections.fi... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/conversions.rb | Ruby | mit | 89 | master | 3,726 | # frozen_string_literal: true
require_relative "const"
require_relative "converter"
module TTY
module Option
module Conversions
extend Converter
TRUE_VALUES = /^(true|y(es)?|t|1)$/i.freeze
FALSE_VALUES = /^(false|n(o)?|f|0)$/i.freeze
convert :bool, :boolean do |val|
case val.to... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/inflection.rb | Ruby | mit | 89 | master | 1,137 | # frozen_string_literal: true
module TTY
module Option
module Inflection
# Remove all modules/class names
#
# @example
# demodulize("TTY::Option::ErrorAggregator")
# # => "ErrorAggregator"
#
# @return [String]
#
# @api public
def demodulize(name)
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/section.rb | Ruby | mit | 89 | master | 398 | # frozen_string_literal: true
module TTY
module Option
class Section
attr_accessor :name, :content
def initialize(name, content = [])
@name = name
@content = content
end
def to_a
[name, content]
end
def empty?
content.empty?
end
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/dsl.rb | Ruby | mit | 89 | master | 2,594 | # frozen_string_literal: true
require "forwardable"
require_relative "dsl/arity"
require_relative "dsl/conversion"
require_relative "inflection"
require_relative "parameter/argument"
require_relative "parameter/environment"
require_relative "parameter/keyword"
require_relative "parameter/option"
require_relative "par... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/deep_dup.rb | Ruby | mit | 89 | master | 1,855 | # frozen_string_literal: true
module TTY
module Option
# Responsible for deep copying an object
#
# @api private
module DeepDup
NONDUPLICATABLE = [
Symbol, TrueClass, FalseClass, NilClass, Numeric, Method, UnboundMethod
].freeze
# Deep copy an object
#
# @exampl... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser.rb | Ruby | mit | 89 | master | 1,583 | # frozen_string_literal: true
require_relative "params"
require_relative "parser/arguments"
require_relative "parser/environments"
require_relative "parser/keywords"
require_relative "parser/options"
require_relative "pipeline"
module TTY
module Option
class Parser
PARAMETER_PARSERS = {
options: T... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/formatter.rb | Ruby | mit | 89 | master | 18,479 | # frozen_string_literal: true
require_relative "sections"
require_relative "usage_wrapper"
module TTY
module Option
# Responsible for formatting help display
#
# @api private
class Formatter
include UsageWrapper
BOOLEANS = [true, false].freeze
DEFAULT_WIDTH = 80
DOUBLE_SPACE... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/pipeline.rb | Ruby | mit | 89 | master | 895 | # frozen_string_literal: true
require_relative "param_conversion"
require_relative "param_permitted"
require_relative "param_validation"
module TTY
module Option
class Pipeline
PROCESSORS = [
ParamConversion,
ParamPermitted,
ParamValidation
].freeze
# Create a param pr... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/result.rb | Ruby | mit | 89 | master | 1,306 | # frozen_string_literal: true
module TTY
module Option
# A monad that respresents success and failure conditions
class Result
# Wrap a value in a success monad
#
# @api public
def self.success(value)
Success.new(value)
end
# Wrap a value in a failure monad
#... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parameter.rb | Ruby | mit | 89 | master | 7,385 | # frozen_string_literal: true
require_relative "deep_dup"
require_relative "dsl/arity"
require_relative "dsl/conversion"
module TTY
module Option
class Parameter
include Comparable
include DSL::Arity
include DSL::Conversion
# Zero or more parameter arity pattern
ZERO_OR_MORE_ARITY... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/usage.rb | Ruby | mit | 89 | master | 5,169 | # frozen_string_literal: true
require_relative "deep_dup"
module TTY
module Option
class Usage
# Create an usage
#
# @api public
def self.create(**properties, &block)
new(**properties, &block)
end
# Create an usage
#
# @api public
def initialize(**p... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/params.rb | Ruby | mit | 89 | master | 2,575 | # frozen_string_literal: true
require "forwardable"
require_relative "aggregate_errors"
module TTY
module Option
class Params
extend Forwardable
def self.create(parameters = {}, remaining = [], errors = [])
new(parameters, remaining: remaining, errors: errors)
end
def_delegato... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/aggregate_errors.rb | Ruby | mit | 89 | master | 2,332 | # frozen_string_literal: true
require "forwardable"
require_relative "usage_wrapper"
module TTY
module Option
class AggregateErrors
include Enumerable
include UsageWrapper
extend Forwardable
def_delegators :@errors, :size, :empty?, :any?, :clear
# Create an intance from the pass... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/param_permitted.rb | Ruby | mit | 89 | master | 823 | # frozen_string_literal: true
require_relative "result"
module TTY
module Option
module ParamPermitted
# Convert parameter value to another type
#
# @example
# param = Parameter::Argument.create(:foo, permit: %w[11 12 13])
# ParamPermitted[param, "12"] # => 12
#
# @... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/converter.rb | Ruby | mit | 89 | master | 1,453 | # frozen_string_literal: true
module TTY
module Option
module Converter
# Store conversions
#
# @api public
def conversions
@conversions ||= {}
end
# Check if conversion is available
#
# @param [String] name
#
# @return [Boolean]
#
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/const.rb | Ruby | mit | 89 | master | 290 | # frozen_string_literal: true
module TTY
module Option
module Const
Undefined = Object.new.tap do |obj|
def obj.to_s
"undefined"
end
def obj.inspect
"undefined".inspect
end
end
end # Const
end # Option
end # TTY |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/errors.rb | Ruby | mit | 89 | master | 5,072 | # frozen_string_literal: true
module TTY
module Option
Error = Class.new(StandardError)
# Raised when a parameter invariant is invalid
ConfigurationError = Class.new(Error)
# Raised when attempting to register already registered parameter
ParameterConflict = Class.new(Error)
# Raised when ... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/error_aggregator.rb | Ruby | mit | 89 | master | 765 | # frozen_string_literal: true
require_relative "inflection"
module TTY
module Option
class ErrorAggregator
include Inflection
# Collected errors
attr_reader :errors
def initialize(errors = [], raise_on_parse_error: false)
@errors = errors
@raise_on_parse_error = raise_o... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/param_validation.rb | Ruby | mit | 89 | master | 4,143 | # frozen_string_literal: true
require_relative "result"
module TTY
module Option
# Responsible for parameter validation
#
# @api private
module ParamValidation
# Validate parameter value against validation rule
#
# @example
# param = TTY::Option::Parameter::Option.create(:f... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parameters.rb | Ruby | mit | 89 | master | 4,195 | # frozen_string_literal: true
require "set"
module TTY
module Option
# A collection to hold all parameters
class Parameters
include Enumerable
# Define a query for parameter types
#
# @api private
def self.define_query(name)
define_method(:"#{name}?") do
!pub... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parameter/environment.rb | Ruby | mit | 89 | master | 385 | # frozen_string_literal: true
module TTY
module Option
class Parameter
class Environment < Parameter
def default_name
key.to_s.tr("-", "_").upcase
end
# Compare this env var to another
#
# @api public
def <=>(other)
name <=> other.name
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parameter/argument.rb | Ruby | mit | 89 | master | 376 | # frozen_string_literal: true
require_relative "../parameter"
module TTY
module Option
class Parameter
class Argument < Parameter
# Required by default unless the arity allows any
#
# @api public
def required?
@settings.fetch(:required) { arity != -1 }
end... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parameter/keyword.rb | Ruby | mit | 89 | master | 279 | # frozen_string_literal: true
require_relative "../parameter"
module TTY
module Option
class Parameter
class Keyword < Parameter
def required?
@settings.fetch(:required) { false }
end
end
end # Parameter
end # Option
end # TTY |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parameter/option.rb | Ruby | mit | 89 | master | 2,487 | # frozen_string_literal: true
module TTY
module Option
class Parameter
class Option < Parameter
# Matches "-f string"
SHORT_ARGUMENT_REQUIRED_RE = /^-.(\s*?|\=)[^\[]+$/.freeze
# Matches "--foo string"
LONG_ARGUMENT_REQUIRED_RE = /^--\S+(\s+|\=)([^\[])+?$/.freeze
# ... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser/options.rb | Ruby | mit | 89 | master | 8,363 | # frozen_string_literal: true
require_relative "arity_check"
require_relative "param_types"
require_relative "required_check"
require_relative "../error_aggregator"
require_relative "../pipeline"
module TTY
module Option
class Parser
class Options
include ParamTypes
LONG_OPTION_RE = /^(--... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser/environments.rb | Ruby | mit | 89 | master | 4,781 | # frozen_string_literal: true
require_relative "arity_check"
require_relative "param_types"
require_relative "required_check"
require_relative "../error_aggregator"
require_relative "../pipeline"
module TTY
module Option
class Parser
class Environments
include ParamTypes
ENV_VAR_RE = /([\... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser/arity_check.rb | Ruby | mit | 89 | master | 747 | # frozen_string_literal: true
module TTY
module Option
class Parser
class ArityCheck
def initialize(error_aggregator)
@multiplies = []
@error_aggregator = error_aggregator
end
def add(param)
@multiplies << param
end
alias << add
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser/required_check.rb | Ruby | mit | 89 | master | 758 | # frozen_string_literal: true
module TTY
module Option
class Parser
class RequiredCheck
def initialize(error_aggregator)
@required = []
@error_aggregator = error_aggregator
end
def add(param)
@required << param
end
alias << add
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser/keywords.rb | Ruby | mit | 89 | master | 4,309 | # frozen_string_literal: true
require_relative "arity_check"
require_relative "param_types"
require_relative "required_check"
require_relative "../error_aggregator"
require_relative "../pipeline"
module TTY
module Option
class Parser
class Keywords
include ParamTypes
KEYWORD_ARG_RE = /([^... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser/param_types.rb | Ruby | mit | 89 | master | 1,471 | # frozen_string_literal: true
module TTY
module Option
class Parser
module ParamTypes
# Positional argument pattern
ARGUMENT_PARAMETER = /^[^-][^=]*\z/.freeze
# Environment variable pattern
ENV_VAR_PARAMETER = /^[\p{Lu}_\-\d]+=/.freeze
# Keyword pattern
KEY... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/parser/arguments.rb | Ruby | mit | 89 | master | 4,273 | # frozen_string_literal: true
require_relative "../error_aggregator"
require_relative "../pipeline"
require_relative "param_types"
require_relative "required_check"
module TTY
module Option
class Parser
class Arguments
include ParamTypes
# Create a command line arguments parser
#
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/dsl/conversion.rb | Ruby | mit | 89 | master | 283 | # frozen_string_literal: true
module TTY
module Option
module DSL
module Conversion
def map_of(type)
:"#{type}_map"
end
def list_of(type)
:"#{type}_list"
end
end # Convert
end # DSL
end # Option
end # TTY |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | lib/tty/option/dsl/arity.rb | Ruby | mit | 89 | master | 816 | # frozen_string_literal: true
module TTY
module Option
module DSL
module Arity
# @api public
def one
1
end
# @api public
def two
2
end
# Zero or more arity
#
# @api public
def zero_or_more
-1
... |
github | piotrmurach/tty-option | https://github.com/piotrmurach/tty-option | tasks/console.rake | Ruby | mit | 89 | master | 229 | # frozen_string_literal: true
desc "Load gem inside irb console"
task :console do
require "irb"
require "irb/completion"
require File.join(__FILE__, "../../lib/tty-option")
ARGV.clear
IRB.start
end
task c: %w[console] |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | Gemfile | Ruby | mit | 89 | master | 1,327 | source "https://rubygems.org"
ruby "2.3.1"
gem "rails", "~> 5.0.0"
gem "pg", "~> 0.15"
gem "puma"
gem "sass-rails", "~> 5.0"
gem "uglifier", ">= 1.3.0"
gem "jquery-rails"
gem "browserify-rails"
gem "react-rails"
gem "materialize-sass"
gem "sdoc", "~> 0.4.0", group: :doc
gem "rack-protection"
gem "title"
gem "flutie... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/controllers/application_controller.rb | Ruby | mit | 89 | master | 256 | class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
PushNotificationError = Class.new(StandardError)
end |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/controllers/subscriptions_controller.rb | Ruby | mit | 89 | master | 225 | class SubscriptionsController < ApplicationController
def create
session[:subscription] = params.fetch(:subscription).to_json
head :ok
end
def destroy
session.delete(:subscription)
head :ok
end
end |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/controllers/streams_controller.rb | Ruby | mit | 89 | master | 719 | class StreamsController < ApplicationController
QUERIES = {
cats: "#cats filter:images -RT"
}.with_indifferent_access
def index
@query = search_query
respond_to do |format|
format.html
format.json { render json: tweets(@query) }
end
end
def show
@query = QUERIES.fetch(params... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/controllers/push_notifications_controller.rb | Ruby | mit | 89 | master | 1,075 | class PushNotificationsController < ApplicationController
def create
Rails.logger.info "Sending push notification from #{push_params.inspect}"
subscription_params = fetch_subscription_params
WebpushJob.perform_later fetch_message,
endpoint: subscription_params[:endpoint],
p256dh: subscription... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/controllers/pages_controller.rb | Ruby | mit | 89 | master | 482 | class PagesController < ApplicationController
include HighVoltage::StaticPage
before_filter :ensure_trailing_slash
def ensure_trailing_slash
redirect_to url_for(params.merge(trailing_slash: true)) unless skip_redirect?
end
def skip_redirect?
trailing_slash? || asset?
end
def asset?
request... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/helpers/twitter_helper.rb | Ruby | mit | 89 | master | 301 | require "addressable/uri"
module TwitterHelper
def tweet_link_to(text, params = {})
uri = Addressable::URI.parse("https://twitter.com/intent/tweet")
uri.query_values = params.reverse_merge hashtags: "serviceworker-rails,serviceworker"
link_to text, uri.to_s, target: "_blank"
end
end |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/helpers/nav_helper.rb | Ruby | mit | 89 | master | 257 | module NavHelper
def demo_navbar
nav_pages t('nav').values.flatten
end
def demo_index
t('nav').map { |sect, titles| [sect.to_s.titleize, nav_pages(titles)] }
end
def nav_pages(titles)
titles.map { |t| [t, t.parameterize] }
end
end |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/helpers/meta_helper.rb | Ruby | mit | 89 | master | 1,274 | module MetaHelper
def metatag(attrs)
"<meta #{attrs.map { |k,v| %Q|#{k}=\"#{v}\"| }.join(" ")}>"
end
def site_metatags
Rails.cache.fetch('site_metatags') do
site_metadata.map do |attrs|
metatag(attrs)
end.join("\n").html_safe
end
end
def site_metadata
[
{ name: "des... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/clients/twitter_client.rb | Ruby | mit | 89 | master | 811 | class TwitterClient
def client
@client ||= Twitter::REST::Client.new do |config|
config.consumer_key = ENV.fetch("TWITTER_CONSUMER_KEY")
config.consumer_secret = ENV.fetch("TWITTER_CONSUMER_SECRET")
config.access_token = ENV.fetch("TWITTER_ACCESS_TOKEN")
config.access_tok... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/clients/webpush_client.rb | Ruby | mit | 89 | master | 1,435 | class WebpushClient
def self.public_key
ENV.fetch('VAPID_PUBLIC_KEY')
end
def self.public_key_bytes
Base64.urlsafe_decode64(public_key).bytes
end
def self.private_key
ENV.fetch('VAPID_PRIVATE_KEY')
end
# Send webpush message using subscription parameters
#
# @param message [String] text... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | app/jobs/webpush_job.rb | Ruby | mit | 89 | master | 390 | class WebpushJob < ActiveJob::Base
queue_as :default
def perform(message, params)
client = WebpushClient.new
log("sending #{message} to #{params[:endpoint]}")
response = client.send_notification(message, params)
log(response ? "success" : "failed")
log(response.body.inspect)
end
def log(m... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | db/schema.rb | Ruby | mit | 89 | master | 899 | # encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative sou... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | spec/rails_helper.rb | Ruby | mit | 89 | master | 2,770 | # 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 | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | spec/clients/twitter_client_spec.rb | Ruby | mit | 89 | master | 1,019 | require "rails_helper"
describe TwitterClient do
let(:client) { TwitterClient.new }
def token
ENV.fetch('TWITTER_ACCESS_TOKEN')
end
def secret
ENV.fetch('TWITTER_ACCESS_SECRET')
end
describe "#client" do
it "wraps the twitter gem rest client" do
twitter = client.client
expect(twi... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | spec/clients/webpush_client_spec.rb | Ruby | mit | 89 | master | 942 | require "spec_helper"
describe WebpushClient do
let(:client) { WebpushClient.new }
describe "#send_notification" do
it "sends to google endpoint" do
p256dh = SecureRandom.random_bytes(65)
auth = SecureRandom.random_bytes(16)
endpoint = "https://fcm.googleapis.com/gcm/send/subscriptionId"
... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | spec/support/database_cleaner.rb | Ruby | mit | 89 | master | 434 | RSpec.configure do |config|
config.before(:suite) do
# DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.clean_with(:deletion)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :deletion
end
conf... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | config/application.rb | Ruby | mit | 89 | master | 1,823 | 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 ServiceworkerRailsSandbox
class Application < Rails::Application
# We want to set up a custom logger which logs to ... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | config/routes.rb | Ruby | mit | 89 | master | 1,929 | Rails.application.routes.draw do
root "welcome#index"
resources :streams
post "/subscribe" => "subscriptions#create"
delete "/unsubscribe" => "subscriptions#destroy"
post "/push" => "push_notifications#create"
get "/*path/offline" => "welcome#offline"
get "/*id" => "pages#show", as: :page, format: fal... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | config/environments/development.rb | Ruby | mit | 89 | master | 1,988 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web serv... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | config/environments/production.rb | Ruby | mit | 89 | master | 7,311 | 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 | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | config/initializers/new_framework_defaults.rb | Ruby | mit | 89 | master | 1,025 | # Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.0 upgrade.
#
# Once upgraded flip defaults one by one to migrate to the new default.
#
# Read the Rails 5.0 release notes for more info on each option.
# Enable per-form CSRF tokens. Previous versi... |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | config/initializers/serviceworker.rb | Ruby | mit | 89 | master | 268 | Rails.application.configure do
config.serviceworker.routes.draw do
match "/serviceworker.js" => "home/serviceworker.js"
match "/*pages/serviceworker.js" => "%{pages}/serviceworker.js"
match "/*pages/manifest.json" => "%{pages}/manifest.json"
end
end |
github | rossta/serviceworker-rails-sandbox | https://github.com/rossta/serviceworker-rails-sandbox | config/initializers/assets.rb | Ruby | mit | 89 | master | 1,476 | # Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
# Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additiona... |
github | logankoester/autorefresh | https://github.com/logankoester/autorefresh | Rakefile | Ruby | mit | 89 | master | 1,673 | require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
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 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specificati... |
github | logankoester/autorefresh | https://github.com/logankoester/autorefresh | Gemfile | Ruby | mit | 89 | master | 409 | source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
gem "pusher", ">= 0.7.0"
gem "watchr", ">= 0.7"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "bacon",... |
github | logankoester/autorefresh | https://github.com/logankoester/autorefresh | lib/autorefresh.rb | Ruby | mit | 89 | master | 801 | require 'pusher'
# Automatically refresh your browser using WebSockets
class AutoRefresh
@@pusher_key = 'a2024b659f492cab86cc'
@@pusher_app_id = '3735'
@@pusher_secret = '3ce64d76b4288e4ba449'
def self.channel(chan)
%q{
<script src="http://js.pusherapp.com/1.6/pusher.js" type="text/javascript"></scr... |
github | logankoester/autorefresh | https://github.com/logankoester/autorefresh | spec/autorefresh_spec.rb | Ruby | mit | 89 | master | 814 | require File.join( File.expand_path(File.dirname(__FILE__)), 'spec_helper')
describe "The AutoRefresh helper" do
before do
@channel = 'testchannel'
@helper = AutoRefresh.channel(@channel)
end
it "should accept a channel name and return a string" do
@helper.class.should.equal String
end
it "shoul... |
github | logankoester/autorefresh | https://github.com/logankoester/autorefresh | spec/spec_helper.rb | Ruby | mit | 89 | master | 469 | require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'bacon'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(Fi... |
github | tily/ruby-faker-japanese | https://github.com/tily/ruby-faker-japanese | Rakefile | Ruby | mit | 89 | master | 1,298 | require 'rubygems'
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "faker-japanese"
gem.summary = %Q{Faker in Japanese}
gem.description = %Q{Faker in Japanese}
gem.email = "tily05@gmail.com"
gem.homepage = "http://github.com/tily/ruby-faker-japanese"
gem.author... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.