js-client-bridge 0.1.0 → 0.1.1
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/Gemfile +4 -0
- data/Gemfile.lock +47 -0
- data/{README.txt → README.rdoc} +0 -0
- data/Rakefile +4 -74
- data/js-client-bridge.gemspec +34 -0
- data/lib/js-client-bridge.rb +7 -9
- data/lib/js-client-bridge/responses.rb +2 -7
- data/lib/js-client-bridge/responses/error.rb +2 -2
- data/lib/js-client-bridge/responses/exception.rb +2 -2
- data/lib/js-client-bridge/responses/ok.rb +2 -2
- data/lib/js-client-bridge/responses/validation.rb +24 -19
- data/lib/js-client-bridge/version.rb +3 -0
- data/spec/error_responses_spec.rb +9 -6
- data/spec/exception_responses_spec.rb +6 -6
- data/spec/ok_responses_spec.rb +24 -20
- data/spec/rcov.opts +6 -0
- data/spec/spec_helper.rb +7 -8
- data/spec/validation_responses_spec.rb +8 -8
- data/tasks/rspec.rake +30 -15
- metadata +97 -48
- data/History.txt +0 -3
- data/Manifest.txt +0 -21
- data/lib/js-client-bridge/extensions/datamapper_errors.rb +0 -43
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
js-client-bridge (0.1.0)
|
5
|
+
json (~> 1.4.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.2.1)
|
11
|
+
archive-tar-minitar (0.5.2)
|
12
|
+
columnize (0.3.1)
|
13
|
+
dm-core (1.0.2)
|
14
|
+
addressable (~> 2.2)
|
15
|
+
extlib (~> 0.9.15)
|
16
|
+
extlib (0.9.15)
|
17
|
+
json (1.4.6)
|
18
|
+
linecache19 (0.5.11)
|
19
|
+
ruby_core_source (>= 0.1.4)
|
20
|
+
mocha (0.9.8)
|
21
|
+
rake
|
22
|
+
rake (0.8.7)
|
23
|
+
rcov (0.9.9)
|
24
|
+
rspec (1.3.0)
|
25
|
+
ruby-debug-base19 (0.11.24)
|
26
|
+
columnize (>= 0.3.1)
|
27
|
+
linecache19 (>= 0.5.11)
|
28
|
+
ruby_core_source (>= 0.1.4)
|
29
|
+
ruby-debug19 (0.11.6)
|
30
|
+
columnize (>= 0.3.1)
|
31
|
+
linecache19 (>= 0.5.11)
|
32
|
+
ruby-debug-base19 (>= 0.11.19)
|
33
|
+
ruby_core_source (0.1.4)
|
34
|
+
archive-tar-minitar (>= 0.5.2)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (>= 1.0.0)
|
41
|
+
dm-core (~> 1.0.2)
|
42
|
+
js-client-bridge!
|
43
|
+
json (~> 1.4.6)
|
44
|
+
mocha (~> 0.9.8)
|
45
|
+
rcov (~> 0.9.8)
|
46
|
+
rspec (~> 1.3.0)
|
47
|
+
ruby-debug19 (~> 0.11.6)
|
data/{README.txt → README.rdoc}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,74 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# Generate all the Rake tasks
|
6
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
7
|
-
$hoe = Hoe.new('js-client-bridge', JsClientBridge::VERSION) do |p|
|
8
|
-
p.developer('Rolly', 'rolly@luma.co.nz')
|
9
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
|
-
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
11
|
-
p.rubyforge_name = p.name # TODO this is default value
|
12
|
-
p.extra_deps = [
|
13
|
-
# ['activesupport','>= 2.0.2'],
|
14
|
-
['json', '>= 0'],
|
15
|
-
['extlib', '>= 0']
|
16
|
-
]
|
17
|
-
p.extra_dev_deps = [
|
18
|
-
['newgem', ">= #{::Newgem::VERSION}"]
|
19
|
-
]
|
20
|
-
|
21
|
-
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
22
|
-
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
23
|
-
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
24
|
-
p.rsync_args = '-av --delete --ignore-errors'
|
25
|
-
end
|
26
|
-
|
27
|
-
require 'newgem/tasks' # load /tasks/*.rake
|
28
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
29
|
-
|
30
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
31
|
-
# task :default => [:spec, :features]
|
32
|
-
|
33
|
-
desc "Run all examples (or a specific spec with TASK=xxxx)"
|
34
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
35
|
-
t.spec_opts = ["-cfs"]
|
36
|
-
t.spec_files = begin
|
37
|
-
if ENV["TASK"]
|
38
|
-
ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
|
39
|
-
else
|
40
|
-
FileList['spec/**/*_spec.rb']
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
#desc 'Default: run spec examples'
|
46
|
-
#task :default => 'spec'
|
47
|
-
=end
|
48
|
-
# -*- ruby -*-
|
49
|
-
|
50
|
-
require 'rubygems'
|
51
|
-
require 'hoe'
|
52
|
-
require 'fileutils'
|
53
|
-
require 'newgem'
|
54
|
-
require 'rubigen'
|
55
|
-
|
56
|
-
#require File.dirname(__FILE__) + '/lib/js-client-bridge'
|
57
|
-
|
58
|
-
Hoe.spec 'js-client-bridge' do
|
59
|
-
developer 'Rolly', 'rolly@luma.co.nz'
|
60
|
-
|
61
|
-
extra_deps << ['json', '>= 0']
|
62
|
-
extra_deps << ['extlib', '>= 0']
|
63
|
-
|
64
|
-
# extra_dev_deps << ['newgem', ">= #{::Newgem::VERSION}"]
|
65
|
-
=begin
|
66
|
-
clean_globs |= %w[**/.DS_Store tmp *.log]
|
67
|
-
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
68
|
-
remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
69
|
-
rsync_args = '-av --delete --ignore-errors'
|
70
|
-
=end
|
71
|
-
end
|
72
|
-
|
73
|
-
# vim: syntax=ruby
|
74
|
-
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/js-client-bridge/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "js-client-bridge"
|
6
|
+
s.version = JsClientBridge::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Rolly Fordham']
|
9
|
+
s.email = ['rolly@luma.co.nz']
|
10
|
+
s.homepage = "http://rubygems.org/gems/js-client-bridge"
|
11
|
+
s.summary = "Standardised way of talking between a service and javascript"
|
12
|
+
s.description = "Little library that encapsulates a (particular) standardised way of talking between a service and javascript. Probably not the best way of doing things, but it's been handy in a pinch."
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "js-client-bridge"
|
16
|
+
|
17
|
+
s.add_dependency "json", "~> 1.4.6"
|
18
|
+
|
19
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
20
|
+
s.add_development_dependency "rspec", "~> 1.3.0"
|
21
|
+
s.add_development_dependency "rcov", "~> 0.9.8"
|
22
|
+
s.add_development_dependency "mocha", "~> 0.9.8"
|
23
|
+
s.add_development_dependency "dm-core", "~> 1.0.2"
|
24
|
+
|
25
|
+
if RUBY_VERSION > '1.9.0'
|
26
|
+
s.add_development_dependency "ruby-debug19", "~> 0.11.6"
|
27
|
+
else
|
28
|
+
s.add_development_dependency "ruby-debug", "~> 0.10.3"
|
29
|
+
end
|
30
|
+
|
31
|
+
s.files = `git ls-files`.split("\n")
|
32
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
33
|
+
s.require_path = 'lib'
|
34
|
+
end
|
data/lib/js-client-bridge.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'json'
|
2
|
+
require 'cgi'
|
3
|
+
|
3
4
|
|
4
5
|
module JsClientBridge
|
5
|
-
VERSION = '0.1.0'
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
require
|
10
|
-
require "extlib"
|
11
|
-
require 'hoe'
|
8
|
+
dir = File.join(Pathname(__FILE__).dirname.expand_path, 'js-client-bridge', 'responses/')
|
9
|
+
%w(ok error exception validation).each {|f| require dir + f }
|
12
10
|
|
13
|
-
|
14
|
-
require '
|
11
|
+
dir = File.join(Pathname(__FILE__).dirname.expand_path + 'js-client-bridge/')
|
12
|
+
require dir + 'responses'
|
@@ -1,9 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
base = File.dirname(__FILE__) / 'responses'
|
4
|
-
%w(ok error exception validation).each {|f| require base / f }
|
5
|
-
|
6
|
-
module JSClientBridge #:nodoc:
|
1
|
+
module JsClientBridge #:nodoc:
|
7
2
|
module Responses
|
8
3
|
class << self
|
9
4
|
include Responses::Ok
|
@@ -44,4 +39,4 @@ module JSClientBridge #:nodoc:
|
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end # module Responses
|
47
|
-
end # module
|
42
|
+
end # module JsClientBridge
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
|
3
|
-
module
|
3
|
+
module JsClientBridge #:nodoc:
|
4
4
|
module Responses #:nodoc:
|
5
5
|
module Error
|
6
6
|
# Generates a error response. If the first parameter is a string is will be
|
@@ -19,4 +19,4 @@ module JSClientBridge #:nodoc:
|
|
19
19
|
|
20
20
|
end # module Error
|
21
21
|
end # module Responses
|
22
|
-
end # module
|
22
|
+
end # module JsClientBridge
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
|
3
|
-
module
|
3
|
+
module JsClientBridge #:nodoc:
|
4
4
|
module Responses #:nodoc:
|
5
5
|
module Exception
|
6
6
|
|
@@ -57,4 +57,4 @@ module JSClientBridge #:nodoc:
|
|
57
57
|
|
58
58
|
end # module Exception
|
59
59
|
end # module Responses
|
60
|
-
end # module
|
60
|
+
end # module JsClientBridge
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
|
3
|
-
module
|
3
|
+
module JsClientBridge #:nodoc:
|
4
4
|
module Responses #:nodoc:
|
5
5
|
module Ok
|
6
6
|
# Generates a 'ok' status response. If the first parameter is a string is will be
|
@@ -18,4 +18,4 @@ module JSClientBridge #:nodoc:
|
|
18
18
|
end
|
19
19
|
end # module Ok
|
20
20
|
end # module Responses
|
21
|
-
end # module
|
21
|
+
end # module JsClientBridge
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
|
3
|
-
module
|
3
|
+
module JsClientBridge #:nodoc:
|
4
4
|
module Responses #:nodoc:
|
5
5
|
module Validation
|
6
|
-
# Generates a
|
6
|
+
# Generates a validation error status response. If the first parameter is a string is will be
|
7
7
|
# used as the _status options. It will also honour custom optionss as long
|
8
8
|
# they don't clash with the standard ones.
|
9
9
|
#
|
@@ -14,34 +14,39 @@ module JSClientBridge #:nodoc:
|
|
14
14
|
# ==== Returns
|
15
15
|
# JSON String::
|
16
16
|
def respond_with_validation_error(*args)
|
17
|
-
if args.blank? || !args.first.respond_to?(:errors_to_hash)
|
18
|
-
raise ArgumentError.new("respond_with_validation_error requires an object that responds to errors_to_hash as it's first parameter")
|
19
|
-
end
|
20
|
-
|
21
17
|
obj = args.shift
|
22
18
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
23
19
|
|
24
20
|
# Generate our response hash and add the exceptions parameter
|
25
21
|
response = if options.include?(:message)
|
26
|
-
options.merge(obj
|
22
|
+
options.merge( validation_errors_to_hash(obj, options.delete(:message)) )
|
27
23
|
|
28
24
|
else
|
29
|
-
options.merge(obj
|
25
|
+
options.merge( validation_errors_to_hash(obj) )
|
30
26
|
end
|
31
27
|
|
32
28
|
format_response(response, options)
|
33
29
|
end
|
34
30
|
|
31
|
+
protected
|
32
|
+
|
33
|
+
def validation_errors_to_hash(data_object, message = "Sorry, we couldn't save your #{data_object.class.to_s.split('::').last}")
|
34
|
+
short_type = data_object.class.to_s.split('::').last
|
35
|
+
|
36
|
+
validation = {
|
37
|
+
:_status => 'validation',
|
38
|
+
:_type => data_object.class,
|
39
|
+
:_short_type => short_type,
|
40
|
+
:_message => message,
|
41
|
+
:validation => data_object.errors.to_hash,
|
42
|
+
}
|
43
|
+
|
44
|
+
validation[:id] = data_object.id.to_s unless data_object.new_record?
|
45
|
+
|
46
|
+
validation
|
47
|
+
end
|
48
|
+
|
49
|
+
|
35
50
|
end # module Validation
|
36
51
|
end # module Responses
|
37
|
-
end # module
|
38
|
-
|
39
|
-
=begin
|
40
|
-
{
|
41
|
-
:_status => 'validation',
|
42
|
-
:_type => self.class,
|
43
|
-
:_short_type => self.class.to_s.split('::').first,
|
44
|
-
:_message => message,
|
45
|
-
:validation => self.errors.to_json
|
46
|
-
}
|
47
|
-
=end
|
52
|
+
end # module JsClientBridge
|
@@ -1,23 +1,26 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
describe "Error Responses" do
|
4
4
|
it "should generate a basic error response" do
|
5
|
-
|
5
|
+
JSON.parse(JsClientBridge::Responses.respond_with_error).should == {'_status' => 'error'}
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should generate a error response with a status message" do
|
9
|
-
|
9
|
+
JSON.parse(JsClientBridge::Responses.respond_with_error('a message')).should == {'_status' => 'error', '_message' => "a message"}
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should generate a error response with a status message and additional custom properties" do
|
13
|
-
|
13
|
+
JSON.parse(JsClientBridge::Responses.respond_with_error('a message', 'blame' => 'the user')).should == {'_status' => 'error', '_message' => "a message", 'blame' => 'the user'}
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should generate a error response with custom properties but not message" do
|
17
|
-
|
17
|
+
JSON.parse(JsClientBridge::Responses.respond_with_error('blame' => 'the user')).should == {'_status' => 'error', 'blame' => 'the user'}
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should generate a basic error response using JSONP" do
|
21
|
-
|
21
|
+
jsonp = JsClientBridge::Responses.respond_with_error('a message', :jsonp => 'jsonp1')
|
22
|
+
jsonp[0..6].should == 'jsonp1('
|
23
|
+
jsonp[-1..-1].should == ')'
|
24
|
+
JSON.parse(jsonp[7..-2]).should == {'_message' => "a message", '_status' => 'error'}
|
22
25
|
end
|
23
26
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
|
4
4
|
|
@@ -9,7 +9,7 @@ describe "Exception Responses" do
|
|
9
9
|
it "should generate an exception response" do
|
10
10
|
exception = TestException.new('An exception')
|
11
11
|
|
12
|
-
ex = JSON.parse(
|
12
|
+
ex = JSON.parse(JsClientBridge::Responses.respond_with_exception(exception, :request_uri => '/', :parameters => {:param1 => 'value1'}))
|
13
13
|
|
14
14
|
ex['_status'].should == 'exception'
|
15
15
|
ex['request_uri'].should == '/'
|
@@ -26,7 +26,7 @@ describe "Exception Responses" do
|
|
26
26
|
it "should generate an exceptions response" do
|
27
27
|
exceptions = [TestException.new('An exception'), TestException.new('Another exception')]
|
28
28
|
|
29
|
-
ex = JSON.parse(
|
29
|
+
ex = JSON.parse(JsClientBridge::Responses.respond_with_exceptions(exceptions, :request_uri => '/', :parameters => {:param1 => 'value1'}))
|
30
30
|
|
31
31
|
ex['_status'].should == 'exception'
|
32
32
|
ex['request_uri'].should == '/'
|
@@ -36,20 +36,20 @@ describe "Exception Responses" do
|
|
36
36
|
|
37
37
|
it "should require the request_uri option" do
|
38
38
|
lambda {
|
39
|
-
|
39
|
+
JsClientBridge::Responses.respond_with_exception(TestException.new('An exception'), :parameters => {:param1 => 'value1'})
|
40
40
|
}.should raise_error(ArgumentError)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should require the exception option" do
|
44
44
|
lambda {
|
45
|
-
|
45
|
+
JsClientBridge::Responses.respond_with_exception(:request_uri => '/', :parameters => {:param1 => 'value1'})
|
46
46
|
}.should raise_error(ArgumentError)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should generate an exception response using JSONP" do
|
50
50
|
exception = TestException.new('An exception')
|
51
51
|
|
52
|
-
ex =
|
52
|
+
ex = JsClientBridge::Responses.respond_with_exception(exception, :request_uri => '/', :parameters => {:param1 => 'value1'}, :jsonp => 'jsonp1')
|
53
53
|
ex[0..6].should == 'jsonp1('
|
54
54
|
ex[-1..-1].should == ')'
|
55
55
|
end
|
data/spec/ok_responses_spec.rb
CHANGED
@@ -1,46 +1,50 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
|
4
4
|
|
5
5
|
|
6
6
|
describe "Ok Responses" do
|
7
7
|
it "should generate a basic ok response" do
|
8
|
-
|
8
|
+
JSON.parse(JsClientBridge::Responses.respond_with_ok).should == {'_status' => 'ok'}
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should generate a ok response with a status message" do
|
12
|
-
|
12
|
+
JSON.parse(JsClientBridge::Responses.respond_with_ok('a message')).should == {'_status' => 'ok', '_message' => "a message"}
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should generate a ok response with a status message and additional custom parameters" do
|
16
|
-
|
16
|
+
JSON.parse(JsClientBridge::Responses.respond_with_ok('a message', 'awesomeness' => 'has happened')).should == {'_status' => 'ok', '_message' => "a message", 'awesomeness' => 'has happened'}
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should generate a ok response with a status message and a complex parameters" do
|
20
|
-
|
20
|
+
JSON.parse(JsClientBridge::Responses.respond_with_ok('a message', 'stuff' => complext_test_data)).should == {'_message' => "a message", 'stuff' => complext_test_data, '_status' => 'ok'}
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should generate a basic ok response using JSONP" do
|
24
|
-
|
24
|
+
jsonp = JsClientBridge::Responses.respond_with_ok('a message', :jsonp => 'jsonp1')
|
25
|
+
jsonp[0..6].should == 'jsonp1('
|
26
|
+
jsonp[-1..-1].should == ')'
|
27
|
+
JSON.parse(jsonp[7..-2]).should == {'_status' => 'ok', '_message' => "a message"}
|
25
28
|
end
|
26
29
|
|
27
30
|
def complext_test_data
|
28
31
|
[
|
29
|
-
{
|
30
|
-
|
31
|
-
|
32
|
-
{
|
33
|
-
{
|
34
|
-
|
35
|
-
|
36
|
-
{
|
37
|
-
{
|
38
|
-
|
39
|
-
|
40
|
-
{
|
41
|
-
|
42
|
-
|
32
|
+
{'name'=>"Whangarei",
|
33
|
+
'description'=>"Northland Coach & Travel Centre, 3C Bank St.",
|
34
|
+
'id'=>'WRE'},
|
35
|
+
{'name'=>"Westwood Lodge", 'description'=>"Westwood Lodge", 'id'=>'WWL'},
|
36
|
+
{'name'=>"Queenstown YHA Lake Esplanade",
|
37
|
+
'description'=>"Queenstown YHA, 80 Lake Esplanade",
|
38
|
+
'id'=>'YHQ'},
|
39
|
+
{'name'=>"Queenstown Airport", 'description'=>"Queenstown Airport", 'id'=>'ZQA'},
|
40
|
+
{'name'=>"Queenstown",
|
41
|
+
'description'=>"Athol Street in the middle of the car park",
|
42
|
+
'id'=>'ZQN'},
|
43
|
+
{'name'=>"Queenstown The Station",
|
44
|
+
'description'=>"The Station, corner of Camp and Shotover Streets",
|
45
|
+
'id'=>'ZQT'}
|
43
46
|
]
|
44
47
|
end
|
48
|
+
|
45
49
|
end
|
46
50
|
|
data/spec/rcov.opts
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
gem 'rspec'
|
6
|
-
require 'spec'
|
7
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'ruby-debug'
|
4
|
+
require 'pp'
|
8
5
|
|
9
6
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
10
7
|
require 'js-client-bridge'
|
11
8
|
|
12
|
-
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
config.mock_with :mocha
|
11
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
2
2
|
|
3
3
|
require 'dm-core'
|
4
4
|
require 'dm-aggregates'
|
@@ -14,8 +14,8 @@ module Luma
|
|
14
14
|
|
15
15
|
property :id, String, :key => true, :length => 36
|
16
16
|
|
17
|
-
property :subject, String, :length => 30..155, :
|
18
|
-
property :body, Text, :
|
17
|
+
property :subject, String, :length => 30..155, :required => true
|
18
|
+
property :body, Text, :required => true
|
19
19
|
end # class Message
|
20
20
|
end
|
21
21
|
end
|
@@ -27,21 +27,21 @@ describe "Validation Responses" do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should generate a basic validation response" do
|
30
|
-
test_do = Luma::Test::TestDO.new
|
30
|
+
test_do = Luma::Test::TestDO.new(:id => 'bob')
|
31
31
|
test_do.save.should be_false
|
32
32
|
|
33
|
-
ex = JSON.parse(
|
33
|
+
ex = JSON.parse(JsClientBridge::Responses.respond_with_validation_error(test_do))
|
34
34
|
pp ex
|
35
|
-
ex['validation'].length.should ==
|
35
|
+
ex['validation'].length.should == 2
|
36
36
|
ex['_short_type'].should == "TestDO"
|
37
37
|
ex['_type'].should == "Luma::Test::TestDO"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should generate a basic validation response using JSONP" do
|
41
|
-
test_do = Luma::Test::TestDO.new
|
41
|
+
test_do = Luma::Test::TestDO.new(:id => 'bob')
|
42
42
|
test_do.save.should be_false
|
43
43
|
|
44
|
-
ex =
|
44
|
+
ex = JsClientBridge::Responses.respond_with_validation_error(test_do, :jsonp => 'jsonp1')
|
45
45
|
ex[0..6].should == 'jsonp1('
|
46
46
|
ex[-1..-1].should == ')'
|
47
47
|
end
|
data/tasks/rspec.rake
CHANGED
@@ -1,21 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require 'spec'
|
1
|
+
spec_defaults = lambda do |spec|
|
2
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
3
|
+
spec.libs << 'lib' << 'spec'
|
4
|
+
spec.spec_opts << '--options' << 'spec/spec.opts'
|
6
5
|
end
|
6
|
+
|
7
7
|
begin
|
8
8
|
require 'spec/rake/spectask'
|
9
|
+
|
10
|
+
Spec::Rake::SpecTask.new(:spec, &spec_defaults)
|
9
11
|
rescue LoadError
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
EOS
|
14
|
-
exit(0)
|
12
|
+
task :spec do
|
13
|
+
abort 'rspec is not available. In order to run spec, you must: gem install rspec'
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
begin
|
18
|
+
require 'rcov'
|
19
|
+
require 'spec/rake/verify_rcov'
|
20
|
+
|
21
|
+
Spec::Rake::SpecTask.new(:rcov) do |rcov|
|
22
|
+
spec_defaults.call(rcov)
|
23
|
+
rcov.rcov = true
|
24
|
+
rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
|
25
|
+
end
|
26
|
+
|
27
|
+
RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
|
28
|
+
rcov.threshold = 100
|
29
|
+
end
|
30
|
+
rescue LoadError
|
31
|
+
%w[ rcov verify_rcov ].each do |name|
|
32
|
+
task name do
|
33
|
+
abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,88 +1,135 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js-client-bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
|
-
- Rolly
|
13
|
+
- Rolly Fordham
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-09-17 00:00:00 +12:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: json
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
|
-
- -
|
27
|
+
- - ~>
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 11
|
27
30
|
segments:
|
28
|
-
-
|
29
|
-
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 6
|
34
|
+
version: 1.4.6
|
30
35
|
type: :runtime
|
31
36
|
version_requirements: *id001
|
32
37
|
- !ruby/object:Gem::Dependency
|
33
|
-
name:
|
38
|
+
name: bundler
|
34
39
|
prerelease: false
|
35
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
36
42
|
requirements:
|
37
43
|
- - ">="
|
38
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
39
46
|
segments:
|
47
|
+
- 1
|
40
48
|
- 0
|
41
|
-
|
42
|
-
|
49
|
+
- 0
|
50
|
+
version: 1.0.0
|
51
|
+
type: :development
|
43
52
|
version_requirements: *id002
|
44
53
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
54
|
+
name: rspec
|
46
55
|
prerelease: false
|
47
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
48
58
|
requirements:
|
49
|
-
- -
|
59
|
+
- - ~>
|
50
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 27
|
51
62
|
segments:
|
52
|
-
-
|
63
|
+
- 1
|
64
|
+
- 3
|
53
65
|
- 0
|
54
|
-
|
55
|
-
version: 2.0.4
|
66
|
+
version: 1.3.0
|
56
67
|
type: :development
|
57
68
|
version_requirements: *id003
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
70
|
+
name: rcov
|
60
71
|
prerelease: false
|
61
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
62
74
|
requirements:
|
63
|
-
- -
|
75
|
+
- - ~>
|
64
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 43
|
65
78
|
segments:
|
66
79
|
- 0
|
67
|
-
-
|
68
|
-
-
|
69
|
-
version: 0.
|
80
|
+
- 9
|
81
|
+
- 8
|
82
|
+
version: 0.9.8
|
70
83
|
type: :development
|
71
84
|
version_requirements: *id004
|
72
85
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
86
|
+
name: mocha
|
74
87
|
prerelease: false
|
75
88
|
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
76
90
|
requirements:
|
77
|
-
- -
|
91
|
+
- - ~>
|
78
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 43
|
79
94
|
segments:
|
80
|
-
- 2
|
81
|
-
- 5
|
82
95
|
- 0
|
83
|
-
|
96
|
+
- 9
|
97
|
+
- 8
|
98
|
+
version: 0.9.8
|
84
99
|
type: :development
|
85
100
|
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: dm-core
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 19
|
110
|
+
segments:
|
111
|
+
- 1
|
112
|
+
- 0
|
113
|
+
- 2
|
114
|
+
version: 1.0.2
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id006
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: ruby-debug
|
119
|
+
prerelease: false
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 49
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
- 10
|
129
|
+
- 3
|
130
|
+
version: 0.10.3
|
131
|
+
type: :development
|
132
|
+
version_requirements: *id007
|
86
133
|
description: Little library that encapsulates a (particular) standardised way of talking between a service and javascript. Probably not the best way of doing things, but it's been handy in a pinch.
|
87
134
|
email:
|
88
135
|
- rolly@luma.co.nz
|
@@ -90,62 +137,64 @@ executables: []
|
|
90
137
|
|
91
138
|
extensions: []
|
92
139
|
|
93
|
-
extra_rdoc_files:
|
94
|
-
|
95
|
-
- Manifest.txt
|
96
|
-
- README.txt
|
140
|
+
extra_rdoc_files: []
|
141
|
+
|
97
142
|
files:
|
98
|
-
-
|
99
|
-
-
|
100
|
-
- README.
|
143
|
+
- Gemfile
|
144
|
+
- Gemfile.lock
|
145
|
+
- README.rdoc
|
101
146
|
- Rakefile
|
147
|
+
- js-client-bridge.gemspec
|
102
148
|
- lib/js-client-bridge.rb
|
103
149
|
- lib/js-client-bridge/responses.rb
|
104
|
-
- lib/js-client-bridge/responses/ok.rb
|
105
|
-
- lib/js-client-bridge/responses/validation.rb
|
106
150
|
- lib/js-client-bridge/responses/error.rb
|
107
151
|
- lib/js-client-bridge/responses/exception.rb
|
108
|
-
- lib/js-client-bridge/
|
109
|
-
-
|
110
|
-
-
|
111
|
-
- script/generate
|
112
|
-
- spec/ok_responses_spec.rb
|
152
|
+
- lib/js-client-bridge/responses/ok.rb
|
153
|
+
- lib/js-client-bridge/responses/validation.rb
|
154
|
+
- lib/js-client-bridge/version.rb
|
113
155
|
- spec/error_responses_spec.rb
|
114
156
|
- spec/exception_responses_spec.rb
|
115
|
-
- spec/
|
157
|
+
- spec/ok_responses_spec.rb
|
158
|
+
- spec/rcov.opts
|
116
159
|
- spec/spec.opts
|
117
160
|
- spec/spec_helper.rb
|
161
|
+
- spec/validation_responses_spec.rb
|
118
162
|
- tasks/rspec.rake
|
119
163
|
has_rdoc: true
|
120
|
-
homepage:
|
164
|
+
homepage: http://rubygems.org/gems/js-client-bridge
|
121
165
|
licenses: []
|
122
166
|
|
123
167
|
post_install_message:
|
124
|
-
rdoc_options:
|
125
|
-
|
126
|
-
- README.txt
|
168
|
+
rdoc_options: []
|
169
|
+
|
127
170
|
require_paths:
|
128
171
|
- lib
|
129
172
|
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
130
174
|
requirements:
|
131
175
|
- - ">="
|
132
176
|
- !ruby/object:Gem::Version
|
177
|
+
hash: 3
|
133
178
|
segments:
|
134
179
|
- 0
|
135
180
|
version: "0"
|
136
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
137
183
|
requirements:
|
138
184
|
- - ">="
|
139
185
|
- !ruby/object:Gem::Version
|
186
|
+
hash: 23
|
140
187
|
segments:
|
141
|
-
-
|
142
|
-
|
188
|
+
- 1
|
189
|
+
- 3
|
190
|
+
- 6
|
191
|
+
version: 1.3.6
|
143
192
|
requirements: []
|
144
193
|
|
145
194
|
rubyforge_project: js-client-bridge
|
146
|
-
rubygems_version: 1.3.
|
195
|
+
rubygems_version: 1.3.7
|
147
196
|
signing_key:
|
148
197
|
specification_version: 3
|
149
|
-
summary:
|
198
|
+
summary: Standardised way of talking between a service and javascript
|
150
199
|
test_files: []
|
151
200
|
|
data/History.txt
DELETED
data/Manifest.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.txt
|
4
|
-
Rakefile
|
5
|
-
lib/js-client-bridge.rb
|
6
|
-
lib/js-client-bridge/responses.rb
|
7
|
-
lib/js-client-bridge/responses/ok.rb
|
8
|
-
lib/js-client-bridge/responses/validation.rb
|
9
|
-
lib/js-client-bridge/responses/error.rb
|
10
|
-
lib/js-client-bridge/responses/exception.rb
|
11
|
-
lib/js-client-bridge/extensions/datamapper_errors.rb
|
12
|
-
script/console
|
13
|
-
script/destroy
|
14
|
-
script/generate
|
15
|
-
spec/ok_responses_spec.rb
|
16
|
-
spec/error_responses_spec.rb
|
17
|
-
spec/exception_responses_spec.rb
|
18
|
-
spec/validation_responses_spec.rb
|
19
|
-
spec/spec.opts
|
20
|
-
spec/spec_helper.rb
|
21
|
-
tasks/rspec.rake
|
@@ -1,43 +0,0 @@
|
|
1
|
-
|
2
|
-
module DataMapper
|
3
|
-
module Validate
|
4
|
-
|
5
|
-
##
|
6
|
-
#
|
7
|
-
# Monkey patch of Datamapper to add a nice to_json method that uses our error format
|
8
|
-
class ValidationErrors
|
9
|
-
|
10
|
-
def to_hash
|
11
|
-
js = {}
|
12
|
-
|
13
|
-
errors.each do |list, pair|
|
14
|
-
js[list] = pair
|
15
|
-
end
|
16
|
-
|
17
|
-
js
|
18
|
-
end
|
19
|
-
|
20
|
-
end # class ValidationErrors
|
21
|
-
end # module Validate
|
22
|
-
end # module DataMapper
|
23
|
-
|
24
|
-
module DataMapper
|
25
|
-
module Resource
|
26
|
-
def errors_to_hash(message = "Sorry, we couldn't save your #{self.class.to_s.split('::').last}")
|
27
|
-
|
28
|
-
short_type = self.class.to_s.split('::').last
|
29
|
-
|
30
|
-
validation = {
|
31
|
-
:_status => 'validation',
|
32
|
-
:_type => self.class,
|
33
|
-
:_short_type => short_type,
|
34
|
-
:_message => message,
|
35
|
-
:validation => self.errors.to_hash,
|
36
|
-
}
|
37
|
-
|
38
|
-
validation[:id] = self.id.to_s unless new_record?
|
39
|
-
|
40
|
-
validation
|
41
|
-
end
|
42
|
-
end # module Resource
|
43
|
-
end # module DataMapper
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/js-client-bridge.rb'}"
|
9
|
-
puts "Loading js-client-bridge gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|