michael-ken 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ require 'pathname'
2
+
3
+ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
+
5
+ describe Ken do
6
+ before :all do
7
+ # Ken::Logger.new(STDOUT, :info)
8
+ Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
9
+ end
10
+
11
+ describe "Ken.get('/en/the_police')" do
12
+ it 'should return a Ken::Resource' do
13
+ the_police = Ken.get("/en/the_police")
14
+ the_police.should be_kind_of(Ken::Resource)
15
+ end
16
+ end
17
+
18
+ describe "Ken::Resource" do
19
+ before :all do
20
+ @the_police = Ken.get("/en/the_police")
21
+ end
22
+
23
+ it "should provide attributes" do
24
+ @the_police.attributes.should have_at_least(1).items
25
+ @the_police.attributes.first.should be_kind_of(Ken::Attribute)
26
+ end
27
+
28
+ it "should have views" do
29
+ @the_police.views.should have_at_least(1).items
30
+ @the_police.views.first.should be_kind_of(Ken::View)
31
+ @the_police.views.first.type.should be_kind_of(Ken::Type)
32
+ end
33
+ end
34
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,40 @@
1
1
  require 'pathname'
2
2
  require 'rubygems'
3
3
  require 'spec'
4
+ require 'json'
4
5
 
5
6
  SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
6
7
  require SPEC_ROOT.parent + 'lib/ken'
