flexirest 1.6.0 → 1.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8959a6f4a0183bc9395d12c61676d30da8157f30
4
- data.tar.gz: dedf65e6535a9da183a39a8cae90aea1c95584f6
3
+ metadata.gz: 96c037bf934becbdc7d5381bfaef226550e1a3c1
4
+ data.tar.gz: 99c2aa6b76d361c1b6862c9bf82fc28b1914737a
5
5
  SHA512:
6
- metadata.gz: 49edb2862a956a893d484d01a9baab9a53645129d29c8445cbabb59684355381b8127d3be16ec93d7b67b033984247efe9a6b74654ab579829a59ad661f9729d
7
- data.tar.gz: 1edb7882ab1e52bfbffebf5940c53e95f878a9665aa2c07a8789a1f038b62c60b04f514d491b54c3964cef0b49753effffa97d1b0621e490633937f9f1da4c1d
6
+ metadata.gz: fe9c061af6b61f68cdffc1243546285f4a33450624dd08b77b8428cb9f58a4ecbf2be4605ff21654f86a35a41713e10055ba92badd4d0c4aaead4a6ff6d5c6f0
7
+ data.tar.gz: c7342b08bb159edbb8691166668e49d0235cd87c7aee73a27c7a127de495f1e81f17a44cbe95e5e58e003ea276d265739b1e67bd3709b4a52518b4328a0bbebd
data/.travis.yml CHANGED
@@ -6,4 +6,3 @@ rvm:
6
6
  - 2.2.0
7
7
  - 2.1.0
8
8
  - 2.0.0
9
- - 1.9.3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.1
4
+
5
+ Feature:
6
+
7
+ - Added `where` filtering to result iterators (thanks to Jeljer te Wies for the feature).
8
+
3
9
  ## 1.6.0
4
10
 
5
11
  Feature:
data/README.md CHANGED
@@ -45,12 +45,13 @@ If you are a previous user of ActiveRestClient, there's some more information on
45
45
  - [Proxying APIs](#proxying-apis)
46
46
  - [Translating APIs](#translating-apis)
47
47
  - [Default Parameters](#default-parameters)
48
- - [Root element removal](#root-element-removal)
48
+ - [Root elements](#root-elements)
49
49
  - [Required Parameters](#required-parameters)
50
50
  - [Updating Only Changed/Dirty](#updating-only-changed-dirty)
51
51
  - [HTTP/Parse Error Handling](#httpparse-error-handling)
52
52
  - [Validation](#validation)
53
53
  - [Permitting nil values](#permitting-nil-values)
54
+ - [Filtering result lists](#filtering-result-lists)
54
55
  - [Debugging](#debugging)
55
56
  - [XML Responses](#xml-responses)
56
57
  - [Contributing](#contributing)
@@ -1201,7 +1202,19 @@ The following attributes will pass validation since they explicitly `allow_nil`:
1201
1202
  - `:retirement_age`
1202
1203
  - `:favorite_authors`
1203
1204
 
1204
- ### Debugging
1205
+ ### Filtering result lists
1206
+
1207
+ If the API returns a JSON list of items, this is retured to you as a `Flexirest::ResultIterator` object. A `ResultIterator` sorts simple filtering of the list based on values matching a specified criteria (or matching using regular expressions):
1208
+
1209
+ ```ruby
1210
+ class Article < Flexirest::Base
1211
+ get :all, "/articles"
1212
+ end
1213
+
1214
+ Article.all.where(published: true, department: /technical\-/)
1215
+ ```
1216
+
1217
+ ## Debugging
1205
1218
 
1206
1219
  You can turn on verbose debugging to see what is sent to the API server and what is returned in one of these two ways:
1207
1220
 
@@ -63,6 +63,20 @@ module Flexirest
63
63
  self
64
64
  end
65
65
 
66
+ def where(criteria={})
67
+ @items.select do |object|
68
+ select = true
69
+ criteria.each do |k, v|
70
+ if v.is_a?(Regexp)
71
+ select = false if !object[k][v]
72
+ else
73
+ select = false if object[k] != v
74
+ end
75
+ end
76
+ select
77
+ end
78
+ end
79
+
66
80
  def parallelise(method=nil)
67
81
  collected_responses = []
68
82
  threads = []
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.1"
3
3
  end
@@ -109,7 +109,30 @@ describe Flexirest::ResultIterator do
109
109
  expect(result.items).to eq(["a"])
110
110
  end
111
111
 
112
+ it "can filter results by simple matching criteria" do
113
+ class Something < Flexirest::Base
114
+ end
115
+
116
+ results = Flexirest::ResultIterator.new
117
+ results << Something.new(type: "foo")
118
+ results << Something.new(type: "foo")
119
+ results << Something.new(type: "bar")
120
+
121
+ expect(results.where(type: "foo").count).to eq(2)
122
+ end
112
123
 
124
+ it "can filter results using regular expression matching criteria" do
125
+ class Something < Flexirest::Base
126
+ end
127
+
128
+ results = Flexirest::ResultIterator.new
129
+ results << Something.new(type: "fooo")
130
+ results << Something.new(type: "foo")
131
+ results << Something.new(type: "fo")
132
+ results << Something.new(type: "bar")
133
+
134
+ expect(results.where(type: /foo+/).count).to eq(2)
135
+ end
113
136
 
114
137
  it "can parallelise calls to each item" do
115
138
  result = Flexirest::ResultIterator.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries