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 | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/operations/each_spec.rb | Ruby | mit | 179 | main | 1,409 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Operations::Each do
subject(:operation) { described_class.new(is_string) }
include_context "predicates"
let(:is_string) { Dry::Logic::Rule::Predicate.build(str?) }
describe "#call" do
it "applies its rules to all elements in the input" do
ex... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/operations/check_spec.rb | Ruby | mit | 179 | main | 2,147 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Operations::Check do
include_context "predicates"
describe "#call" do
context "with 1-level nesting" do
subject(:operation) do
described_class.new(Dry::Logic::Rule::Predicate.build(eql?).curry(1), id: :compare, keys: [:num])
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/operations/and_spec.rb | Ruby | mit | 179 | main | 2,016 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Operations::And do
subject(:operation) { described_class.new(left, right) }
include_context "predicates"
let(:left) { Dry::Logic::Rule::Predicate.build(int?) }
let(:right) { Dry::Logic::Rule::Predicate.build(gt?).curry(18) }
describe "#call" do
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/operations/implication_spec.rb | Ruby | mit | 179 | main | 880 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Operations::Implication do
subject(:operation) { described_class.new(left, right) }
include_context "predicates"
let(:left) { Dry::Logic::Rule::Predicate.build(int?) }
let(:right) { Dry::Logic::Rule::Predicate.build(gt?).curry(18) }
describe "#call"... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/operations/set_spec.rb | Ruby | mit | 179 | main | 1,205 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Operations::Set do
subject(:operation) { described_class.new(is_int, gt_18) }
include_context "predicates"
let(:is_int) { Dry::Logic::Rule::Predicate.build(int?) }
let(:gt_18) { Dry::Logic::Rule::Predicate.build(gt?, args: [18]) }
describe "#call" d... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/operations/attr_spec.rb | Ruby | mit | 179 | main | 940 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Operations::Attr do
subject(:operation) do
Dry::Logic::Operations::Attr.new(Dry::Logic::Rule::Predicate.build(str?), name: :name)
end
include_context "predicates"
let(:model) { Struct.new(:name) }
describe "#call" do
it "applies predicate to... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/operations/xor_spec.rb | Ruby | mit | 179 | main | 1,780 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Operations::Xor do
subject(:operation) { described_class.new(left, right) }
include_context "predicates"
let(:left) { Dry::Logic::Rule::Predicate.build(array?) }
let(:right) { Dry::Logic::Rule::Predicate.build(empty?) }
let(:other) do
Dry::Logic... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/rule/predicate_spec.rb | Ruby | mit | 179 | main | 1,407 | # frozen_string_literal: true
RSpec.describe Dry::Logic::Rule::Predicate do
subject(:rule) { described_class.build(predicate) }
let(:predicate) { str? }
include_context "predicates"
it_behaves_like Dry::Logic::Rule
describe "#name" do
it "returns predicate identifier" do
expect(rule.name).to be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/gt_spec.rb | Ruby | mit | 179 | main | 777 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#gt?" do
let(:predicate_name) { :gt? }
context "when value is greater than n" do
let(:arguments_list) do
[
[13, 14],
[13.37, 13.38]
]
end
it... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v7_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v7?" do
let(:predicate_name) { :uuid_v7? }
context "when value is a valid V7 UUID" do
let(:arguments_list) do
[["017f22e2-79b0-7cc3-98c4-dc0c0c07398f"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v3_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v3?" do
let(:predicate_name) { :uuid_v3? }
context "when value is a valid V3 UUID" do
let(:arguments_list) do
[["f2d26c57-e07c-3416-a749-57e937930e04"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/str_spec.rb | Ruby | mit | 179 | main | 607 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#str?" do
let(:predicate_name) { :str? }
context "when value is a string" do
let(:arguments_list) do
[
[""],
["John"]
]
end
it_behaves_like ... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/bool_spec.rb | Ruby | mit | 179 | main | 666 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#bool?" do
let(:predicate_name) { :bool? }
context "when value is a boolean" do
let(:arguments_list) do
[[true], [false]]
end
it_behaves_like "a passing predicate"
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/excludes_spec.rb | Ruby | mit | 179 | main | 1,254 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#excludes?" do
let(:predicate_name) { :excludes? }
context "with input excludes value" do
let(:arguments_list) do
[
["Jack", %w[Jill John]],
[0, 1..2],
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/none_spec.rb | Ruby | mit | 179 | main | 590 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#nil?" do
let(:predicate_name) { :nil? }
context "when value is nil" do
let(:arguments_list) { [[nil]] }
it_behaves_like "a passing predicate"
end
context "when value is not ... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/decimal_spec.rb | Ruby | mit | 179 | main | 632 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#decimal?" do
let(:predicate_name) { :decimal? }
context "when value is a decimal" do
let(:arguments_list) do
[[1.2.to_d]]
end
it_behaves_like "a passing predicate"
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/hash_spec.rb | Ruby | mit | 179 | main | 708 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#hash?" do
let(:predicate_name) { :hash? }
context "when value is a hash" do
let(:arguments_list) do
[
[{}],
[foo: :bar],
[{}]
]
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/attr_spec.rb | Ruby | mit | 179 | main | 703 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#attr?" do
let(:predicate_name) { :attr? }
context "when value responds to the attr name" do
let(:arguments_list) do
[
[:name, Struct.new(:name).new("John")],
[:... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/included_in_spec.rb | Ruby | mit | 179 | main | 796 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#included_in?" do
let(:predicate_name) { :included_in? }
context "when value is present in list" do
let(:arguments_list) do
[
[%w[Jill John], "Jill"],
[%w[Jill J... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/false_spec.rb | Ruby | mit | 179 | main | 673 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#false?" do
let(:predicate_name) { :false? }
context "when value is false" do
let(:arguments_list) do
[[false]]
end
it_behaves_like "a passing predicate"
end
c... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/empty_spec.rb | Ruby | mit | 179 | main | 727 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#empty?" do
let(:predicate_name) { :empty? }
context "when value is empty" do
let(:arguments_list) do
[
[""],
[[]],
[{}],
[nil]
]
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/max_size_spec.rb | Ruby | mit | 179 | main | 984 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#max_size?" do
let(:predicate_name) { :max_size? }
context "when value size is less than n" do
let(:arguments_list) do
[
[3, [1, 2]],
[5, "Jill"],
[3, ... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/date_spec.rb | Ruby | mit | 179 | main | 608 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#date?" do
let(:predicate_name) { :date? }
context "when value is a date" do
let(:arguments_list) do
[[Date.today]]
end
it_behaves_like "a passing predicate"
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/lteq_spec.rb | Ruby | mit | 179 | main | 781 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#lteq?" do
let(:predicate_name) { :lteq? }
context "when value is less than n" do
let(:arguments_list) do
[
[13, 12],
[13.37, 13.36]
]
end
i... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/bytesize_spec.rb | Ruby | mit | 179 | main | 1,013 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#bytesize?" do
let(:predicate_name) { :bytesize? }
context "when value size is equal to n" do
let(:arguments_list) do
[
[4, "こa"],
[1..8, "こa"]
]
e... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/not_eql_spec.rb | Ruby | mit | 179 | main | 466 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates, "#not_eql?" do
let(:predicate_name) { :not_eql? }
context "when value is equal to the arg" do
let(:arguments_list) do
[%w[Foo Foo]]
end
it_behaves_like "a failing predicate"
end
context "wi... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/includes_spec.rb | Ruby | mit | 179 | main | 532 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates, "#is?" do
let(:predicate_name) { :is? }
let(:one) { Object.new }
let(:two) { Object.new }
context "when value is equal to the arg" do
let(:arguments_list) do
[[one, one], [:one, :one]]
end
i... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/gteq_spec.rb | Ruby | mit | 179 | main | 781 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#gteq?" do
let(:predicate_name) { :gteq? }
context "when value is greater than n" do
let(:arguments_list) do
[
[13, 14],
[13.37, 13.38]
]
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/case_spec.rb | Ruby | mit | 179 | main | 712 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#case?" do
let(:predicate_name) { :case? }
context "when the value matches the pattern" do
let(:arguments_list) do
[
[11, 11],
[:odd?.to_proc, 11],
[/\... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v6_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v6?" do
let(:predicate_name) { :uuid_v6? }
context "when value is a valid V6 UUID" do
let(:arguments_list) do
[["1ec9414c-232a-6b00-b3c8-9e6bdeced846"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v2_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v2?" do
let(:predicate_name) { :uuid_v2? }
context "when value is a valid V1 UUID" do
let(:arguments_list) do
[["f2d26c57-e07c-2416-a749-57e937930e04"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/odd_spec.rb | Ruby | mit | 179 | main | 579 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#odd?" do
let(:predicate_name) { :odd? }
context "when value is an odd int" do
let(:arguments_list) do
[
[13],
[1],
[1111]
]
end
i... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/true_spec.rb | Ruby | mit | 179 | main | 669 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#true?" do
let(:predicate_name) { :true? }
context "when value is true" do
let(:arguments_list) do
[[true]]
end
it_behaves_like "a passing predicate"
end
conte... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/float_spec.rb | Ruby | mit | 179 | main | 604 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#float?" do
let(:predicate_name) { :float? }
context "when value is a float" do
let(:arguments_list) do
[[1.0]]
end
it_behaves_like "a passing predicate"
end
c... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/key_spec.rb | Ruby | mit | 179 | main | 621 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#key?" do
let(:predicate_name) { :key? }
context "when key is present in value" do
let(:arguments_list) do
[
[:name, {name: "John"}],
[:age, {age: 18}]
]... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/size_spec.rb | Ruby | mit | 179 | main | 1,204 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#size?" do
let(:predicate_name) { :size? }
context "when value size is equal to n" do
let(:arguments_list) do
[
[[2, 4, 6], "abcd"],
[4, "Jill"],
[2, {... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/min_bytesize_spec.rb | Ruby | mit | 179 | main | 743 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#min_bytesize?" do
let(:predicate_name) { :min_bytesize? }
context "when value size is greater than n" do
let(:arguments_list) do
[
[3, "こa"]
]
end
it... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/even_spec.rb | Ruby | mit | 179 | main | 581 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#even?" do
let(:predicate_name) { :even? }
context "when value is an odd int" do
let(:arguments_list) do
[
[13],
[1],
[1111]
]
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v4_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v4?" do
let(:predicate_name) { :uuid_v4? }
context "when value is a valid V4 UUID" do
let(:arguments_list) do
[["f2d26c57-e07c-4416-a749-57e937930e04"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/respond_to_spec.rb | Ruby | mit | 179 | main | 616 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#respond_to?" do
let(:predicate_name) { :respond_to? }
context "when value responds to method" do
let(:arguments_list) do
[
[:method, Object],
[:new, Hash]
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v8_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v8?" do
let(:predicate_name) { :uuid_v8? }
context "when value is a valid V8 UUID" do
let(:arguments_list) do
[["320c3d4d-cc00-875b-8ec9-32d5f69181c0"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/type_spec.rb | Ruby | mit | 179 | main | 812 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#type?" do
let(:predicate_name) { :type? }
context "when value has a correct type" do
let(:arguments_list) do
[[TrueClass, true]]
end
it_behaves_like "a passing predica... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/excluded_from_spec.rb | Ruby | mit | 179 | main | 800 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#excluded_from?" do
let(:predicate_name) { :excluded_from? }
context "when value is not present in list" do
let(:arguments_list) do
[
[%w[Jill John], "Jack"],
[1... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/date_time_spec.rb | Ruby | mit | 179 | main | 624 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#date_time?" do
let(:predicate_name) { :date_time? }
context "when value is a datetime" do
let(:arguments_list) do
[[DateTime.now]]
end
it_behaves_like "a passing predi... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/time_spec.rb | Ruby | mit | 179 | main | 606 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#time?" do
let(:predicate_name) { :time? }
context "when value is a time" do
let(:arguments_list) do
[[Time.now]]
end
it_behaves_like "a passing predicate"
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/format_spec.rb | Ruby | mit | 179 | main | 618 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates, "#format?" do
let(:predicate_name) { :format? }
context "when value matches provided regexp" do
let(:arguments_list) do
[[/^F/, "Foo"]]
end
it_behaves_like "a passing predicate"
end
context... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/array_spec.rb | Ruby | mit | 179 | main | 798 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#array?" do
let(:predicate_name) { :array? }
context "when value is an array" do
let(:arguments_list) do
[
[[]],
[%w[other array]],
[[123, "really", :b... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v5_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v5?" do
let(:predicate_name) { :uuid_v5? }
context "when value is a valid V5 UUID" do
let(:arguments_list) do
[["f2d26c57-e07c-5416-a749-57e937930e04"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uuid_v1_spec.rb | Ruby | mit | 179 | main | 908 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uuid_v1?" do
let(:predicate_name) { :uuid_v1? }
context "when value is a valid V1 UUID" do
let(:arguments_list) do
[["f2d26c57-e07c-1416-a749-57e937930e04"]]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/int_spec.rb | Ruby | mit | 179 | main | 637 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#int?" do
let(:predicate_name) { :int? }
context "when value is an integer" do
let(:arguments_list) do
[
[1],
[33],
[7]
]
end
it_b... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/lt_spec.rb | Ruby | mit | 179 | main | 777 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#lt?" do
let(:predicate_name) { :lt? }
context "when value is less than n" do
let(:arguments_list) do
[
[13, 12],
[13.37, 13.36]
]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/uri_spec.rb | Ruby | mit | 179 | main | 1,703 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#uri?" do
let(:predicate_name) { :uri? }
context "when value is a valid URI" do
let(:arguments_list) do
[
[nil, "https://github.com/dry-rb/dry-logic"], # without schemes p... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/filled_spec.rb | Ruby | mit | 179 | main | 731 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#filled?" do
let(:predicate_name) { :filled? }
context "when value is filled" do
let(:arguments_list) do
[
["Jill"],
[[1, 2, 3]],
[{name: "John"}],
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/eql_spec.rb | Ruby | mit | 179 | main | 458 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates, "#eql?" do
let(:predicate_name) { :eql? }
context "when value is equal to the arg" do
let(:arguments_list) do
[%w[Foo Foo]]
end
it_behaves_like "a passing predicate"
end
context "with value... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/min_size_spec.rb | Ruby | mit | 179 | main | 984 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#min_size?" do
let(:predicate_name) { :min_size? }
context "when value size is greater than n" do
let(:arguments_list) do
[
[1, [1, 2]],
[3, "Jill"],
[... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/max_bytesize_spec.rb | Ruby | mit | 179 | main | 746 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#max_bytesize?" do
let(:predicate_name) { :max_bytesize? }
context "when value size is less than n" do
let(:arguments_list) do
[
[5, "こa"]
]
end
it_be... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | spec/unit/predicates/number_spec.rb | Ruby | mit | 179 | main | 723 | # frozen_string_literal: true
require "dry/logic/predicates"
RSpec.describe Dry::Logic::Predicates do
describe "#number?" do
let(:predicate_name) { :number? }
context "when value is numerical" do
let(:arguments_list) do
[
["34"],
["1.000004"],
["0"],
[4... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic.rb | Ruby | mit | 179 | main | 547 | # frozen_string_literal: true
require "zeitwerk"
require "dry/core"
module Dry
module Logic
include Dry::Core::Constants
def self.loader
@loader ||= Zeitwerk::Loader.new.tap do |loader|
root = File.expand_path("..", __dir__)
loader.tag = "dry-logic"
loader.inflector = Zeitwerk... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/appliable.rb | Ruby | mit | 179 | main | 497 | # frozen_string_literal: true
module Dry
module Logic
module Appliable
def id
options[:id]
end
def result
options[:result]
end
def applied?
!result.nil?
end
def success?
result.equal?(true)
end
def failure?
!success... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operators.rb | Ruby | mit | 179 | main | 506 | # frozen_string_literal: true
module Dry
module Logic
module Operators
def and(other)
Operations::And.new(self, other)
end
alias_method :&, :and
def or(other)
Operations::Or.new(self, other)
end
alias_method :|, :or
def xor(other)
Operations::Xo... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/result.rb | Ruby | mit | 179 | main | 1,586 | # frozen_string_literal: true
module Dry
module Logic
class Result
SUCCESS = ::Class.new {
def success?
true
end
def failure?
false
end
}.new.freeze
attr_reader :success
attr_reader :id
attr_reader :serializer
def initia... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/predicates.rb | Ruby | mit | 179 | main | 6,009 | # frozen_string_literal: true
require "dry/core/constants"
require "bigdecimal"
require "bigdecimal/util"
require "date"
require "uri"
module Dry
module Logic
module Predicates
include ::Dry::Core::Constants
module Methods
def self.uuid_format(version)
::Regexp.new(<<~FORMAT.chom... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/builder.rb | Ruby | mit | 179 | main | 2,134 | # frozen_string_literal: true
require "singleton"
require "delegate"
module Dry
module Logic
module Builder
IGNORED_OPERATIONS = %i[
Abstract
Binary
Unary
].freeze
IGNORED_PREDICATES = [
:predicate
].freeze
# Predicate and operation builder
#... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/rule.rb | Ruby | mit | 179 | main | 2,345 | # frozen_string_literal: true
require "concurrent/map"
module Dry
module Logic
def self.Rule(*args, **options, &block)
if args.any?
Rule.build(*args, **options)
elsif block
Rule.build(block, **options)
end
end
class Rule
include Core::Constants
include ::Dr... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/evaluator.rb | Ruby | mit | 179 | main | 957 | # frozen_string_literal: true
module Dry
module Logic
class Evaluator
include Dry::Equalizer(:path)
attr_reader :path
class Set
include Dry::Equalizer(:evaluators)
attr_reader :evaluators
def self.new(paths)
super(paths.map { |path| Evaluator::Key.new(path)... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/rule_compiler.rb | Ruby | mit | 179 | main | 1,720 | # frozen_string_literal: true
module Dry
module Logic
class RuleCompiler
attr_reader :predicates
def initialize(predicates)
@predicates = predicates
end
def call(ast)
ast.map { |node| visit(node) }
end
def visit(node)
name, nodes = node
send(... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/rule/interface.rb | Ruby | mit | 179 | main | 3,921 | # frozen_string_literal: true
module Dry
module Logic
class Rule
class Interface < ::Module
SPLAT = ["*rest"].freeze
attr_reader :arity
attr_reader :curried
def initialize(arity, curried)
super()
@arity = arity
@curried = curried
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/rule/predicate.rb | Ruby | mit | 179 | main | 620 | # frozen_string_literal: true
module Dry
module Logic
class Rule
class Predicate < Rule
def self.specialize(arity, curried, base = Predicate)
super
end
def type
:predicate
end
def name
predicate.name
end
def to_s
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/and.rb | Ruby | mit | 179 | main | 941 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class And < Binary
attr_reader :hints
def initialize(*, **)
super
@hints = options.fetch(:hints, true)
end
def type
:and
end
alias_method :operator, :type
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/binary.rb | Ruby | mit | 179 | main | 500 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Binary < Abstract
attr_reader :left
attr_reader :right
def initialize(left, right, **options)
super
@left = left
@right = right
end
def ast(input = Undefine... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/check.rb | Ruby | mit | 179 | main | 1,067 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Check < Unary
attr_reader :evaluator
def self.new(rule, **options)
if options[:evaluator]
super
else
keys = options.fetch(:keys)
evaluator = Evaluator::Set.... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/xor.rb | Ruby | mit | 179 | main | 479 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Xor < Binary
def type
:xor
end
alias_method :operator, :type
def call(input)
Result.new(self[input], id) { ast(input) }
end
def [](input)
left[input]... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/each.rb | Ruby | mit | 179 | main | 650 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Each < Unary
def type
:each
end
def call(input)
results = input.map { |element| rule.(element) }
success = results.all?(&:success?)
Result.new(success, id) do
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/abstract.rb | Ruby | mit | 179 | main | 804 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Abstract
include Core::Constants
include ::Dry::Equalizer(:rules, :options)
include Operators
attr_reader :rules
attr_reader :options
def initialize(*rules, **options)
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/set.rb | Ruby | mit | 179 | main | 696 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Set < Abstract
def type
:set
end
def call(input)
results = rules.map { |rule| rule.(input) }
success = results.all?(&:success?)
Result.new(success, id) do
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/key.rb | Ruby | mit | 179 | main | 1,382 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Key < Unary
attr_reader :evaluator
attr_reader :path
def self.new(rules, **options)
if options[:evaluator]
super
else
name = options.fetch(:name)
e... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/implication.rb | Ruby | mit | 179 | main | 654 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Implication < Binary
def type
:implication
end
def operator
:then
end
def call(input)
left_result = left.(input)
if left_result.success?
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/unary.rb | Ruby | mit | 179 | main | 404 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Unary < Abstract
attr_reader :rule
def initialize(*rules, **options)
super
@rule = rules.first
end
def ast(input = Undefined)
[type, rule.ast(input)]
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/negation.rb | Ruby | mit | 179 | main | 338 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Negation < Unary
def type
:not
end
def call(input)
Result.new(rule.(input).failure?, id) { ast(input) }
end
def [](input)
!rule[input]
end
end
... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/or.rb | Ruby | mit | 179 | main | 682 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Or < Binary
def type
:or
end
alias_method :operator, :type
def call(input)
left_result = left.(input)
if left_result.success?
Result::SUCCESS
e... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | lib/dry/logic/operations/attr.rb | Ruby | mit | 179 | main | 257 | # frozen_string_literal: true
module Dry
module Logic
module Operations
class Attr < Key
def self.evaluator(name)
Evaluator::Attr.new(name)
end
def type
:attr
end
end
end
end
end |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | benchmarks/setup.rb | Ruby | mit | 179 | main | 211 | # frozen_string_literal: true
require "benchmark/ips"
require "hotch"
ENV["HOTCH_VIEWER"] ||= "open"
require "dry/logic"
require "dry/logic/predicates"
def profile(&block)
Hotch(filter: "Dry", &block)
end |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | benchmarks/rule_application.rb | Ruby | mit | 179 | main | 996 | # frozen_string_literal: true
require_relative "setup"
unless Dry::Logic::Rule.respond_to?(:build)
Dry::Logic::Rule.singleton_class.alias_method(:build, :new)
end
predicates = Dry::Logic::Predicates
type_check = Dry::Logic::Rule.build(predicates[:type?]).curry(Integer)
int_check = Dry::Logic::Rule.build(predicate... |
github | dry-rb/dry-logic | https://github.com/dry-rb/dry-logic | benchmarks/builder.rb | Ruby | mit | 179 | main | 733 | # frozen_string_literal: true
require "benchmark/ips"
require "dry/logic"
require "dry/logic/builder"
def regular
user_present = Dry::Logic::Rule::Predicate.new(Dry::Logic::Predicates[:key?]).curry(:user)
min_age = Dry::Logic::Rule::Predicate.new(Dry::Logic::Predicates[:gt?]).curry(18)
has_min_age = Dry::Logic:... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | Guardfile | Ruby | mit | 179 | master | 229 | # ~*~ encoding: utf-8 ~*~
guard 'minitest' do
# with Minitest::Unit
watch(%r|^test/(.*)\/?test_(.*)\.rb|)
watch(%r|^lib/(.*/)?([^/]+)\.rb|) { |m| "test/test_#{m[2]}.rb" }
watch(%r|^test/helper\.rb|) { "test" }
end |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | gollum-lib.gemspec | Ruby | mit | 179 | master | 639 | require File.join(File.dirname(__FILE__), 'gemspec.rb')
require File.join(File.dirname(__FILE__), 'lib', 'gollum-lib', 'version.rb')
# This file needs to conditionally define the default adapter for MRI and Java, because this is the file that is included from the Gemfile.
# In addition, the default Java adapter needs t... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | Rakefile | Ruby | mit | 179 | master | 5,639 | require 'rubygems'
require 'rake'
require 'date'
require 'tempfile'
#############################################################################
#
# Helper functions
#
#############################################################################
def name
"gollum-lib"
end
def date
Time.now.strftime("%Y-%m-%d")
e... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | gemspec.rb | Ruby | mit | 179 | master | 4,087 | def specification(version, default_adapter, platform = nil)
Proc.new do |s|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.required_ruby_version = '>= 2.4'
s.name = 'gollum-lib'
s.version = version
s.platform ... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | gollum-lib_java.gemspec | Ruby | mit | 179 | master | 272 | require File.join(File.dirname(__FILE__), 'gemspec.rb')
require File.join(File.dirname(__FILE__), 'lib', 'gollum-lib', 'version.rb')
default_adapter = ['gollum-rjgit_adapter', '~> 2.0']
Gem::Specification.new &specification(Gollum::Lib::VERSION, default_adapter, "java") |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib.rb | Ruby | mit | 179 | master | 1,818 | # ~*~ encoding: utf-8 ~*~
# stdlib
require 'digest/md5'
require 'digest/sha1'
require 'ostruct'
require 'pathname'
DEFAULT_ADAPTER = RUBY_PLATFORM == 'java' ? 'rjgit' : 'rugged'
module Gollum; end
Gollum::GIT_ADAPTER = DEFAULT_ADAPTER if !defined?(Gollum::GIT_ADAPTER)
require "#{Gollum::GIT_ADAPTER.downcase}_adapter"... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/markup.rb | Ruby | mit | 179 | master | 5,974 | # ~*~ encoding: utf-8 ~*~
require 'digest/sha1'
require 'rouge'
require 'base64'
require File.expand_path '../helpers', __FILE__
# Use pygments if it's installed
begin
require 'pygments'
Pygments.start
rescue Exception
end
module Gollum
class Markup
include Helpers
@formats = {}
@extensions = []
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/helpers.rb | Ruby | mit | 179 | master | 587 | # ~*~ encoding: utf-8 ~*~
module Gollum
module Helpers
# Replace url-encoded slashes ('%2F') with slashes
# Clean up double slashes
def trim_leading_slashes(url)
return nil if url.nil?
url.gsub!('%2F', '/')
Pathname.new(url).cleanpath.to_s
end
# Take a link path and tu... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/committer.rb | Ruby | mit | 179 | master | 6,722 | # ~*~ encoding: utf-8 ~*~
module Gollum
# Responsible for handling the commit process for a Wiki. It sets up the
# Git index, provides methods for modifying the tree, and stores callbacks
# to be fired after the commit has been made. This is specifically
# designed to handle multiple updated pages in a single... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/pagination.rb | Ruby | mit | 179 | master | 2,029 | # ~*~ encoding: utf-8 ~*~
module Gollum
module Pagination
def self.included(klass)
klass.extend ClassMethods
class << klass
# Default Integer max count of items to return in git commands.
attr_accessor :per_page
end
klass.per_page = 30
end
module ClassMethods
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/markups.rb | Ruby | mit | 179 | master | 3,645 | # ~*~ encoding: utf-8 ~*~
require 'pathname'
module Gollum
module MarkupRegisterUtils
# Check if a gem exists. This implementation requires Gem::Specificaton to
# be filled.
def gem_exists?(name)
Gem::Specification.find {|spec| spec.name == name} != nil
end
def all_gems_available?(names)... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/page.rb | Ruby | mit | 179 | master | 11,938 | # ~*~ encoding: utf-8 ~*~
module Gollum
class Page < Gollum::File
include Pagination
SUBPAGENAMES = [:header, :footer, :sidebar]
class << self
# For use with self.global_find: returns true if the given query corresponds to the in-repo path of the BlobEntry.
#
# query - The Str... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/hook.rb | Ruby | mit | 179 | master | 690 | # ~*~ encoding: utf-8 ~*~
module Gollum
class Hook
@hooks = {}
class << self
def register(type, id, &block)
type_hooks = @hooks[type] ||= {}
type_hooks[id] = block
end
def unregister(type, id)
type_hooks = @hooks[type]
if type_hooks
type_hooks.... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/redirects.rb | Ruby | mit | 179 | master | 797 | require 'yaml'
REDIRECTS_FILE = '.redirects.gollum'
module Gollum
module Redirects
def stale?
@current_head != get_head_sha
end
def init(wiki)
@wiki = wiki
@current_head = get_head_sha
end
def load
file = @wiki.file(REDIRECTS_FILE)
redirects = {}
... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/wiki.rb | Ruby | mit | 179 | master | 31,035 | # ~*~ encoding: utf-8 ~*~
require 'pathname'
module Gollum
class Wiki
include Pagination
class << self
# Sets the default ref for the wiki.
attr_writer :default_refs
# Sets the default name for commits.
attr_writer :default_committer_name
# Sets the default email for commits.... |
github | gollum/gollum-lib | https://github.com/gollum/gollum-lib | lib/gollum-lib/git_access.rb | Ruby | mit | 179 | master | 5,887 | # ~*~ encoding: utf-8 ~*~
module Gollum
# Controls all access to the Git objects from Gollum. Extend this class to
# add custom caching for special cases.
class GitAccess
# Initializes the GitAccess instance.
#
# path - The String path to the Git repository that holds the
# ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.