7
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 = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
32
+ def h(value)
33
+ value.to_s.gsub(/[&<>"]/) {|s| ESCAPE_TABLE[s] }
34
+ end
8
35
 
9
36
  Spec::Runner.configure do |config|
10
37
  config.after(:all) do
11
-
38
+
12
39
  end
13
40
  end
@@ -0,0 +1,50 @@
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
+
@@ -0,0 +1,30 @@
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
+
@@ -0,0 +1,63 @@
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
@@ -1,9 +1,7 @@
1
1
  require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
2
+ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
3
 
5
4
  describe Ken::Session do
6
-
7
5
  before :all do
8
6
  Ken::Logger.new(STDOUT, :info)
9
7
  Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,26 @@
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
+
11
+ @view = @the_police.views.first
12
+ end
13
+
14
+ it "should have a type" do
15
+ @view.type.should_not be_nil
16
+ end
17
+
18
+ it "should have properties" do
19
+ @view.properties.should_not be_nil
20
+ end
21
+
22
+ it "should have attributes" do
23
+ @view.properties.should_not be_nil
24
+ end
25
+ end
26
+
data/tasks/gemspec.rb ADDED
@@ -0,0 +1,23 @@
1
+ desc "Generate gemspec"
2
+ task :gemspec do |x|
3
+ # Clean up extraneous files before checking manifest
4
+ %x[rake clean]
5
+
6
+ # Check the manifest before generating the gemspec
7
+ manifest = %x[rake check_manifest]
8
+ manifest.gsub!("(in /usr/local/projects/dm/dm-core)\n", "")
9
+
10
+ unless manifest.empty?
11
+ print "\n", "#"*68, "\n"
12
+ print <<-EOS
13
+ Manifest.txt is not up-to-date. Please review the changes below.
14
+ If the changes are correct, run 'rake check_manifest | patch'
15
+ and then run this command again.
16
+ EOS
17
+ print "#"*68, "\n\n"
18
+ puts manifest
19
+ else
20
+ %x[rake debug_gem > #{GEM_NAME}.gemspec]
21
+ puts "Successfully created gemspec for #{GEM_NAME}!"
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: michael-ken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Aufreiter
@@ -35,31 +35,40 @@ extra_rdoc_files:
35
35
  - TODO
36
36
  - History.txt
37
37
  files:
38
- - .gitignore
39
38
  - History.txt
40
39
  - LICENSE
41
40
  - Manifest.txt
42
41
  - README.txt
42
+ - README.textile
43
43
  - Rakefile
44
44
  - TODO
45
- - ken.gemspec
45
+ - examples/artist.rb
46
46
  - lib/ken.rb
47
+ - lib/ken/attribute.rb
47
48
  - lib/ken/collection.rb
48
49
  - lib/ken/logger.rb
49
50
  - lib/ken/property.rb
50
51
  - lib/ken/resource.rb
51
52
  - lib/ken/session.rb
52
53
  - lib/ken/type.rb
54
+ - lib/ken/util.rb
53
55
  - lib/ken/version.rb
54
- - spec/mql_spec.rb
55
- - spec/property_spec.rb
56
- - spec/resource_spec.rb
57
- - spec/session_spec.rb
56
+ - lib/ken/view.rb
57
+ - spec/unit/attribute_spec.rb
58
+ - spec/unit/property_spec.rb
59
+ - spec/unit/resource_spec.rb
60
+ - spec/unit/session_spec.rb
61
+ - spec/unit/type_spec.rb
62
+ - spec/unit/view_spec.rb
63
+ - spec/integration/ken_spec.rb
64
+ - spec/fixtures/music_artist.json
65
+ - spec/fixtures/the_police.json
58
66
  - spec/spec.opts
59
67
  - spec/spec_helper.rb
60
68
  - tasks/hoe.rb
61
69
  - tasks/install.rb
62
70
  - tasks/spec.rb
71
+ - tasks/gemspec.rb
63
72
  has_rdoc: true
64
73
  homepage: http://github.com/michael/ken
65
74
  post_install_message:
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- *.log
2
- log/*
3
- pkg/*
4
- doc
5
- cov
6
- pkg
7
- .DS_Store
8
- coverage.html
9
- coverage/*
10
- *.db
11
- \#*
12
- _Yardoc
13
- .yardoc
14
- tmp/*
data/ken.gemspec DELETED
@@ -1,32 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = %q{ken}
3
- s.version = "0.0.1"
4
-
5
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
- s.authors = ["Michael Aufreiter"]
7
- s.date = %q{2009-02-10}
8
- s.description = %q{Ruby API for accessing Freebase}
9
- s.email = ["ma [a] zive [d] at"]
10
- s.extra_rdoc_files = ["README.txt", "LICENSE", "TODO", "History.txt"]
11
- s.files = [".gitignore", "History.txt", "LICENSE", "Manifest.txt", "README.txt", "Rakefile", "TODO", "ken.gemspec", "lib/ken.rb", "lib/ken/collection.rb", "lib/ken/logger.rb", "lib/ken/property.rb", "lib/ken/resource.rb", "lib/ken/session.rb", "lib/ken/type.rb", "lib/ken/version.rb", "spec/mql_spec.rb", "spec/property_spec.rb", "spec/resource_spec.rb", "spec/session_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/hoe.rb", "tasks/install.rb", "tasks/spec.rb"]
12
- s.has_rdoc = true
13
- s.homepage = %q{http://github.com/michael/ken}
14
- s.rdoc_options = ["--main", "README.txt"]
15
- s.require_paths = ["lib"]
16
- s.rubyforge_project = %q{ken}
17
- s.rubygems_version = %q{1.3.1}
18
- s.summary = %q{Ruby API for accessing Freebase}
19
-
20
- if s.respond_to? :specification_version then
21
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
- s.specification_version = 2
23
-
24
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
- s.add_runtime_dependency(%q<extlib>, [">= 0"])
26
- else
27
- s.add_dependency(%q<extlib>, [">= 0"])
28
- end
29
- else
30
- s.add_dependency(%q<extlib>, [">= 0"])
31
- end
32
- end
data/spec/mql_spec.rb DELETED
@@ -1,16 +0,0 @@
1
- require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
4
-
5
- describe Ken do
6
- before :all do
7
- # Ken::Logger.new(STDOUT, :info)
8
- Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
9
- end
10
-
11
- it 'should return a Ken::Resource' do
12
- the_police = Ken.get("/en/the_police")
13
- the_police.should be_kind_of(Ken::Resource)
14
- end
15
-
16
- end
File without changes
@@ -1,28 +0,0 @@
1
- require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
4
-
5
- describe Ken::Resource 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 resource
11
- @the_police = Ken.get("/en/the_police")
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 an id and a name' do
20
- @the_police.id.should be_kind_of(::String)
21
- @the_police.name.should be_kind_of(::String)
22
- end
23
-
24
- it 'should get known attributes' do
25
- # expected London
26
- @the_police.read_attribute('origin').should == "London"
27
- end
28
- end