primedia-endeca 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +31 -0
- data/README.rdoc +60 -0
- data/Rakefile +48 -0
- data/example/benchmark.rb +13 -0
- data/example/listing.rb +36 -0
- data/lib/class_to_proc.rb +5 -0
- data/lib/core_ext.rb +73 -0
- data/lib/endeca.rb +38 -0
- data/lib/endeca/dimension.rb +30 -0
- data/lib/endeca/document.rb +109 -0
- data/lib/endeca/document_collection.rb +93 -0
- data/lib/endeca/map.rb +119 -0
- data/lib/endeca/readers.rb +95 -0
- data/lib/endeca/refinement.rb +29 -0
- data/lib/endeca/request.rb +58 -0
- data/lib/endeca/transformer.rb +40 -0
- data/spec/core_ext_spec.rb +52 -0
- data/spec/endeca/dimension_spec.rb +65 -0
- data/spec/endeca/document_collection_spec.rb +116 -0
- data/spec/endeca/document_spec.rb +290 -0
- data/spec/endeca/map_spec.rb +81 -0
- data/spec/endeca/readers_spec.rb +112 -0
- data/spec/endeca/refinement_spec.rb +38 -0
- data/spec/endeca/request_spec.rb +65 -0
- data/spec/endeca/transformer_spec.rb +50 -0
- data/spec/endeca_spec.rb +12 -0
- data/spec/rcov.opts +5 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +1 -0
- metadata +93 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
+
|
3
|
+
describe Endeca::Map do
|
4
|
+
before do
|
5
|
+
@query = {:foo => "bazz", :bizz => "somevalue"}
|
6
|
+
@map = Endeca::Map.new :foo, :bizz
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".perform" do
|
10
|
+
it "should return correctly mapped hash" do
|
11
|
+
@map.perform(@query).should == {:bizz => "bazz"}
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should transform the value based on the block" do
|
15
|
+
map = @map.transform{|val| val.to_s.upcase}
|
16
|
+
map.perform(@query).should == {:bizz => "BAZZ"}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should nest in parent_hash" do
|
20
|
+
@map.into({:bip => :bop}).perform(@query).
|
21
|
+
should == {:bip => "bizz", :bop => "bazz"}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should join the new value with the existing value" do
|
25
|
+
map = @map.join('|')
|
26
|
+
map.perform(@query).should == {:bizz => "somevalue|bazz"}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#into" do
|
31
|
+
it "should assign the hash to map the given query hash into" do
|
32
|
+
@map.into(:foo => :bar).instance_variable_get(:@into).should == {:foo => :bar}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should assign the default character to join keys to values with" do
|
36
|
+
@map.into(:foo => :bar).instance_variable_get(:@with).should == ':'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should assign the default character used to join key/value pairs" do
|
40
|
+
@map.into(:foo => :bar).instance_variable_get(:@join).should == '|'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#with" do
|
45
|
+
it "should assign the character to join keys to values with" do
|
46
|
+
@map.with('*').instance_variable_get(:@with).should == '*'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#join" do
|
51
|
+
it "should assign the character used to join key/value pairs" do
|
52
|
+
@map.join('*').instance_variable_get(:@join).should == '*'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#boolean" do
|
57
|
+
it "should convert a true value to its integral equivalent" do
|
58
|
+
@map.boolean.perform(:foo => true).should == {:bizz => 1}
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should convert a false value to its integral equivalent" do
|
62
|
+
@map.boolean.perform(:foo => false).should == {:bizz => 0}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#==" do
|
67
|
+
it "is true if the keys, join and transformations are equivalent" do
|
68
|
+
Endeca::Map.new(:foo, :bar).into(:M).should == Endeca::Map.new(:foo, :bar).into(:M)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#transform" do
|
73
|
+
it "should execute the transformation block on the query"
|
74
|
+
map = Endeca::Map.new(:field_list)
|
75
|
+
map.into(:F).transform do |fields_array|
|
76
|
+
fields_array.collect{|field| "#{field.to_s}:1"}.join('|')
|
77
|
+
end
|
78
|
+
map.perform(:field_list => [:first_name, :last_name, :email]).
|
79
|
+
should == {:F => "first_name:1|last_name:1|email:1"}
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
+
|
3
|
+
describe Endeca::Readers do
|
4
|
+
class Helper
|
5
|
+
extend Endeca::Readers
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
@helper = Class.new(Endeca::Document)
|
10
|
+
@a_helper = @helper.new('Properties' => {'helper_id' => "1"})
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".add_reader" do
|
14
|
+
it "should add a method named for the argument" do
|
15
|
+
@helper.add_reader(:float_reader) {|x| x.to_f}
|
16
|
+
@helper.should respond_to(:float_reader)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".reader" do
|
21
|
+
describe "with a symbol" do
|
22
|
+
it "adds a reader that returns the attribute by that key" do
|
23
|
+
@helper.reader(:helper_id)
|
24
|
+
@a_helper.should respond_to(:helper_id)
|
25
|
+
@a_helper.helper_id.should == "1"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with a hash" do
|
30
|
+
it "adds a reader that returns the corresponding element" do
|
31
|
+
@helper.reader(:helper_id => :new_helper_id)
|
32
|
+
@a_helper.should respond_to(:new_helper_id)
|
33
|
+
@a_helper.new_helper_id.should == "1"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with a hash and a block" do
|
38
|
+
it "adds a reader that returns the corresponding element, cast by calling the block" do
|
39
|
+
@helper.reader(:helper_id => :succ_helper_id){|id| id.succ}
|
40
|
+
@a_helper.should respond_to(:succ_helper_id)
|
41
|
+
@a_helper.succ_helper_id.should == "1".succ
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe ".integer_reader" do
|
47
|
+
it "adds a reader that casts the value to an integer" do
|
48
|
+
@helper.integer_reader(:helper_id)
|
49
|
+
@a_helper.helper_id.should == 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ".decimal_reader" do
|
54
|
+
it "adds a reader that casts the value to an decimal" do
|
55
|
+
@helper.decimal_reader(:helper_id)
|
56
|
+
@a_helper.helper_id.should == BigDecimal.new("1")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".float_reader" do
|
61
|
+
it "adds a reader that casts the value to an float" do
|
62
|
+
@helper.float_reader(:helper_id)
|
63
|
+
a_helper = @helper.new('Properties' => {'helper_id' => "1.9234"})
|
64
|
+
a_helper.helper_id.should == Float("1.9234")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe ".boolean_reader" do
|
69
|
+
it "adds a reader that casts the value to an boolean" do
|
70
|
+
@helper.boolean_reader(:helper_id)
|
71
|
+
@a_helper.helper_id.should == true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe ".dim_reader" do
|
76
|
+
describe "with a symbol" do
|
77
|
+
it "adds a reader that returns the name of that dimension" do
|
78
|
+
@helper.dim_reader(:type)
|
79
|
+
dimensions = {"type" => mock('type', :name => 'a type')}
|
80
|
+
@a_helper.stub!(:dimensions).and_return(dimensions)
|
81
|
+
@a_helper.type.should == 'a type'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "with a string" do
|
86
|
+
it "adds a reader that returns the name of that dimension" do
|
87
|
+
@helper.dim_reader('type')
|
88
|
+
dimensions = {"type" => mock('type', :name => 'a type')}
|
89
|
+
@a_helper.stub!(:dimensions).and_return(dimensions)
|
90
|
+
@a_helper.type.should == 'a type'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "with a string that has spaces" do
|
95
|
+
it "adds a reader that returns the name of that dimension" do
|
96
|
+
@helper.dim_reader('type a lot' => :type_a_lot)
|
97
|
+
dimensions = {"type a lot" => mock('type', :name => 'a type')}
|
98
|
+
@a_helper.stub!(:dimensions).and_return(dimensions)
|
99
|
+
@a_helper.type_a_lot.should == 'a type'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "exception handling" do
|
105
|
+
it "should raise an Endeca::Reader error if the call fails" do
|
106
|
+
helper = Class.new(Endeca::Document)
|
107
|
+
helper.integer_reader(:helper_id)
|
108
|
+
helper = helper.new('Properties' => {'helper_id' => 'W'})
|
109
|
+
lambda{helper.helper_id}.should raise_error(Endeca::ReaderError, %{invalid value for Integer: "W"})
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
+
|
3
|
+
describe Endeca::Refinement do
|
4
|
+
before do
|
5
|
+
@refinement = Endeca::Refinement.new
|
6
|
+
end
|
7
|
+
describe '#==' do
|
8
|
+
it "should compare refinements by id" do
|
9
|
+
doc_1, doc_2 = Endeca::Refinement.new, Endeca::Refinement.new
|
10
|
+
doc_1.stub!(:id).and_return(1)
|
11
|
+
doc_2.stub!(:id).and_return(1)
|
12
|
+
(doc_1 == doc_2).should be_true
|
13
|
+
|
14
|
+
doc_2.stub!(:id).and_return(2)
|
15
|
+
(doc_1 == doc_2).should be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#inspect' do
|
20
|
+
it "includes the class name" do
|
21
|
+
@refinement.inspect.should include(Endeca::Refinement.name)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "includes the hex string of the object id" do
|
25
|
+
@refinement.inspect.should include("0x#{@refinement.object_id.to_s(16)}")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "includes the id" do
|
29
|
+
@refinement.stub!(:id).and_return(1)
|
30
|
+
@refinement.inspect.should include('id=1')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "includes the inspected name" do
|
34
|
+
@refinement.stub!(:name).and_return('A Name')
|
35
|
+
@refinement.inspect.should include('name="A Name"')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fake_web'
|
3
|
+
require 'json'
|
4
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
5
|
+
|
6
|
+
describe Endeca::Request do
|
7
|
+
before do
|
8
|
+
@path = 'http://example.com/foobar'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.perform' do
|
12
|
+
it "initalializes a new request object and performs the request" do
|
13
|
+
path = 'path'
|
14
|
+
query = 'query'
|
15
|
+
request = mock('Endeca::Request')
|
16
|
+
request.should_receive(:perform)
|
17
|
+
Endeca::Request.should_receive(:new).with(path, query).and_return(request)
|
18
|
+
|
19
|
+
Endeca::Request.perform(path, query)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#perform' do
|
24
|
+
before do
|
25
|
+
@request = Endeca::Request.new(@path)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "when successful" do
|
29
|
+
before do
|
30
|
+
@response_hash = {"foo" => "bar"}
|
31
|
+
FakeWeb.register_uri(@path, :string => @response_hash.to_json)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return the parsed JSON of the response body" do
|
35
|
+
@request.perform.should == @response_hash
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "when unsuccessful" do
|
40
|
+
before do
|
41
|
+
FakeWeb.register_uri(@path, :status => ['404', 'Not Found'])
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should raise an Endeca::RequestError" do
|
45
|
+
lambda {@request.perform}.should raise_error(Endeca::RequestError, '404 "Not Found"')
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#uri'
|
52
|
+
describe "with a hash of query options" do
|
53
|
+
it "should append the query options onto the url" do
|
54
|
+
query = {:foo => :bar}
|
55
|
+
Endeca::Request.new(@path, query).uri.query.should == query.to_params
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "with a string of query options" do
|
60
|
+
it "should append the query options string onto the url" do
|
61
|
+
query = 'N=56'
|
62
|
+
Endeca::Request.new(@path, query).uri.query.should == query.to_params
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
+
|
3
|
+
describe Endeca::Transformer do
|
4
|
+
class Helper
|
5
|
+
extend Endeca::Transformer
|
6
|
+
|
7
|
+
inherited_accessor :mappings, {}
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
@helper = Helper.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should add the map method to the class" do
|
15
|
+
Helper.should respond_to(:map)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should add the tranform_query_options method to the class" do
|
19
|
+
Helper.should respond_to(:transform_query_options)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".map" do
|
23
|
+
it "should raise Argument error for more than one key=>value pair" do
|
24
|
+
lambda{Helper.map({:foo => :bar, :bizz => :bazz})}.
|
25
|
+
should raise_error(ArgumentError, "map only accepts one key=>value pair")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should add Map object to mappings" do
|
29
|
+
Helper.map :foo => :bar
|
30
|
+
Helper.mappings[:foo].class.should == Endeca::Map
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should add Map object to mappings with only one argument" do
|
34
|
+
Helper.map :foo
|
35
|
+
Helper.mappings[:foo].class.should == Endeca::Map
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should create a boolean mapping" do
|
39
|
+
Helper.map(:foo => :bar).should be_boolean
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".transform_query_options" do
|
44
|
+
it "should return new query based on transformation" do
|
45
|
+
Helper.map :foo => :bar
|
46
|
+
expected_query = {:bar => :bazz}
|
47
|
+
Helper.transform_query_options(:foo => :bazz).should == expected_query
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/endeca_spec.rb
ADDED
data/spec/rcov.opts
ADDED
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib endeca]))
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: primedia-endeca
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rein Henrichs
|
8
|
+
- Andy Stone
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-01-22 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bones
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.2.0
|
24
|
+
version:
|
25
|
+
description: An Endeca client library for Ruby.
|
26
|
+
email: ""
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
39
|
+
- example/benchmark.rb
|
40
|
+
- example/listing.rb
|
41
|
+
- lib/class_to_proc.rb
|
42
|
+
- lib/core_ext.rb
|
43
|
+
- lib/endeca.rb
|
44
|
+
- lib/endeca/dimension.rb
|
45
|
+
- lib/endeca/document.rb
|
46
|
+
- lib/endeca/document_collection.rb
|
47
|
+
- lib/endeca/map.rb
|
48
|
+
- lib/endeca/readers.rb
|
49
|
+
- lib/endeca/refinement.rb
|
50
|
+
- lib/endeca/request.rb
|
51
|
+
- lib/endeca/transformer.rb
|
52
|
+
- spec/core_ext_spec.rb
|
53
|
+
- spec/endeca/dimension_spec.rb
|
54
|
+
- spec/endeca/document_collection_spec.rb
|
55
|
+
- spec/endeca/document_spec.rb
|
56
|
+
- spec/endeca/map_spec.rb
|
57
|
+
- spec/endeca/readers_spec.rb
|
58
|
+
- spec/endeca/refinement_spec.rb
|
59
|
+
- spec/endeca/request_spec.rb
|
60
|
+
- spec/endeca/transformer_spec.rb
|
61
|
+
- spec/endeca_spec.rb
|
62
|
+
- spec/rcov.opts
|
63
|
+
- spec/spec.opts
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/primedia/endeca-ruby
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --main
|
70
|
+
- README.rdoc
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: endeca-ruby
|
88
|
+
rubygems_version: 1.2.0
|
89
|
+
signing_key:
|
90
|
+
specification_version: 2
|
91
|
+
summary: An Endeca client library for Ruby
|
92
|
+
test_files: []
|
93
|
+
|