LVS-JSONService 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.specification +1 -1
- data/JSONService.gemspec +2 -2
- data/VERSION +1 -1
- data/lib/lvs/json_service/base.rb +18 -7
- data/lib/lvs/json_service/logger.rb +5 -2
- data/spec/lvs/json_service/logger_spec.rb +22 -8
- data/spec/lvs/json_service/request_spec.rb +4 -0
- data/spec/spec_helper.rb +0 -2
- metadata +2 -2
data/.specification
CHANGED
data/JSONService.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{JSONService}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["LVS"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-24}
|
10
10
|
s.email = %q{info@lvs.co.uk}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -56,7 +56,7 @@ module LVS
|
|
56
56
|
|
57
57
|
def site=(value)
|
58
58
|
# value is containing AGP_LOCATION already sometimes:
|
59
|
-
value.gsub!(/^#{AGP_LOCATION}/, '') if AGP_LOCATION && value.match(/#{AGP_LOCATION}/)
|
59
|
+
value.gsub!(/^#{AGP_LOCATION}/, '') if defined?(AGP_LOCATION) && value.match(/#{AGP_LOCATION}/)
|
60
60
|
agp = @agp_location ? @agp_location : AGP_LOCATION
|
61
61
|
agp.gsub!(/\/$/, '')
|
62
62
|
value.gsub!(/^\//, '')
|
@@ -111,7 +111,7 @@ module LVS
|
|
111
111
|
add_service(name)
|
112
112
|
end
|
113
113
|
|
114
|
-
def fake_service(name, json)
|
114
|
+
def fake_service(name, json, options = {})
|
115
115
|
(class<<self;self;end).send :define_method, name do |*args|
|
116
116
|
self.parse_result(JSON.parse(json))
|
117
117
|
end
|
@@ -135,16 +135,27 @@ module LVS
|
|
135
135
|
def initialize(values = {})
|
136
136
|
values.each_pair do |key, value|
|
137
137
|
key = key.underscore
|
138
|
-
|
139
|
-
|
138
|
+
new_instance_methods = "
|
139
|
+
def #{key}
|
140
|
+
@#{key}
|
141
|
+
end
|
142
|
+
def #{key}=(value)
|
143
|
+
@#{key} = value
|
144
|
+
end
|
145
|
+
"
|
140
146
|
|
141
147
|
# If the key starts with has_ create alias to has_ method removing has
|
142
148
|
# and putting ? at the end
|
143
149
|
if key =~ /^has_/
|
144
150
|
temp_key = "#{key.gsub(/^has_/, '')}?"
|
145
|
-
|
146
|
-
|
147
|
-
|
151
|
+
new_instance_methods << "
|
152
|
+
def #{temp_key}
|
153
|
+
@#{key}
|
154
|
+
end
|
155
|
+
"
|
156
|
+
end
|
157
|
+
|
158
|
+
self.instance_eval(new_instance_methods)
|
148
159
|
|
149
160
|
if value.is_a?(Hash)
|
150
161
|
self.instance_variable_set("@#{key}", self.class.new(value))
|
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'pp'
|
1
2
|
module LVS
|
2
3
|
module JsonService
|
3
4
|
module Logger
|
4
5
|
def self.debug(message)
|
5
|
-
|
6
|
-
|
6
|
+
if defined?(Rails) && Rails.logger
|
7
|
+
message = " \033[1;4;32mLVS::JsonService\033[0m #{message}"
|
8
|
+
Rails.logger.debug(message)
|
9
|
+
end
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
@@ -1,28 +1,42 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
|
+
|
3
4
|
describe LVS::JsonService::Logger do
|
4
5
|
before :each do
|
5
6
|
end
|
6
7
|
|
7
8
|
describe "debug" do
|
8
|
-
describe "with
|
9
|
+
describe "with Rails.logger set" do
|
9
10
|
before :each do
|
10
11
|
@mock_logger = mock()
|
11
|
-
|
12
|
+
|
13
|
+
if !defined?(Rails)
|
14
|
+
class Rails
|
15
|
+
class << self
|
16
|
+
def logger=(value)
|
17
|
+
@logger = value
|
18
|
+
end
|
19
|
+
def logger
|
20
|
+
@logger
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Rails.logger = @mock_logger
|
12
27
|
end
|
13
28
|
|
14
|
-
it "should pass the message to
|
29
|
+
it "should pass the message to Rails.logger" do
|
15
30
|
message = "Some debug message"
|
16
|
-
|
31
|
+
coloured_message = " \033[1;4;32mLVS::JsonService\033[0m #{message}"
|
32
|
+
@mock_logger.should_receive(:debug).with(coloured_message)
|
17
33
|
LVS::JsonService::Logger.debug(message)
|
18
34
|
end
|
19
35
|
end
|
20
36
|
|
21
|
-
describe "without
|
37
|
+
describe "without Rails defined" do
|
22
38
|
before :each do
|
23
|
-
|
24
|
-
remove_const(:RAILS_DEFAULT_LOGGER) if const_defined?(:RAILS_DEFAULT_LOGGER)
|
25
|
-
end
|
39
|
+
Object.send(:remove_const, :Rails)
|
26
40
|
end
|
27
41
|
|
28
42
|
it "should not raise an exception" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: LVS-JSONService
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LVS
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|