sg_node_mapper 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/README.md +2 -0
- data/Rakefile +7 -0
- data/lib/sg_node_mapper.rb +15 -4
- data/lib/sg_node_mapper/caching.rb +15 -0
- data/lib/sg_node_mapper/version.rb +1 -1
- data/sg_node_mapper.gemspec +3 -0
- data/spec/sg_node_mapper/caching_spec.rb +28 -0
- data/spec/sg_node_mapper_spec.rb +16 -0
- metadata +74 -53
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# SgNodeMapper
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/hecticjeff/sg_node_mapper.png?branch=master)](http://travis-ci.org/hecticjeff/sg_node_mapper)
|
4
|
+
|
3
5
|
Lightweight ruby wrapper around the Social Graph Node Mapper [javascript
|
4
6
|
library](https://github.com/webjay/sgNodeMapper).
|
5
7
|
|
data/Rakefile
CHANGED
data/lib/sg_node_mapper.rb
CHANGED
@@ -7,6 +7,7 @@ require 'active_support/core_ext'
|
|
7
7
|
|
8
8
|
# Internal
|
9
9
|
require 'sg_node_mapper/version'
|
10
|
+
require 'sg_node_mapper/caching'
|
10
11
|
|
11
12
|
# Simple wrapper for the sgNodeMapper javascript library. Uses
|
12
13
|
# [ExecJS](https://github.com/sstephenson/execjs) to dynamically select the best
|
@@ -18,6 +19,9 @@ require 'sg_node_mapper/version'
|
|
18
19
|
# delegating to javascript.
|
19
20
|
class SgNodeMapper
|
20
21
|
include Singleton
|
22
|
+
include Caching
|
23
|
+
|
24
|
+
class Error < StandardError; end
|
21
25
|
|
22
26
|
# When a method is called on this class, we intercept it and pass it through
|
23
27
|
# to the javascript context by converting the method name from underscore_case
|
@@ -29,9 +33,17 @@ class SgNodeMapper
|
|
29
33
|
#
|
30
34
|
# Returns the result from javascript.
|
31
35
|
def self.method_missing(method, *args)
|
32
|
-
instance.
|
36
|
+
instance.send(method, *args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_missing(method, *args)
|
40
|
+
cache_and_return method, *args do
|
41
|
+
context.call("nodemapper.#{method.to_s.camelize(:lower)}", *args)
|
42
|
+
end
|
33
43
|
end
|
34
44
|
|
45
|
+
private
|
46
|
+
|
35
47
|
# Get a (potentially cached) version of the compiled source code for sgNodeMapper.
|
36
48
|
#
|
37
49
|
# Returns an ExecJS::ExternalRuntime::Context.
|
@@ -39,13 +51,12 @@ class SgNodeMapper
|
|
39
51
|
@context ||= ExecJS.compile(source)
|
40
52
|
end
|
41
53
|
|
42
|
-
private
|
43
54
|
|
44
|
-
# Get a
|
55
|
+
# Get a string of the sgNodeMapper source code.
|
45
56
|
#
|
46
57
|
# Returns the String javascript source code.
|
47
58
|
def source
|
48
|
-
|
59
|
+
File.read(source_path)
|
49
60
|
end
|
50
61
|
|
51
62
|
# Get the full path to the sgNodeMapper.js source code.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class SgNodeMapper
|
2
|
+
module Caching
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def cache_and_return(method, *args)
|
7
|
+
raise Error, 'You must call cache_and_return with a block' unless block_given?
|
8
|
+
cache[method][args] ||= yield
|
9
|
+
end
|
10
|
+
|
11
|
+
def cache
|
12
|
+
@cache ||= Hash.new { |h, k| h[k] = {} }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/sg_node_mapper.gemspec
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SgNodeMapper::Caching do
|
4
|
+
let(:js_context) { double }
|
5
|
+
before { SgNodeMapper.instance.stub(context: js_context) }
|
6
|
+
|
7
|
+
describe "cache miss" do
|
8
|
+
|
9
|
+
it "calls the javascript context" do
|
10
|
+
js_context.should_receive(:call).with('nodemapper.urlToGraphNode', 'miss').and_return('fresh')
|
11
|
+
SgNodeMapper.url_to_graph_node('miss')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "cache hit" do
|
16
|
+
before do
|
17
|
+
js_context.stub(call: 'cached')
|
18
|
+
|
19
|
+
# Prime the cache.
|
20
|
+
SgNodeMapper.url_to_graph_node('hit')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "doesn't call the javascript context" do
|
24
|
+
js_context.should_not_receive(:call)
|
25
|
+
SgNodeMapper.url_to_graph_node('hit').should == 'cached'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/sg_node_mapper_spec.rb
CHANGED
@@ -5,4 +5,20 @@ describe SgNodeMapper do
|
|
5
5
|
subject { SgNodeMapper.url_to_graph_node('http://twitter.com/google') }
|
6
6
|
it { should == 'sgn://twitter.com/?ident=google' }
|
7
7
|
end
|
8
|
+
|
9
|
+
describe ".parse_sgn_url('sgn://twitter.com/?ident=google')" do
|
10
|
+
subject { SgNodeMapper.parse_sgn_url('sgn://twitter.com/?ident=google') }
|
11
|
+
|
12
|
+
it "returns a hash" do
|
13
|
+
subject.should be_a_kind_of(Hash)
|
14
|
+
subject['domain'].should == 'twitter.com'
|
15
|
+
subject['keyName'].should == 'ident'
|
16
|
+
subject['value'].should == 'google'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".url_from_graph_node('sgn://twitter.com/?ident=google', 'profile')" do
|
21
|
+
subject { SgNodeMapper.url_from_graph_node('sgn://twitter.com/?ident=google', 'profile') }
|
22
|
+
it { should == 'http://twitter.com/google' }
|
23
|
+
end
|
8
24
|
end
|
metadata
CHANGED
@@ -1,48 +1,80 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sg_node_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Mytton
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
16
|
-
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
17
18
|
requirements:
|
18
19
|
- - ! '>='
|
19
20
|
- !ruby/object:Gem::Version
|
20
21
|
version: '1.4'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
25
|
none: false
|
22
|
-
requirement: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.4'
|
27
|
-
none: false
|
28
|
-
prerelease: false
|
29
|
-
type: :runtime
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activesupport
|
32
|
-
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
33
34
|
requirements:
|
34
35
|
- - ! '>='
|
35
36
|
- !ruby/object:Gem::Version
|
36
37
|
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
41
|
none: false
|
38
|
-
requirement: !ruby/object:Gem::Requirement
|
39
42
|
requirements:
|
40
43
|
- - ! '>='
|
41
44
|
- !ruby/object:Gem::Version
|
42
45
|
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.9'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
57
|
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.10'
|
70
|
+
type: :development
|
44
71
|
prerelease: false
|
45
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.10'
|
46
78
|
description: Map social networking sites' URLs to and from a canonical form.
|
47
79
|
email:
|
48
80
|
- self@hecticjeff.net
|
@@ -50,60 +82,49 @@ executables: []
|
|
50
82
|
extensions: []
|
51
83
|
extra_rdoc_files: []
|
52
84
|
files:
|
53
|
-
-
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
-
|
58
|
-
|
59
|
-
-
|
60
|
-
|
61
|
-
-
|
62
|
-
|
63
|
-
-
|
64
|
-
|
65
|
-
-
|
66
|
-
|
67
|
-
-
|
68
|
-
|
69
|
-
- !binary |-
|
70
|
-
c2dfbm9kZV9tYXBwZXIuZ2Vtc3BlYw==
|
71
|
-
- !binary |-
|
72
|
-
c3BlYy9zZ19ub2RlX21hcHBlcl9zcGVjLnJi
|
73
|
-
- !binary |-
|
74
|
-
c3BlYy9zcGVjX2hlbHBlci5yYg==
|
75
|
-
- !binary |-
|
76
|
-
dmVuZG9yL3NnX25vZGVfbWFwcGVyL0xJQ0VOU0U=
|
77
|
-
- !binary |-
|
78
|
-
dmVuZG9yL3NnX25vZGVfbWFwcGVyL25vZGVtYXBwZXIuanM=
|
85
|
+
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- .travis.yml
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- lib/sg_node_mapper.rb
|
93
|
+
- lib/sg_node_mapper/caching.rb
|
94
|
+
- lib/sg_node_mapper/version.rb
|
95
|
+
- sg_node_mapper.gemspec
|
96
|
+
- spec/sg_node_mapper/caching_spec.rb
|
97
|
+
- spec/sg_node_mapper_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- vendor/sg_node_mapper/LICENSE
|
100
|
+
- vendor/sg_node_mapper/nodemapper.js
|
79
101
|
homepage: https://github.com/hecticjeff/sg_node_mapper
|
80
102
|
licenses: []
|
81
|
-
post_install_message:
|
103
|
+
post_install_message:
|
82
104
|
rdoc_options: []
|
83
105
|
require_paths:
|
84
106
|
- lib
|
85
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
86
109
|
requirements:
|
87
110
|
- - ! '>='
|
88
111
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
90
|
-
MA==
|
91
|
-
none: false
|
112
|
+
version: '0'
|
92
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
93
115
|
requirements:
|
94
116
|
- - ! '>='
|
95
117
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
MA==
|
98
|
-
none: false
|
118
|
+
version: '0'
|
99
119
|
requirements: []
|
100
|
-
rubyforge_project:
|
101
|
-
rubygems_version: 1.8.
|
102
|
-
signing_key:
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.8.23
|
122
|
+
signing_key:
|
103
123
|
specification_version: 3
|
104
|
-
summary: The Social Graph Node Mapper is a community project to build a portable library
|
124
|
+
summary: The Social Graph Node Mapper is a community project to build a portable library
|
125
|
+
to map social networking sites' URLs to and from a canonical form (sgn:// URLs).
|
105
126
|
test_files:
|
106
|
-
-
|
107
|
-
|
108
|
-
-
|
109
|
-
|
127
|
+
- spec/sg_node_mapper/caching_spec.rb
|
128
|
+
- spec/sg_node_mapper_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
has_rdoc:
|