api_client 0.5.5 → 0.5.6
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/api_client/base.rb +12 -2
- data/lib/api_client/version.rb +1 -1
- data/spec/api_client/base_spec.rb +44 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2dce33109687e5c643cd183ef8c656d56af40d4
|
4
|
+
data.tar.gz: 97d0acdf47edc3ed2a03a00d3085c9b897687da3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db347b7180f5ec2296438e1be6ae95ee51fff531fd1d3d703948f5880af427ac07e89e682b6519b52f17d7ee9ce39e47a3e89fa50d57cf7b314c2bd05b5b64db
|
7
|
+
data.tar.gz: eb9d837428478b41fefba7725c30bfd4093fcfe98daae2a3f19bd89673429989051dab0e6acc14276acde7bbec87823dea53663223bcfb13535ac316c87b56c0
|
data/CHANGELOG.md
ADDED
data/lib/api_client/base.rb
CHANGED
@@ -56,7 +56,17 @@ module ApiClient
|
|
56
56
|
"#<#{self.class} #{attributes.join(', ')}>"
|
57
57
|
end
|
58
58
|
|
59
|
+
private
|
60
|
+
def method_missing(method_name, *args, &blk)
|
61
|
+
if respond_to?(method_name)
|
62
|
+
super
|
63
|
+
else
|
64
|
+
if respond_to?(:strict_attr_reader?) && self.strict_attr_reader?
|
65
|
+
fetch(method_name)
|
66
|
+
else
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
59
71
|
end
|
60
|
-
|
61
72
|
end
|
62
|
-
|
data/lib/api_client/version.rb
CHANGED
@@ -10,6 +10,18 @@ describe ApiClient::Base do
|
|
10
10
|
subject.should respond_to("id")
|
11
11
|
end
|
12
12
|
|
13
|
+
class StrictApi < ApiClient::Base
|
14
|
+
def accessor_of_x
|
15
|
+
self.x
|
16
|
+
end
|
17
|
+
|
18
|
+
def strict_attr_reader?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class StrictDescendant < StrictApi
|
24
|
+
end
|
13
25
|
|
14
26
|
describe "#inspect" do
|
15
27
|
|
@@ -35,4 +47,36 @@ describe ApiClient::Base do
|
|
35
47
|
|
36
48
|
end
|
37
49
|
|
50
|
+
describe "strict_read" do
|
51
|
+
it "fails if the key is missing and strict_read is set" do
|
52
|
+
api = StrictApi.new
|
53
|
+
lambda { api.missing }.should raise_error(KeyError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "doesn't fail if strict_read is not set" do
|
57
|
+
api = ApiClient::Base.new
|
58
|
+
api.missing
|
59
|
+
end
|
60
|
+
|
61
|
+
it "doesn't fail if the key was set after object was created" do
|
62
|
+
api = StrictApi.new
|
63
|
+
api.not_missing = 1
|
64
|
+
api.not_missing.should == 1
|
65
|
+
end
|
66
|
+
|
67
|
+
it "allows to call methods" do
|
68
|
+
api = StrictApi.new(:x => 14)
|
69
|
+
api.accessor_of_x.should == 14
|
70
|
+
end
|
71
|
+
|
72
|
+
it "calling method which asks for missing attribute fails" do
|
73
|
+
api = StrictApi.new
|
74
|
+
lambda { api.accessor_of_x }.should raise_error(KeyError)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "passes strict api configuration to subclasses" do
|
78
|
+
api = StrictDescendant.new
|
79
|
+
lambda { api.missing }.should raise_error(KeyError)
|
80
|
+
end
|
81
|
+
end
|
38
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Bunsch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yajl-ruby
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
77
|
- .rspec
|
78
|
+
- CHANGELOG.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE
|
80
81
|
- README.md
|