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 | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-lang/functional/test_aggregation.rb | Ruby | mit | 49 | master | 974 | require 'spec_helper'
module Alf
module Lang
describe "Aggregation methods" do
include Functional
let(:input){[
{:tested => 1, :other => "b"},
{:tested => 30, :other => "a"},
]}
let(:expected){[
{:tested => 30, :other => "a", :upcase => "A"},
]}
cont... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_autonum.rb | Ruby | mit | 49 | master | 233 | require 'optimizer_helper'
module Alf
describe "autonum" do
subject{ autonum(an_operand, :auto) }
let(:split_attributes){ AttrList[subject.as] }
it_should_behave_like "a split-able expression for restrict"
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_summarize.rb | Ruby | mit | 49 | master | 357 | require 'optimizer_helper'
module Alf
describe "summarize" do
let(:summarization){
Summarization.coerce(:total => Aggregator.sum{ qty })
}
subject{ summarize(an_operand, [:id], summarization) }
let(:split_attributes){ subject.summarization.to_attr_list }
it_should_behave_like "a split-abl... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_rank.rb | Ruby | mit | 49 | master | 241 | require 'optimizer_helper'
module Alf
describe "rank" do
subject{ rank(an_operand, [[:x, :asc]], :rank) }
let(:split_attributes){ AttrList[subject.as] }
it_should_behave_like "a split-able expression for restrict"
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_coerce.rb | Ruby | mit | 49 | master | 249 | require 'optimizer_helper'
module Alf
describe "coerce" do
subject{ coerce(an_operand, :y => Integer) }
let(:split_attributes){ subject.coercions.to_attr_list }
it_should_behave_like "a split-able expression for restrict"
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_extend.rb | Ruby | mit | 49 | master | 246 | require 'optimizer_helper'
module Alf
describe "extend" do
subject{ extend(an_operand, :y => "x.upcase") }
let(:split_attributes){ subject.ext.to_attr_list }
it_should_behave_like "a split-able expression for restrict"
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_defaults.rb | Ruby | mit | 49 | master | 247 | require 'optimizer_helper'
module Alf
describe "defaults" do
subject{ defaults(an_operand, :y => 12) }
let(:split_attributes){ subject.defaults.to_attr_list }
it_should_behave_like "a split-able expression for restrict"
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_wrap.rb | Ruby | mit | 49 | master | 234 | require 'optimizer_helper'
module Alf
describe "wrap" do
subject{ wrap(an_operand, [:x, :y], :z) }
let(:split_attributes){ AttrList[subject.as] }
it_should_behave_like "a split-able expression for restrict"
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_group.rb | Ruby | mit | 49 | master | 237 | require 'optimizer_helper'
module Alf
describe "group" do
subject{ group(an_operand, [:x, :y], :z) }
let(:split_attributes){ AttrList[subject.as] }
it_should_behave_like "a split-able expression for restrict"
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_rename.rb | Ruby | mit | 49 | master | 646 | require 'optimizer_helper'
module Alf
describe "rename" do
subject{ rename(an_operand, renaming) }
context 'on a fully known predicate' do
let(:predicate){ Predicate.eq(:y, 2) & Predicate.eq(:foo => 3) }
let(:renaming) { {:x => :y} }
let(:replaced_predicate){
Predicate.eq(:x, 2) &... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/test_quota.rb | Ruby | mit | 49 | master | 364 | require 'optimizer_helper'
module Alf
describe "quota" do
let(:summarization){
Summarization.coerce(:total => Aggregator.sum{ qty })
}
subject{ quota(an_operand, [:id], [[:x, :asc]], summarization) }
let(:split_attributes){ subject.summarization.to_attr_list }
it_should_behave_like "a sp... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/restrict/test_on_autonum.rb | Ruby | mit | 49 | master | 1,153 | require 'optimizer_helper'
module Alf
class Optimizer
describe Restrict, "on_autonum" do
let(:inside){ an_operand }
let(:expr) { restrict(autonum(inside, :auto), predicate) }
subject{ Restrict.new.call(expr) }
context 'when the restriction does not apply to auto at all' do
let(... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/restrict/test_on_join.rb | Ruby | mit | 49 | master | 3,622 | require 'optimizer_helper'
module Alf
class Optimizer
describe Restrict, "on_join" do
let(:left) { an_operand.with_heading(id: Integer, name: String) }
let(:right){ an_operand.with_heading(id: Integer, city: String) }
let(:id_pred) { comp(id: 1) }
let(:name_pred){ comp(name: 'foo'... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/restrict/test_on_matching.rb | Ruby | mit | 49 | master | 1,356 | require 'optimizer_helper'
module Alf
class Optimizer
describe Restrict, "on_matching" do
let(:left) { an_operand.with_heading(id: Integer, name: String) }
let(:right){ an_operand.with_heading(id: Integer, city: String) }
let(:id_pred) { comp(id: 1) }
let(:name_pred){ comp(name: '... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/restrict/test_on_unwrap.rb | Ruby | mit | 49 | master | 1,278 | require 'optimizer_helper'
module Alf
class Optimizer
describe Restrict, "on_unwrap" do
let(:operand) { an_operand.with_heading(id: Integer, wrapped: Tuple[x: Integer, y: Integer]) }
let(:expr) { restrict(unwrap(operand, :wrapped), predicate) }
let(:optimized){ Restrict.new.call(expr) ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/restrict/test_on_coerce.rb | Ruby | mit | 49 | master | 1,150 | require 'optimizer_helper'
module Alf
class Optimizer
describe Restrict, "on_coerce" do
let(:inside) { an_operand }
let(:coercion){ Heading.coerce(:x => Integer) }
let(:expr) { restrict(coerce(inside, coercion), predicate) }
subject{ Restrict.new.call(expr) }
context 'when the... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/optimizer/test_search.rb | Ruby | mit | 49 | master | 1,100 | require 'optimizer_helper'
module Alf
class Optimizer
describe Search do
let(:search){
Search.new(processor, Algebra::Project)
}
let(:new_operand){ an_operand }
let(:processor){
lambda{|expr, s|
raise unless expr.is_a?(Algebra::Project)
raise unless ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/shared/an_unoptimizable_expression_for_restrict.rb | Ruby | mit | 49 | master | 492 | shared_examples_for "an unoptimizable expression for restrict" do
let(:the_predicate){
defined?(predicate) ? predicate : Alf::Predicate.eq(:x, 12)
}
let(:restriction){
restrict(subject, the_predicate)
}
let(:optimized){
Alf::Optimizer::Restrict.new.call(restriction)
}
# before(:all) do
#... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/shared/an_optimizable_expression_for_restrict.rb | Ruby | mit | 49 | master | 919 | shared_examples_for "an optimizable expression for restrict" do
let(:restriction){
restrict(subject, predicate)
}
let(:optimized){
Alf::Optimizer::Restrict.new.call(restriction)
}
let(:middle){
optimized.operand
}
let(:inside){
middle.operand
}
# before(:all) do
# puts "\n----... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/shared/a_pass_through_expression_for_restrict.rb | Ruby | mit | 49 | master | 965 | shared_examples_for "a pass-through expression for restrict" do
let(:the_predicate){
defined?(predicate) ? predicate : Alf::Predicate.native(lambda{})
}
let(:restriction){
restrict(subject, the_predicate)
}
let(:optimized){
Alf::Optimizer::Restrict.new.call(restriction)
}
# before(:all) do... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-optimizer/shared/a_split_able_expression_for_restrict.rb | Ruby | mit | 49 | master | 1,268 | shared_examples_for "a split-able expression for restrict" do
let(:split_pred){
Alf::Predicate.eq(split_attributes.to_a.first, 12)
}
let(:stay_pred){
Alf::Predicate.eq(:a_non_split_attribute, 12)
}
context 'with a native predicate' do
let(:predicate){ Alf::Predicate.native(lambda{ true }) }
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_ruby_case.rb | Ruby | mit | 49 | master | 325 | require 'spec_helper'
module Alf
describe Support, "ruby_case" do
let(:tools){ Object.new.extend(Support) }
it "should work on one word" do
tools.ruby_case(:Alf).should == "alf"
end
it "should work on multiple words" do
tools.ruby_case(:HelloWorld).should == "hello_world"
end
end... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_unsymbolize_keys.rb | Ruby | mit | 49 | master | 546 | require 'spec_helper'
module Alf
describe Support, 'unsymbolize_keys' do
include Support
subject{ unsymbolize_keys(arg) }
context 'with an empty Hash' do
let(:arg){ Hash.new }
it { should eq({}) }
end
context 'with a Hash with String keys' do
let(:arg){ {"name" => "Jones", "id... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_coerce.rb | Ruby | mit | 49 | master | 607 | require 'spec_helper'
module Alf
describe "Support#coerce" do
it 'coerces integers without trouble' do
Support.coerce("12", Integer).should eql(12)
end
it 'coerces Time without trouble' do
Support.coerce("2012-05-11 12:00:00.000000+0200", Time).should be_a(Time)
end
it 'coerces Date... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_to_lispy.rb | Ruby | mit | 49 | master | 3,230 | require 'spec_helper'
module Alf
describe Support, ".to_lispy" do
subject{ Support.to_lispy(value) }
describe "on an AttrName" do
let(:value){ :city }
it { should eq(":city") }
end
describe "on an AttrList" do
let(:value){ AttrList.new([:name, :city]) }
it { should eq("[:nam... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_tuple_scope.rb | Ruby | mit | 49 | master | 1,362 | require 'spec_helper'
module Alf
module Support
describe TupleScope do
let(:scope){ TupleScope.new }
it "should install methods properly" do
scope.__set_tuple(:hello => "a", :world => "b")
scope.respond_to?(:hello).should be_true
scope.respond_to?(:world).should be_true
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_class_name.rb | Ruby | mit | 49 | master | 346 | require 'spec_helper'
module Alf
describe Support, "class_name" do
let(:tools){ Object.new.extend(Support) }
it "should work on top-level namespaces" do
tools.class_name(Alf).should eq(:Alf)
end
it "should work on non top-level namespaces" do
tools.class_name(Alf::Support).should eq(:Su... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_registry.rb | Ruby | mit | 49 | master | 1,554 | require 'spec_helper'
module Alf
module Support
describe Registry do
let(:clazz){ Class.new.extend(Registry) }
let(:seen) { [] }
before do
clazz.listen{|n,c| seen << [n,c] }
end
describe 'when used with classes' do
before do
clazz.register(Integer, clazz)... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_rubycase_name.rb | Ruby | mit | 49 | master | 548 | require 'spec_helper'
module Alf
describe Support, "rubycase_name" do
let(:tools){ Object.new.extend(Support) }
it "should work on a Symbol" do
tools.rubycase_name(:Alf).should == :alf
end
it "should work on a String" do
tools.rubycase_name("HelloWorld").should == :hello_world
end
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_to_ruby_literal.rb | Ruby | mit | 49 | master | 600 | require 'spec_helper'
module Alf
describe "Support#to_ruby_literal" do
it 'works on Symbols' do
Support.to_ruby_literal(:name).should eql(":name")
end
it 'works on Integers' do
Support.to_ruby_literal(12).should eql("12")
end
it 'works on DateTime' do
dt = DateTime.parse('2012... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_to_tuple.rb | Ruby | mit | 49 | master | 646 | require 'spec_helper'
module Alf
describe "Support#to_tuple" do
let(:expected){
Tuple(name: "Alf")
}
def to_tuple(x, &bl)
Tuple(x, &bl) # Tuple(...) -> Alf::Tuple(...) -> Support.to_tuple(...)
end
it 'returns a tuple already' do
to_tuple(name: "Alf").should eq(expected)
en... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/test_symbolize_keys.rb | Ruby | mit | 49 | master | 540 | require 'spec_helper'
module Alf
describe Support, 'symbolize_keys' do
include Support
subject{ symbolize_keys(arg) }
context 'with an empty Hash' do
let(:arg){ Hash.new }
it { should eq({}) }
end
context 'with a Hash with all symbols already' do
let(:arg){ {:name => "Jones", ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/tuple_scope/test_to_s.rb | Ruby | mit | 49 | master | 458 | require 'spec_helper'
module Alf
module Support
describe TupleScope, "to_s and inspect" do
let(:tuple){ {:a => 1, :b => 2} }
context 'with a simple TupleScope' do
let(:scope){ TupleScope.new(tuple) }
it "delegates to_s to the tuple" do
scope.to_s.should eq(tuple.to_s)
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/tuple_scope/test_hash_get.rb | Ruby | mit | 49 | master | 385 | require 'spec_helper'
module Alf
module Support
describe TupleScope, "[]" do
context 'with a simple TupleScope' do
let(:scope){ TupleScope.new(:a => 1, :b => 2) }
it "delegates to the tuple" do
scope[:a].should == 1
end
it "return nil on unexisting" do
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/tuple_scope/test_evaluate.rb | Ruby | mit | 49 | master | 1,001 | require 'spec_helper'
module Alf
module Support
describe TupleScope, "evaluate" do
context 'with a simple TupleScope' do
let(:scope){ TupleScope.new(:a => 1, :b => 2) }
it "should allow a block" do
scope.evaluate{ a }.should == 1
end
it 'should resolve DUM and DE... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/tuple_scope/test_respond_to.rb | Ruby | mit | 49 | master | 983 | require 'spec_helper'
module Alf
module Support
describe TupleScope, 'respond_to?' do
context 'on an empty TupleScope' do
let(:scope){ TupleScope.new }
it_behaves_like "A scope"
it 'responds to [], to_s and inspect' do
scope.respond_to?(:[]).should be_true
scop... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/scope/test_evaluate.rb | Ruby | mit | 49 | master | 1,173 | require 'spec_helper'
module Alf
module Support
describe Scope, "evaluate" do
context 'on a scope with helpers' do
let(:scope) { Scope.new [ HelpersInScope ] }
it 'has available helpers in scope' do
scope.evaluate{ hello(world) }.should eq("Hello world!")
end
it ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/scope/test_branch.rb | Ruby | mit | 49 | master | 626 | require 'spec_helper'
module Alf
module Support
describe Scope, '__branch' do
let(:scope) { Scope.new [ HelpersInScope ] }
subject{ scope.__branch(arg) }
context 'when branched with a Tuple' do
let(:arg){ {:here => "here"} }
it_behaves_like 'A scope'
it 'responds to ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/scope/test_initialize.rb | Ruby | mit | 49 | master | 443 | require 'spec_helper'
module Alf
module Support
describe Scope, 'initialize' do
it 'supports no argument' do
lambda{ Scope.new }.should_not raise_error
end
it 'supports an array of modules' do
lambda{ Scope.new([ Helpers ]) }.should_not raise_error
end
it 'supports... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/scope/test_respond_to.rb | Ruby | mit | 49 | master | 747 | require 'spec_helper'
module Alf
module Support
describe Scope, 'respond_to?' do
context 'on an empty Scope' do
subject{ Scope.new }
it_behaves_like "A scope"
end
context 'on a Scope that has helpers' do
subject{ Scope.new [ HelpersInScope ] }
it_behaves_like "... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_option_setter.rb | Ruby | mit | 49 | master | 1,583 | require 'spec_helper'
module Alf
module Support
describe Config, 'option setter' do
let(:conf_subclass){
Class.new(Config){
option :ready, Boolean, false
option :which, String, ->{ "foo" }
option :done, Proc, ->{ "bar" }
}
}
let(:config){ conf_subc... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_hash_get.rb | Ruby | mit | 49 | master | 734 | require 'spec_helper'
module Alf
module Support
describe Config, '[]' do
let(:conf_subclass){
Class.new(Config){
option :ready, Boolean, false
option :preferences, Array, ["foo"]
}
}
let(:config){ conf_subclass.new }
subject{ config[attr] }
con... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_option.rb | Ruby | mit | 49 | master | 959 | require 'spec_helper'
module Alf
module Support
describe Config, '.option' do
let(:conf1){
Class.new(Config){
option :ready, Boolean, false
option :which, String, ->{ "foo" }
option :done, Proc, ->{ "bar" }
option :cross, String, ->{ which.capitalize }
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_freeze.rb | Ruby | mit | 49 | master | 771 | require 'spec_helper'
module Alf
module Support
describe Config, 'freeze' do
let(:conf_subclass){
Class.new(Config){
option :ready, Boolean, false
option :preferences, Array, []
}
}
let(:config){ conf_subclass.new }
subject{ config.freeze }
it ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_helpers.rb | Ruby | mit | 49 | master | 652 | require 'spec_helper'
module Alf
module Support
describe Config, "helpers" do
let(:config_class){
Class.new(Config){
option :ready, Boolean, true
option :hello, String, "world"
}
}
subject{ config_class.helpers(:a_config) }
it { should be_a(Module) }... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_merge.rb | Ruby | mit | 49 | master | 720 | require 'spec_helper'
module Alf
module Support
describe Config, "merge" do
let(:config_class){
Class.new(Config){
option :ready, Boolean, true
option :hello, String, "world"
}
}
let(:config){ config_class.new }
subject{ config.merge(ready: false) }
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_hash_set.rb | Ruby | mit | 49 | master | 1,270 | require 'spec_helper'
module Alf
module Support
describe Config, '[]=' do
let(:conf_subclass){
Class.new(Config){
option :ready, Boolean, false
option :preferences, Array, ["foo"]
}
}
let(:config){ conf_subclass.new }
subject{ config[attr] = value }
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_dup.rb | Ruby | mit | 49 | master | 1,508 | require 'spec_helper'
module Alf
module Support
describe Config, 'dup' do
let(:conf_subclass){
Class.new(Config){
option :ready, Boolean, false
option :preferences, Array, []
option :aproc, Boolean, ->{ !ready? }
}
}
let(:config){ conf_subclass.new... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_new.rb | Ruby | mit | 49 | master | 1,340 | require 'spec_helper'
module Alf
module Support
describe Config, '.new' do
let(:conf_subclass){
Class.new(Config){
option :ready, Boolean, false
}
}
subject{ conf_subclass.new(h) }
context 'when options must be coerced' do
let(:h){ {ready: "true"} }
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/unit/alf-support/config/test_options.rb | Ruby | mit | 49 | master | 417 | require 'spec_helper'
module Alf
module Support
describe Config, '.options' do
let(:conf){
Class.new(Config){
option :ready, Boolean, false
option :hello, String, "world"
}
}
it 'should contain the options' do
conf.options.should eq([
[:rea... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/shared/a_value.rb | Ruby | mit | 49 | master | 312 | shared_examples_for "A value" do
it "should have a inspect/class.parse that lead to equal values" do
Kernel.eval(subject.inspect).should eq(subject)
end
it "should act a valid Hash keys" do
dup = Kernel.eval(subject.inspect)
{subject => true, dup => false}.size.should == 1
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/shared/a_valid_type_implementation.rb | Ruby | mit | 49 | master | 1,058 | shared_examples_for "A valid type implementation" do
it 'should have exemplars available' do
type.exemplars.should_not be_empty
type.exemplars.each do |value|
(type === value).should be_true
end
end
it 'should define dupable values' do
type.exemplars.each do |ex|
ex.dup.should eq(ex)... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/shared/an_operator_class.rb | Ruby | mit | 49 | master | 1,363 | shared_examples_for "An operator class" do
it "should have a public rubycase_name method" do
operator_class.should respond_to(:rubycase_name)
end
it "should have an arity class method" do
operator_class.should respond_to(:arity)
end
it "should have a unary? class method" do
operator_class.shoul... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/shared/a_cog.rb | Ruby | mit | 49 | master | 903 | shared_examples_for 'a cog' do
it { should be_a(Alf::Engine::Cog) }
it 'should return self on to_cog' do
subject.to_cog.should be(subject)
end
end
shared_examples_for 'a traceable cog' do
it_should_behave_like "a cog"
def has_tracking!(compiled)
compiled.expr.should_not be_nil
case compiled
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/shared/a_scope.rb | Ruby | mit | 49 | master | 547 | shared_examples_for "A scope" do
it 'responds to its own methods' do
subject.respond_to?(:respond_to?).should be_true
subject.respond_to?(:evaluate).should be_true
subject.respond_to?(:__eval_binding).should be_true
end
it 'responds to needed kernel methods' do
subject.respond_to?(:lambda).shoul... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/integration/test_examples.rb | Ruby | mit | 49 | master | 841 | require 'spec_helper'
Path.backfind("examples").glob("**/*.alf").each do |file|
describe "Alf example: #{file}" do
let(:example_path){ file }
let(:example_dir) { file.parent }
let(:example_db) { Alf.connect(example_dir) }
let(:source){ example_path.read }
context 'when optimized through relvar... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/integration/ext/test_relation.rb | Ruby | mit | 49 | master | 357 | require 'spec_helper'
describe "Relation()" do
it 'returns a Relation' do
Relation(:name => "Alf").should be_a(Alf::Relation)
end
it 'helps building a singleton' do
Relation(:name => "Alf").cardinality.should eq(1)
end
it 'helps building a list if values' do
Relation(:name => ["Alf", "Myrrha"])... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/integration/relation/test_extend.rb | Ruby | mit | 49 | master | 315 | require 'spec_helper'
describe Alf::Relation, 'extend' do
let(:rel) {
Relation(name: ["Jones", "Smith"])
}
let(:expected){
Relation(name: ["JONESfoo", "SMITHfoo"])
}
let(:scoped){
"foo"
}
it 'supports procs of arity 1' do
rel.extend(foo: ->(t){ t.name.upcase + scoped })
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | spec/integration/relation/test_to_array.rb | Ruby | mit | 49 | master | 696 | require 'spec_helper'
describe Alf::Relation, 'to_array' do
let(:rel) {
examples_database.query do
group((project suppliers, [:city, :name]), [:name], :incity)
end
}
let(:expected){
[
{:city => 'Athens', :incity => [ {:name => 'Adams'} ]},
{:city => 'London', :incity => [ {:name =>... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | tasks/integration_test.rake | Ruby | mit | 49 | master | 1,226 | begin
require "rspec/core/rake_task"
desc "Run RSpec code examples"
RSpec::Core::RakeTask.new(:integration_test => :unit_test) do |t|
# Glob pattern to match files.
t.pattern = "spec/integration/**/test_*.rb"
# Whether or not to fail Rake when an error occurs (typically when
# examples fail).
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | tasks/gh-pages.rake | Ruby | mit | 49 | master | 2,159 | module Alf
def self.markdown(md)
Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(md)
end
end
task :"gh-pages" do
$:.unshift File.expand_path('../../lib', __FILE__)
require 'fileutils'
require 'wlang'
require 'wlang/ext/hash_methodize'
require 'alf'
require 'bluecloth'
require 'redcarpet'
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | tasks/yard.rake | Ruby | mit | 49 | master | 1,653 | # Installs a rake task to generate API documentation using yard.
#
# This file installs the 'rake yard' task. It is automatically generated by Noe from
# your .noespec file, and should therefore be configured there, under the
# variables/rake_tasks/yard entry, as illustrated below:
#
# variables:
# rake_tasks:
# ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | tasks/gem.rake | Ruby | mit | 49 | master | 281 | require 'rubygems/package_task'
gemspec_file = File.expand_path('../../alf-core.gemspec', __FILE__)
gemspec = Kernel.eval(File.read(gemspec_file))
Gem::PackageTask.new(gemspec) do |t|
t.name = gemspec.name
t.version = gemspec.version
t.package_files = gemspec.files
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | tasks/regression_test.rake | Ruby | mit | 49 | master | 1,264 | begin
require "rspec/core/rake_task"
desc "Run RSpec code examples"
RSpec::Core::RakeTask.new(:regression_test => :integration_test) do |t|
# Glob pattern to match files.
t.pattern = "spec/regression/**/test_*.rb"
# Whether or not to fail Rake when an error occurs (typically when
# examples fail... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | tasks/unit_test.rake | Ruby | mit | 49 | master | 1,213 | begin
require "rspec/core/rake_task"
desc "Run RSpec code examples"
RSpec::Core::RakeTask.new(:unit_test) do |t|
# Glob pattern to match files.
t.pattern = "spec/unit/**/test_*.rb"
# Whether or not to fail Rake when an error occurs (typically when
# examples fail).
t.fail_on_error = true
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | examples/memory_database.rb | Ruby | mit | 49 | master | 1,765 | require 'alf'
module MemoryDatabase
include Alf::Viewpoint
def suppliers
Relation(
{:sid => "S1", :name => "Smith", :status => 20, :city => "London"},
{:sid => "S2", :name => "Jones", :status => 10, :city => "Paris"},
{:sid => "S3", :name => "Blake", :status => 30, :city => "Paris"},
{:... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | examples/functions-as-values.rb | Ruby | mit | 49 | master | 896 | require 'alf'
module Database
include Alf::Viewpoint
def orders
Relation(
Tuple(oid: "O1", city: "London", amount: 100.00),
Tuple(oid: "O2", city: "Paris", amount: 100.00))
end
def discount_rules
Relation(
Tuple(city: "London", rule: ->{ amount * 0.20 }),
Tuple(city: "Paris",... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | examples/readme.rb | Ruby | mit | 49 | master | 485 | require 'alf'
db = Alf.examples
grouped = db.query{
group(suppliers, [:sid, :name, :status], :in_that_city)
}
puts grouped
grouped2 = db.query{
extend(grouped, how_many: ->{ in_that_city.count },
avg_status: ->{ in_that_city.avg{ status } })
}
puts grouped2
summarized = db.query{
summary ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/engine.rb | Ruby | mit | 49 | master | 1,170 | module Alf
module Engine
Cogable = lambda{|arg| arg.respond_to?(:to_cog) }
end # module Engine
end # module Alf
require_relative 'engine/cog'
require_relative 'engine/support/cesure'
require_relative 'engine/leaf'
require_relative 'engine/autonum'
require_relative 'engine/clip'
require_relative 'engine/coerc... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/viewpoint.rb | Ruby | mit | 49 | master | 1,389 | require_relative 'viewpoint/metadata'
module Alf
module Viewpoint
module ClassMethods
def metadata
@metadata ||= Metadata.new
end
def expects(*viewpoints)
metadata.expects(viewpoints)
end
def depends(as, *viewpoints)
metadata.depends(as => viewpoints)
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/core.rb | Ruby | mit | 49 | master | 992 | require_relative 'core/loader'
require_relative 'core/version'
require_relative 'errors'
require_relative 'ext'
require_relative 'facade'
module Alf
TupleLike = lambda{|t| t.is_a?(Hash) || t.is_a?(Tuple) }
RelationLike = lambda{|r| Relation===r || Engine::Cog===r || Reader===r || Relvar===r }
end
require_relat... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/predicate.rb | Ruby | mit | 49 | master | 2,343 | require_relative 'predicate/factory'
require_relative 'predicate/grammar'
require_relative 'predicate/processors'
module Alf
class Predicate
def initialize(sexpr)
@sexpr = sexpr
end
attr_reader :sexpr
alias :expr :sexpr
class << self
include Factory
def coerce(arg)
cas... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/renderer.rb | Ruby | mit | 49 | master | 3,982 | module Alf
#
# Renders a relation iterator in a specific format.
#
# A renderer takes a tuple iterator as input and renders it on an output stream.
# Similarly to the {Reader} class, this one provides a registration mechanism for
# specific output formats. The common scenario is as follows:
#
# # Regi... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/adapter.rb | Ruby | mit | 49 | master | 3,355 | module Alf
class Adapter
class << self
include Support::Registry
# Register an adapter class under a specific name.
#
# Registered class must implement a recognizes? method that takes an array of
# arguments; it must returns true if an adapter instance can be built using those
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/relation.rb | Ruby | mit | 49 | master | 4,101 | require_relative 'tuple'
module Alf
#
# Defines an in-memory relation data structure.
#
# A relation is a set of tuples; a tuple is a set of attribute (name, value) pairs. The
# class implements such a data structure with full relational algebra installed as
# instance methods.
#
# Relation values can b... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/algebra.rb | Ruby | mit | 49 | master | 313 | require_relative 'algebra/support'
require_relative 'algebra/operand'
require_relative 'algebra/operator'
require_relative 'algebra/shortcut'
module Alf
module Algebra
def named_operand(name, connection = nil)
Operand::Named.new(name, connection)
end
module_function :named_operand
end
end |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/errors.rb | Ruby | mit | 49 | master | 512 | module Alf
class Error < StandardError; end
class ConfigError < Alf::Error; end
class UnboundError < StandardError; end
class NotSupportedError < Error; end
class NoSuchRelvarError < Error; end
class NoSuchTupleError < Error; end
class FactAssertionError < Error; end
class CoercionError < Error; end
c... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/tuple.rb | Ruby | mit | 49 | master | 2,797 | module Alf
class Tuple
extend Domain::Reuse.new(Hash)
extend Domain::HeadingBased.new(self)
reuse :map, :size, :empty?, :fetch, :[], :to_a, :keys, :values_at, :has_key?
coercions do |c|
c.coercion(Tuple){|tuple,type|
c.coerce(tuple.to_hash, type)
}
c.coercion(Hash){|hash,ty... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/types.rb | Ruby | mit | 49 | master | 1,862 | module Alf
#
# This module defines a namespace for useful datatypes as well as a few typing tools.
# Defined types are automatically defined as constants on the Alf module itself.
#
module Types
# Returns the (least) common super type of c1 and c2.
#
# The least common super type is defined as th... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/compiler.rb | Ruby | mit | 49 | master | 1,449 | module Alf
class Compiler
def supports_reuse?
false
end
def join(plan)
nil
end
def call(expr)
Plan.new(self).compile(expr)
end
def compile(plan, expr, compiled, usage_count)
send(to_method_name(expr), plan, expr, *compiled)
end
def on_relation(plan, exp... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/relvar.rb | Ruby | mit | 49 | master | 1,757 | module Alf
module Relvar
extend Forwardable
include Algebra::Operand
include Lang::ObjectOriented
def initialize(expr = nil)
@expr = expr
end
attr_reader :expr
def_delegators :expr, :heading,
:keys,
:to_cog,
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/database.rb | Ruby | mit | 49 | master | 1,174 | require_relative 'database/options'
require_relative 'database/connection'
module Alf
class Database
include Options.helpers(:default_options)
def self.new(conn_spec, options = {})
adapter = Adapter.factor(conn_spec)
options = Options.new(options)
yield(options) if block_given?
super(... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/support.rb | Ruby | mit | 49 | master | 618 | module Alf
#
# Provides tooling methods that are used here and there in Alf.
#
module Support
extend self
end # module Support
Tools = Support
end # module Alf
require_relative 'support/registry'
require_relative 'support/coerce'
require_relative 'support/to_ruby_literal'
require_relative 'support/to_l... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/facade.rb | Ruby | mit | 49 | master | 1,192 | module Alf
module Facade
def database(*args, &bl)
Alf::Database.new(*args, &bl)
end
def connect(*args, &bl)
Alf::Database.connect(*args, &bl)
end
def query(*args, &bl)
connect(*args) do |conn|
conn.query(&bl)
end
end
def examples_adapter
Path.backf... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/optimizer.rb | Ruby | mit | 49 | master | 894 | module Alf
class Optimizer
def initialize
@processors = []
end
def call(expr)
@processors.inject(expr){|c,p| p.call(c) }
end
def register(processor)
@processors << processor
self
end
class Base < Algebra::Rewriter
include Lang::Functional
def call(e... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/aggregator.rb | Ruby | mit | 49 | master | 6,529 | module Alf
#
# Aggregation operator.
#
# This class provides a basis for implementing aggregation operators. It should always
# be used as a superclass for such implementations.
#
# Aggregation operators are made available through factory methods on the
# Aggregator class itself:
#
# Aggregator.... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/dsl.rb | Ruby | mit | 49 | master | 393 | module Alf
module Dsl
Tuple = Alf::Tuple
Relation = Alf::Relation
DUM = Alf::Relation::DUM
DEE = Alf::Relation::DEE
def Relation(*args, &bl)
::Alf::Relation(*args, &bl)
end
def Tuple(*args, &bl)
::Alf::Tuple(*args, &bl)
end
def Heading(*args, &bl)
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/reader.rb | Ruby | mit | 49 | master | 6,980 | module Alf
#
# Implements an iterator at the interface with the outside world.
#
# This base class provides a default behavior for readers that works with IO objects. It
# can be safely extended, overriden, or mimiced. This class also provides a registration
# mechanism to help getting Reader instances for ... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/ext/yaml.rb | Ruby | mit | 49 | master | 874 | module Psych
module Visitors
class YAMLTree
def visit_Alf_Tuple o
@emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::BLOCK)
o.to_hash.each do |k,v|
accept k.to_s
accept v
end
@emitter.end_mapping
end
def visit_Alf_Relation o
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/ext/domain/heading_based.rb | Ruby | mit | 49 | master | 3,519 | module Domain
class HeadingBased < Module
EMPTY_SET = Set.new.freeze
def initialize(master_class)
define_method(:new){|*args|
raise "#{master_class}.new may not be called directly" if master_class==self
super(*args)
}
define_method(:type){|generating_type={},&bl|
cl... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/reader/json.rb | Ruby | mit | 49 | master | 561 | module Alf
class Reader
#
# Implements Alf::Reader contract for reading JSON input.
#
class JSON < Reader
def self.mime_type
"application/json"
end
def each
return to_enum unless block_given?
require 'json'
p = ::JSON.parse(input_text, create_additio... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/reader/ruby.rb | Ruby | mit | 49 | master | 532 | module Alf
class Reader
#
# Specialization of the Reader contract for .rb files.
#
# A .rb file/stream contains some ruby code that evaluates to a Relation-like
# object, typically an Array of hashes.
#
class Ruby < Reader
def self.mime_type
nil
end
def each(&bl... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/reader/rash.rb | Ruby | mit | 49 | master | 1,045 | module Alf
class Reader
#
# Specialization of the Reader contract for .rash files.
#
# A .rash file/stream contains one ruby hash literal on each line. This reader simply
# decodes each of them in turn with Kernel.eval, providing a state-less reader (that
# is, tuples are not all loaded in mem... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/reader/yaml.rb | Ruby | mit | 49 | master | 535 | module Alf
class Reader
#
# Implements Alf::Reader contract for reading YAML input.
#
class YAML < Reader
def self.mime_type
"text/yaml"
end
def each
return to_enum unless block_given?
require 'yaml'
p = ::YAML.load(input_text)
p = [p] if Tup... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/reader/csv.rb | Ruby | mit | 49 | master | 680 | module Alf
class Reader
#
# Implements Alf::Reader contract for reading CSV files.
#
class CSV < Reader
include Support::CSVUtils
def self.mime_type
"text/csv"
end
def each
return to_enum unless block_given?
with_input_io do |io|
block = Proc... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/lang/predicates.rb | Ruby | mit | 49 | master | 330 | module Alf
module Lang
module Predicates
[ :tautology, :contradiction,
:among, :in, :eq, :neq,
:lt, :lte, :gt, :gte, :between ].each do |m|
define_method(m) do |*args|
Predicate.send(m, *args)
end
end
end # module Predicates
end # module Lang
end # m... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/lang/functional.rb | Ruby | mit | 49 | master | 1,055 | module Alf
module Lang
module Functional
class << self
def def_aggregator_method(name, clazz)
define_method(name) do |*args, &block|
clazz.new(*args, &block)
end
end
def def_operator_method(name, clazz)
define_method(name) do |*args|
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/lang/aggregators.rb | Ruby | mit | 49 | master | 400 | module Alf
module Lang
module Aggregators
class << self
def def_aggregator_method(name, clazz)
define_method(name) do |*args, &block|
clazz.new(*args, &block)
end
end
end
Aggregator.listen do |name, clazz|
def_aggregator_method(name, claz... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/lang/object_oriented.rb | Ruby | mit | 49 | master | 638 | require_relative 'oo/aggregation_methods'
require_relative 'oo/algebra_methods'
require_relative 'oo/rendering_methods'
module Alf
module Lang
module ObjectOriented
include AggregationMethods
include AlgebraMethods
include RenderingMethods
def self.new(self_operand)
Module.new{
... |
github | alf-tool/alf-core | https://github.com/alf-tool/alf-core | lib/alf/lang/parser/safer.rb | Ruby | mit | 49 | master | 1,667 | require 'ruby_cop'
module Alf
module Lang
module Parser
class Safer
include Parser
def initialize(helpers = [], connection = nil)
@lispy = Lispy.new(helpers, connection)
end
def parse(expr = nil, *rest, &bl)
if expr.nil? and bl
raise Security... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.