braque 0.1.7 → 0.1.8
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/lib/braque/collection.rb +10 -10
- data/lib/braque/model.rb +12 -4
- data/lib/braque/version.rb +1 -1
- data/spec/braque/model_attributes_spec.rb +2 -2
- data/spec/braque/subclassed_model_spec.rb +31 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1301ea8c8cb20ba8d4bf8785c56d43483e39f5c9
|
4
|
+
data.tar.gz: a105f99e589ed6be0ed3a5144b8c0ed3e83d08c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ede1d3e637ae1b3dd5f2830c4043bfbf1762c624040ab2d047c3ce2b00fb9d09cc38ee3641ca0906457fdb4a4c69d4526038b46960cc007bbe52007f651e7b5e
|
7
|
+
data.tar.gz: 34aa058fdc69bc3668315ad6a2b6d31d10eaf11b8bb93031264731a5275e9f5502f35a78244a3f3f5abb80e92f2cd8d18b681534e1560d8f6d50b00e8be1e6cf
|
data/lib/braque/collection.rb
CHANGED
@@ -6,21 +6,21 @@ module Braque
|
|
6
6
|
attr_reader :total_count
|
7
7
|
|
8
8
|
def initialize(response = [], klass)
|
9
|
-
next_link = response._links.try(:next)
|
10
|
-
previous_link = response._links.try(:prev)
|
11
|
-
total_count = response.try(:total_count)
|
9
|
+
@next_link = response._links.try(:next)
|
10
|
+
@previous_link = response._links.try(:prev)
|
11
|
+
@total_count = response.try(:total_count)
|
12
|
+
super build_retrieved_items(response, klass)
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_retrieved_items(response, klass)
|
12
16
|
retrieved_items = []
|
13
|
-
|
17
|
+
response_collection(response, klass).each do |item|
|
14
18
|
retrieved_items << klass.new(item)
|
15
19
|
end
|
16
|
-
|
17
|
-
@next_link = next_link
|
18
|
-
@previous_link = previous_link
|
19
|
-
@total_count = total_count
|
20
|
-
super retrieved_items
|
20
|
+
retrieved_items
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def response_collection(response, klass)
|
24
24
|
return response unless response.respond_to? :_embedded
|
25
25
|
response._embedded.send klass.collection_method_name
|
26
26
|
end
|
data/lib/braque/model.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Braque
|
2
2
|
module Model
|
3
|
-
extend
|
4
|
-
include
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ActiveAttr::Model
|
5
5
|
|
6
6
|
included do
|
7
7
|
class_attribute :config
|
@@ -15,7 +15,7 @@ module Braque
|
|
15
15
|
# in client apps if some other scheme is more advisable.
|
16
16
|
#
|
17
17
|
def to_param
|
18
|
-
fail 'Please overide to_param or add
|
18
|
+
fail 'Please overide to_param or add ID to your model attributes.' unless attributes.include? 'id'
|
19
19
|
id.to_s
|
20
20
|
end
|
21
21
|
|
@@ -27,7 +27,7 @@ module Braque
|
|
27
27
|
# classes in client apps if some other scheme is more advisable.
|
28
28
|
#
|
29
29
|
def resource_find_options
|
30
|
-
fail 'Please overide resource_find_options or add
|
30
|
+
fail 'Please overide resource_find_options or add ID to your model attributes.' unless attributes.include? 'id'
|
31
31
|
{ id: id }
|
32
32
|
end
|
33
33
|
|
@@ -50,8 +50,16 @@ module Braque
|
|
50
50
|
|
51
51
|
def self.inherited(subclass)
|
52
52
|
subclass.class_eval do
|
53
|
+
# Allow the config settings for a superclass Braque::Model
|
54
|
+
# to be inherited by its subclassed Braque::Model classes
|
55
|
+
#
|
53
56
|
self.config = self.config.dup
|
54
57
|
|
58
|
+
# Allow a superclass's attributes to be inerited
|
59
|
+
# by subclassed Braque::Model classes
|
60
|
+
#
|
61
|
+
self.attributes = self.superclass.attributes.dup
|
62
|
+
|
55
63
|
define_singleton_method subclass.instance_method_name do
|
56
64
|
end
|
57
65
|
|
data/lib/braque/version.rb
CHANGED
@@ -52,7 +52,7 @@ RSpec.describe 'Braque::Model attribute definitions', type: :model do
|
|
52
52
|
context '.to_param' do
|
53
53
|
it 'raises an error unless id is defined or the method overridden' do
|
54
54
|
expect { Agate.new.to_param }.to raise_error(
|
55
|
-
RuntimeError, 'Please overide to_param or add
|
55
|
+
RuntimeError, 'Please overide to_param or add ID to your model attributes.'
|
56
56
|
)
|
57
57
|
end
|
58
58
|
|
@@ -76,7 +76,7 @@ RSpec.describe 'Braque::Model attribute definitions', type: :model do
|
|
76
76
|
context '.resource_find_options' do
|
77
77
|
it 'raises an error unless id is defined or the method is overridden' do
|
78
78
|
expect { Agate.new.resource_find_options }.to raise_error(
|
79
|
-
RuntimeError, 'Please overide resource_find_options or add
|
79
|
+
RuntimeError, 'Please overide resource_find_options or add ID to your model attributes.'
|
80
80
|
)
|
81
81
|
end
|
82
82
|
|
@@ -2,26 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Braque::Model, type: :model do
|
4
4
|
context 'with subclassed Braque::Model classes' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
class GeologicModel
|
6
|
+
include ::Braque::Model
|
7
|
+
api_root_url 'http://localhost:9292'
|
8
|
+
http_authorization_header 'replace-me'
|
9
|
+
attribute :id
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
class ContinentalDrift < GeologicModel
|
13
|
+
attribute :name
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
class Convection < GeologicModel
|
17
|
+
api_root_url 'http://localhost:9595'
|
18
|
+
http_authorization_header 'ok-another-one-to-replace'
|
19
|
+
attribute :first_name
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
22
|
+
class SeafloorSpreading
|
23
|
+
include ::Braque::Model
|
24
|
+
api_root_url 'http://localhost:9393'
|
25
|
+
http_authorization_header 'do-replace-me-as-well'
|
25
26
|
end
|
26
27
|
|
27
28
|
context 'api configuration' do
|
@@ -43,6 +44,19 @@ RSpec.describe Braque::Model, type: :model do
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
context 'attributes' do
|
48
|
+
[GeologicModel, ContinentalDrift, Convection].each do |klass|
|
49
|
+
it 'includes attributes defined by the superclass' do
|
50
|
+
expect(klass.attributes).to include :id
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'includes attributes defined by the subclass' do
|
55
|
+
expect(ContinentalDrift.attributes).to include :name
|
56
|
+
expect(Convection.attributes).to include :first_name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
46
60
|
context 'dynamic class methods' do
|
47
61
|
it 'sets the correct dynamic class methods for the base class' do
|
48
62
|
[:geologic_model, :geologic_models].each do |sym|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Fareed
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hyperclient
|