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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb5eeb6e340c2b3236d9cb8c193d5761498d8d90
4
- data.tar.gz: 75325168af92642cab483442ac1f22ab46290e7a
3
+ metadata.gz: 0993017b73e85cdf5feea7202fe15bc08b7337db
4
+ data.tar.gz: 96efc042d20d434f44e31485f2f585a18aa26522
5
5
  SHA512:
6
- metadata.gz: f1c9c3bedfe7b4ea7796845b0d063df8828d425c315314c7ff179dd794624edc63f1207fe024a8062c976007dde65c74a5f237758e746944a1d701666690f999
7
- data.tar.gz: cf7b16dcaa42d6f4ad4145c24939b21fd4179431bb917aec1951cf690fa6ccd2c5409237e0c841da3c3364c90a9a14bc8520bff192d6f0d66765cd2d5f7a7220
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', git: 'https://github.com/chrisfrank/airmodel.git'
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
@@ -17,7 +17,7 @@ module Airmodel
17
17
  @@api_client
18
18
  end
19
19
 
20
- def self.bases(path_to_config_file="#{Airmodel.root}/config/bases.yml")
20
+ def self.bases(path_to_config_file="#{Dir.pwd}/config/bases.yml")
21
21
  @@bases ||= YAML.load_file(path_to_config_file)
22
22
  @@bases
23
23
  end
@@ -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)
@@ -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
- bases = normalized_base_config(db[:bases])
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(bases[args.delete(:shard)], db[:table_name])]
15
+ [Airmodel.client.table(bases_list[args.delete(:shard)], db[:table_name])]
16
16
  # otherwise return each one
17
17
  else
18
- bases.map{|key, val| Airmodel.client.table val, db[:table_name] }
18
+ bases_list.map{|key, val| Airmodel.client.table val, db[:table_name] }
19
19
  end
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Airmodel
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
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.1
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-18 00:00:00.000000000 Z
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler