michael-ken 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +70 -22
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/artist.rb +2 -2
- data/examples/artist_links.rb +28 -0
- data/ken.gemspec +82 -0
- data/lib/ken/attribute.rb +16 -7
- data/lib/ken/collection.rb +0 -8
- data/lib/ken/property.rb +5 -0
- data/lib/ken/resource.rb +17 -14
- data/lib/ken/session.rb +34 -11
- data/lib/ken/type.rb +17 -2
- data/lib/ken/view.rb +13 -0
- data/lib/ken.rb +4 -10
- data/rails/init.rb +2 -0
- data/tasks/ken.rb +4 -0
- data/tasks/spec.rb +1 -1
- data/{spec → test}/fixtures/music_artist.json +1 -0
- data/test/fixtures/the_police.json +940 -0
- data/{spec/integration/ken_spec.rb → test/integration/ken_test.rb} +33 -28
- data/test/test_helper.rb +51 -0
- data/test/unit/attribute_test.rb +48 -0
- data/test/unit/property_test.rb +27 -0
- data/test/unit/resource_test.rb +48 -0
- data/test/unit/session_test.rb +27 -0
- data/test/unit/type_test.rb +35 -0
- data/test/unit/view_test.rb +48 -0
- metadata +38 -26
- data/lib/ken/version.rb +0 -3
- data/spec/fixtures/the_police.json +0 -891
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -40
- data/spec/unit/attribute_spec.rb +0 -50
- data/spec/unit/property_spec.rb +0 -30
- data/spec/unit/resource_spec.rb +0 -63
- data/spec/unit/session_spec.rb +0 -18
- data/spec/unit/type_spec.rb +0 -21
- data/spec/unit/view_spec.rb +0 -28
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require 'rubygems'
|
3
|
-
require 'spec'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
|
7
|
-
require SPEC_ROOT.parent + 'lib/ken'
|
8
|
-
|
9
|
-
def load_fixture(fixture_name)
|
10
|
-
fname = "#{File.dirname(__FILE__)}/fixtures/#{fixture_name}.json"
|
11
|
-
unless File.exists?(fname)
|
12
|
-
open(fname, "w") do |file|
|
13
|
-
puts "WARNING: Fixtures could not be loaded."
|
14
|
-
end
|
15
|
-
end
|
16
|
-
JSON.parse open(fname,"r").read
|
17
|
-
end
|
18
|
-
|
19
|
-
# this will append a <br /> to every logged message, which produces
|
20
|
-
# nicely formatted DataMapper debug outputs in Textmate's RSpec Bundle's output
|
21
|
-
module Ken
|
22
|
-
class Logger
|
23
|
-
def prep_msg(message, level)
|
24
|
-
level << delimiter << message << "<br/>"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# debugging helper (textmate rspec bundle)
|
30
|
-
# TODO remove before release
|
31
|
-
ESCAPE_TABLE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
|
32
|
-
def h(value)
|
33
|
-
value.to_s.gsub(/[&<>"]/) {|s| ESCAPE_TABLE[s] }
|
34
|
-
end
|
35
|
-
|
36
|
-
Spec::Runner.configure do |config|
|
37
|
-
config.after(:all) do
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
data/spec/unit/attribute_spec.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe Ken::Attribute do
|
6
|
-
before :all do
|
7
|
-
Ken::Logger.new(STDOUT, :info)
|
8
|
-
Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
|
9
|
-
data = load_fixture('the_police')
|
10
|
-
@the_police = Ken::Resource.new(data)
|
11
|
-
|
12
|
-
@attribute = @unique_value_attribute = @the_police.attributes[2] # /music/artist/active_start
|
13
|
-
@unique_object_attribute = @the_police.attributes[11] # /music/artist/origin
|
14
|
-
@non_unique_value_attribute = @the_police.attributes[8] # /common/topic/alias
|
15
|
-
@non_unique_object_attribute = @the_police.attributes[4] # /music/artist/album
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should have values" do
|
19
|
-
@attribute.values.should_not be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "with unique value type" do
|
23
|
-
it "should be unique and no object_type" do
|
24
|
-
@unique_value_attribute.unique?.should == true
|
25
|
-
@unique_value_attribute.object_type?.should == false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "with unique object type" do
|
30
|
-
it "be unique and an object type" do
|
31
|
-
@unique_object_attribute.unique?.should == true
|
32
|
-
@unique_object_attribute.object_type?.should == true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "with non-unique value type" do
|
37
|
-
it "be unique and an object type" do
|
38
|
-
@non_unique_value_attribute.unique?.should == false
|
39
|
-
@non_unique_value_attribute.object_type?.should == false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "with non-unique object type" do
|
44
|
-
it "be unique and an object type" do
|
45
|
-
@non_unique_object_attribute.unique?.should == false
|
46
|
-
@non_unique_object_attribute.object_type?.should == true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
data/spec/unit/property_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe Ken::Property do
|
6
|
-
before :all do
|
7
|
-
Ken::Logger.new(STDOUT, :info)
|
8
|
-
# Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
|
9
|
-
data = load_fixture('music_artist')
|
10
|
-
@type = Ken::Type.new(data)
|
11
|
-
@value_property = @type.properties[1]
|
12
|
-
@object_property = @type.properties[3]
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should be a valid property instance' do
|
16
|
-
@value_property.should be_kind_of(Ken::Property)
|
17
|
-
@object_property.should be_kind_of(Ken::Property)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should have a type' do
|
21
|
-
@value_property.type.should be_kind_of(Ken::Type)
|
22
|
-
@object_property.type.should be_kind_of(Ken::Type)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should distinguish wheter it is an object or value type' do
|
26
|
-
@value_property.object_type?.should == false
|
27
|
-
@object_property.object_type?.should == true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
data/spec/unit/resource_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe Ken::Resource do
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
# Ken::Logger.new(STDOUT, :info)
|
9
|
-
# Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
|
10
|
-
data = load_fixture('the_police')
|
11
|
-
@the_police = Ken::Resource.new(data)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should have types' do
|
15
|
-
@the_police.types.should have_at_least(1).items
|
16
|
-
@the_police.types.first.should be_kind_of(Ken::Type)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should have views' do
|
20
|
-
@the_police.views.should have(6).items
|
21
|
-
@the_police.views.first.should be_kind_of(Ken::View)
|
22
|
-
@the_police.views.first.type.should be_kind_of(Ken::Type)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should have an id and a name' do
|
26
|
-
@the_police.id.should be_kind_of(::String)
|
27
|
-
@the_police.name.should be_kind_of(::String)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should have attributes' do
|
31
|
-
@the_police.attributes.should_not be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should deal with non-unique value type attributes' do
|
35
|
-
pending
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should deal with unique object type attributes' do
|
39
|
-
pending
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should deal with non-unique object type attributes' do
|
43
|
-
pending
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should load attributes only on demand' do
|
47
|
-
@the_police.attributes_loaded?.should == false
|
48
|
-
@the_police.attributes
|
49
|
-
@the_police.attributes_loaded?.should == true
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should load schema only on demand when calling types' do
|
53
|
-
@the_police.schema_loaded?.should == false
|
54
|
-
@the_police.types
|
55
|
-
@the_police.schema_loaded?.should == true
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should load schema only on demand when calling views' do
|
59
|
-
@the_police.schema_loaded?.should == false
|
60
|
-
@the_police.views
|
61
|
-
@the_police.schema_loaded?.should == true
|
62
|
-
end
|
63
|
-
end
|
data/spec/unit/session_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
|
-
|
4
|
-
describe Ken::Session do
|
5
|
-
before :all do
|
6
|
-
Ken::Logger.new(STDOUT, :info)
|
7
|
-
Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should return the types of the_police' do
|
11
|
-
result = Ken.session.mqlread({:id => "/en/the_police", :type => []})
|
12
|
-
result['type'].length.should == 6
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should raise an Ken::MqlReadError if node does not exist' do
|
16
|
-
lambda { Ken.session.mqlread({:id => "/en/the_police", :evil_property => []}) }.should raise_error(Ken::ReadError)
|
17
|
-
end
|
18
|
-
end
|
data/spec/unit/type_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe Ken::Type do
|
6
|
-
before :all do
|
7
|
-
Ken::Logger.new(STDOUT, :info)
|
8
|
-
Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
|
9
|
-
|
10
|
-
# fetch a type
|
11
|
-
@type = Ken.get("/en/the_police").types.first
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should have an id and a name' do
|
15
|
-
puts @type.id
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should have properties' do
|
19
|
-
@type.properties.should have_at_least(1).items
|
20
|
-
end
|
21
|
-
end
|
data/spec/unit/view_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
4
|
-
|
5
|
-
describe Ken::View do
|
6
|
-
before :all do
|
7
|
-
Ken::Logger.new(STDOUT, :info)
|
8
|
-
data = load_fixture('the_police')
|
9
|
-
@the_police = Ken::Resource.new(data)
|
10
|
-
@view = @the_police.views.first
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should have a type" do
|
14
|
-
@view.type.should_not be_nil
|
15
|
-
@view.type.should be_kind_of(Ken::Type)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should have properties" do
|
19
|
-
@view.properties.should_not be_nil
|
20
|
-
@view.properties.each { |p| p.should be_kind_of(Ken::Property)}
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should have attributes" do
|
24
|
-
@view.attributes.should_not be_nil
|
25
|
-
@view.attributes.each { |p| p.should be_kind_of(Ken::Attribute)}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|