airmodel 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/airmodel.rb +1 -1
- data/lib/airmodel/model.rb +18 -0
- data/lib/airmodel/utils.rb +3 -3
- data/lib/airmodel/version.rb +1 -1
- data/spec/models_spec.rb +13 -0
- 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: 0993017b73e85cdf5feea7202fe15bc08b7337db
|
4
|
+
data.tar.gz: 96efc042d20d434f44e31485f2f585a18aa26522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6198d0499f0b32b0d7d6df2dd16ea5405cdf8fd9125ac87118416082587080e1c775319aef2359825f8c458455483fc88883dc5b5c4c2fc6b84866c15cb078e
|
7
|
+
data.tar.gz: 574e06e6344caee7da1ed5e904bbe6fabaf58f313e8714fe5305de108a1c7dfb109c6b6cfd33b411f2ad1200a3ef86ac6ebae91b3e13a112a1a10741181cb454
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Installation
|
|
8
8
|
|
9
9
|
Add this line to your Gemfile:
|
10
10
|
|
11
|
-
gem install 'airmodel'
|
11
|
+
gem install 'airmodel'
|
12
12
|
|
13
13
|
Configuration
|
14
14
|
----------------
|
@@ -69,6 +69,10 @@ Now you can write code like
|
|
69
69
|
|
70
70
|
Song.where("Artist Name": "The Beatles", "Composer": "Harrison")
|
71
71
|
|
72
|
+
Song.find("recXYZ")
|
73
|
+
|
74
|
+
Song.find(["recXYZ", "recABC", "recJKL"])
|
75
|
+
|
72
76
|
See lib/airmodel/model.rb for all available methods.
|
73
77
|
|
74
78
|
|
data/lib/airmodel.rb
CHANGED
data/lib/airmodel/model.rb
CHANGED
@@ -29,6 +29,24 @@ module Airmodel
|
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
|
+
# find a record by ID.
|
33
|
+
# IF you've (1) defined an 'id' Field in Airtable, (2) made it a formula,
|
34
|
+
# and (3) set the formula to RECORD_ID(),
|
35
|
+
# THEN you can pass self.find([an,array,of,ids]) and it will return
|
36
|
+
# each record in that order. This is mostly only useful for looking up
|
37
|
+
# records linked to a particular record.
|
38
|
+
def self.find(id, shard=nil)
|
39
|
+
if id.is_a? String
|
40
|
+
results = self.classify tables(shard: shard).map{|tbl| tbl.find(id) }
|
41
|
+
results.count == 0 ? nil : results.first
|
42
|
+
else
|
43
|
+
formula = "OR(" + id.map{|x| "id='#{x}'" }.join(',') + ")"
|
44
|
+
some(shard: shard, filterByFormula: formula).sort_by do |x|
|
45
|
+
id.index(x.id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
32
50
|
# find a record by specified attributes, return it
|
33
51
|
def self.find_by(filters)
|
34
52
|
shard = filters.delete(:shard)
|
data/lib/airmodel/utils.rb
CHANGED
@@ -9,13 +9,13 @@ module Airmodel
|
|
9
9
|
# each backed by a base defined in DB YAML file
|
10
10
|
def tables(args={})
|
11
11
|
db = Airmodel.bases[table_name] || raise(NoSuchBase.new("Could not find base '#{table_name}' in config file"))
|
12
|
-
|
12
|
+
bases_list = normalized_base_config(db[:bases])
|
13
13
|
# return just one Airtable::Table if a particular shard was requested
|
14
14
|
if args[:shard]
|
15
|
-
[Airmodel.client.table(
|
15
|
+
[Airmodel.client.table(bases_list[args.delete(:shard)], db[:table_name])]
|
16
16
|
# otherwise return each one
|
17
17
|
else
|
18
|
-
|
18
|
+
bases_list.map{|key, val| Airmodel.client.table val, db[:table_name] }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/lib/airmodel/version.rb
CHANGED
data/spec/models_spec.rb
CHANGED
@@ -71,6 +71,19 @@ describe TestModel do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
describe "find" do
|
75
|
+
it "should call airtable-ruby's 'find' method when passed just one record ID" do
|
76
|
+
stub_airtable_response! "https://api.airtable.com/v0/appXYZ/example_table/recABC", { "id":"recABC", fields: {"name": "example record"} }
|
77
|
+
record = TestModel.find("recABC")
|
78
|
+
expect(record.name).to eq "example record"
|
79
|
+
end
|
80
|
+
it "should return an ordered list of records when passed an array of record IDs" do
|
81
|
+
records = TestModel.find(["recABC", "recXYZ"])
|
82
|
+
expect(records.class).to eq Array
|
83
|
+
expect(records.first.id).to eq "recABC"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
74
87
|
describe "find_by" do
|
75
88
|
it "should return one record that matches the supplied filters", skip_before: true do
|
76
89
|
stub_airtable_response!(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airmodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrisfrankdotfm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|