loquor 0.5.4 → 0.6.0
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 +5 -13
- data/CHANGELOG.md +4 -0
- data/lib/loquor/object_hash.rb +13 -6
- data/lib/loquor/resource.rb +3 -1
- data/lib/loquor/resource_mock.rb +5 -1
- data/lib/loquor/version.rb +1 -1
- data/test/object_hash_test.rb +13 -0
- data/test/resource_mock_test.rb +9 -1
- data/test/resource_test.rb +13 -4
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YmNkNzIzMTEzNmY0MmE4YTg5NWVhYjdhZDU4YTAwNGFiNjRiZDZjZQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2cfe52db79896211774e1d089c9214411c2357a6
|
4
|
+
data.tar.gz: 624d56b874f89f65dbcba8fae1d58701a12ae967
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MzRmNGJjNDYzMTllNmJiNWVhZTk1ZGJiY2U0MTI1MWMwODI5NjMwNTc5NDc4
|
11
|
-
NzU0YmMyYjlkZDJlMjcwZjE1MGVlYTE0ZTI3MWFmMWQ0MWUzMWM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NzJjMWM1ODcwNGI1ZjEyNDc1ZTExYTRlZTI1NDQ4YWFmZmFiNzQ3MTZjOGNl
|
14
|
-
MzlhNjQwMWMwNTkwMGI3NjhiMDUwMzk4N2E5MGI4OWYyZTkzOGEzMDNiZjI2
|
15
|
-
YmVkYTUyNWVlMzA0NzcyMGI5NGVjNWZhMWQ0MmEwODcyYWMyMDQ=
|
6
|
+
metadata.gz: 3b877ce234feba0ccbdf1b22da876456dac29f12fe4a3fad2b05114dbbf7f051bcc581ab9aabbbdfd04e2ab4b23389f870d8f801fe675c5bee99492f2eabe3af
|
7
|
+
data.tar.gz: 5a964b9378199a23451a913fbdf5a246009cb9820a06cf0c4ed7c98fc6dcd6e6bb40d22ecf72b7a14cd9f2e286fdc12517e69988c229364e821e329c53482048
|
data/CHANGELOG.md
CHANGED
data/lib/loquor/object_hash.rb
CHANGED
@@ -3,8 +3,9 @@ module Loquor
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class ObjectHash
|
6
|
-
def initialize(hash)
|
6
|
+
def initialize(hash, options = {})
|
7
7
|
@hash = hash
|
8
|
+
@strict = options[:strict]
|
8
9
|
end
|
9
10
|
|
10
11
|
def ==(other)
|
@@ -20,13 +21,19 @@ module Loquor
|
|
20
21
|
def [](key)
|
21
22
|
fetch_indescriminately(key)
|
22
23
|
rescue ObjectHashKeyMissingError
|
23
|
-
|
24
|
+
if @strict
|
25
|
+
raise $!
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
def method_missing(name, *args)
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
if name[-1] == "="
|
33
|
+
@hash.send(name, *args)
|
34
|
+
else
|
35
|
+
self[name]
|
36
|
+
end
|
30
37
|
end
|
31
38
|
|
32
39
|
private
|
@@ -39,7 +46,7 @@ module Loquor
|
|
39
46
|
elsif @hash.has_key?(name.to_s.to_sym)
|
40
47
|
@hash[name.to_s.to_sym]
|
41
48
|
else
|
42
|
-
raise ObjectHashKeyMissingError.new
|
49
|
+
raise ObjectHashKeyMissingError.new(name)
|
43
50
|
end
|
44
51
|
end
|
45
52
|
end
|
data/lib/loquor/resource.rb
CHANGED
@@ -2,11 +2,13 @@ module Loquor
|
|
2
2
|
class Resource
|
3
3
|
|
4
4
|
def initialize(data)
|
5
|
-
@data = ObjectHash.new(data)
|
5
|
+
@data = ObjectHash.new(data, strict: true)
|
6
6
|
end
|
7
7
|
|
8
8
|
def method_missing(name, *args)
|
9
9
|
@data[name]
|
10
|
+
rescue
|
11
|
+
raise NameError.new("undefined local variable or method '#{name}' for #{self.class.name}")
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.path=(path)
|
data/lib/loquor/resource_mock.rb
CHANGED
@@ -9,7 +9,7 @@ module Loquor
|
|
9
9
|
attr = name.to_s[0..-2].to_sym
|
10
10
|
@data[attr] = args[0]
|
11
11
|
else
|
12
|
-
raise NameError.new("undefined local variable or method '#{name}' for
|
12
|
+
raise NameError.new("undefined local variable or method '#{name}' for #{self.class.name}")
|
13
13
|
end
|
14
14
|
else
|
15
15
|
super(name, *args)
|
@@ -27,6 +27,10 @@ module Loquor
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def sample(overrides = {})
|
30
|
+
arbitary_attributes = (overrides.keys - attributes.keys)
|
31
|
+
unless arbitary_attributes.empty?
|
32
|
+
raise NameError.new("undefined local variable or method '#{arbitary_attributes.first}' for #{self.name}")
|
33
|
+
end
|
30
34
|
self.new(attributes.merge(overrides))
|
31
35
|
end
|
32
36
|
|
data/lib/loquor/version.rb
CHANGED
data/test/object_hash_test.rb
CHANGED
@@ -26,5 +26,18 @@ module Loquor
|
|
26
26
|
representation = ObjectHash.new({foo: "bar"})
|
27
27
|
assert_equal "bar", representation.foo
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_non_strict_returns_nil_on_missing_attribute
|
31
|
+
representation = ObjectHash.new({foo: "bar"})
|
32
|
+
assert_equal nil, representation.cat
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_strict_raises_on_missing_attribute
|
36
|
+
representation = ObjectHash.new({foo: "bar"}, strict: true)
|
37
|
+
ex = assert_raises(ObjectHashKeyMissingError) do
|
38
|
+
representation.cat
|
39
|
+
end
|
40
|
+
assert_equal "cat", ex.message
|
41
|
+
end
|
29
42
|
end
|
30
43
|
end
|
data/test/resource_mock_test.rb
CHANGED
@@ -18,9 +18,10 @@ module Loquor
|
|
18
18
|
|
19
19
|
def test_should_not_be_able_to_set_arbitary_attributes
|
20
20
|
foobar = Foobar.find(1)
|
21
|
-
assert_raises(NameError) do
|
21
|
+
ex = assert_raises(NameError) do
|
22
22
|
foobar.description = "Cat"
|
23
23
|
end
|
24
|
+
assert_equal "undefined local variable or method 'description=' for Loquor::ResourceMockTest::Foobar", ex.message
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_should_return_sample_object
|
@@ -33,6 +34,13 @@ module Loquor
|
|
33
34
|
foobar = Foobar.sample(name: name)
|
34
35
|
assert_equal name, foobar.name
|
35
36
|
end
|
37
|
+
|
38
|
+
def test_should_not_be_able_to_override_arbitary_attributes
|
39
|
+
ex = assert_raises(NameError) do
|
40
|
+
Foobar.sample(cat: "foobar")
|
41
|
+
end
|
42
|
+
assert_equal "undefined local variable or method 'cat' for Loquor::ResourceMockTest::Foobar", ex.message
|
43
|
+
end
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
data/test/resource_test.rb
CHANGED
@@ -19,10 +19,11 @@ module Loquor
|
|
19
19
|
|
20
20
|
def test_find_each_should_yield_block
|
21
21
|
Loquor.expects(:get).returns([{id: 1}])
|
22
|
-
|
22
|
+
count = 0
|
23
23
|
Foobar.find_each do |json|
|
24
|
-
|
24
|
+
count += 1
|
25
25
|
end
|
26
|
+
assert_equal 1, count
|
26
27
|
end
|
27
28
|
|
28
29
|
def test_select_should_proxy
|
@@ -43,13 +44,21 @@ module Loquor
|
|
43
44
|
Loquor.expects(:put).with("/foobar/#{id}", payload: payload)
|
44
45
|
Foobar.update(id, payload)
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
def test_can_read_path
|
48
49
|
assert_equal "/foobar", Foobar.path
|
49
50
|
end
|
50
|
-
|
51
|
+
|
51
52
|
def test_cache_flag_false_by_default
|
52
53
|
refute Foobar.cache
|
53
54
|
end
|
55
|
+
|
56
|
+
def test_raises_on_missing_attribute
|
57
|
+
representation = Foobar.new({})
|
58
|
+
ex = assert_raises(NameError) do
|
59
|
+
representation.random_attr
|
60
|
+
end
|
61
|
+
assert_equal "undefined local variable or method 'random_attr' for Loquor::ResourceTest::Foobar", ex.message
|
62
|
+
end
|
54
63
|
end
|
55
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loquor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
@@ -84,28 +84,28 @@ dependencies:
|
|
84
84
|
name: mocha
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: An API dispatcher for Meducation
|
@@ -164,12 +164,12 @@ require_paths:
|
|
164
164
|
- lib
|
165
165
|
required_ruby_version: !ruby/object:Gem::Requirement
|
166
166
|
requirements:
|
167
|
-
- -
|
167
|
+
- - '>='
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
|
-
- -
|
172
|
+
- - '>='
|
173
173
|
- !ruby/object:Gem::Version
|
174
174
|
version: '0'
|
175
175
|
requirements: []
|