airmodel 0.0.1pre → 0.0.1

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: 52609d17520965802a5ce6ad3bfbd4ed9e16d1bc
4
- data.tar.gz: a2aa97650c28a577de2a568827ef8e52ab502004
3
+ metadata.gz: fb5eeb6e340c2b3236d9cb8c193d5761498d8d90
4
+ data.tar.gz: 75325168af92642cab483442ac1f22ab46290e7a
5
5
  SHA512:
6
- metadata.gz: 1cb44df1db02298370724c4245548cb0dc52f49700efa0a8946c255b3aeaf9603912a1f4b7d451a8273a03927b31382714453e54b7a41981f5d60f447b005ef1
7
- data.tar.gz: 7b8a4704f3679579fc8f0324f6a6f66a4764b47770843ae8a20d56898699eb535b8d608146ed0834fc48893d00ce1612619af13bf7102349b9d3ffc2324ebba0
6
+ metadata.gz: f1c9c3bedfe7b4ea7796845b0d063df8828d425c315314c7ff179dd794624edc63f1207fe024a8062c976007dde65c74a5f237758e746944a1d701666690f999
7
+ data.tar.gz: cf7b16dcaa42d6f4ad4145c24939b21fd4179431bb917aec1951cf690fa6ccd2c5409237e0c841da3c3364c90a9a14bc8520bff192d6f0d66765cd2d5f7a7220
data/README.md CHANGED
@@ -61,6 +61,8 @@ Now you can write code like
61
61
 
62
62
  Song.all
63
63
 
64
+ Song.some
65
+
64
66
  Song.first
65
67
 
66
68
  Song.new("Name": "Best Song Ever").save
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'pry', '~> 0.10'
23
23
  spec.add_development_dependency 'fakeweb', '~> 1.3'
24
24
 
25
- spec.add_dependency 'airtable', '~> 0.0.8'
25
+ spec.add_dependency 'airtable', '~> 0.0.9'
26
26
  spec.add_dependency 'activesupport', '~> 5.0'
27
27
  end
@@ -23,22 +23,3 @@ module Airmodel
23
23
  end
24
24
 
25
25
  end
26
-
27
- # monkeypatch airtable-ruby to add v 0.0.9's PATCH method,
28
- # at least until Airtable adds 0.0.9 to rubygems
29
- module Airtable
30
- class Table
31
-
32
- def update_record_fields(record_id, fields_for_update)
33
- result = self.class.patch(worksheet_url + "/" + record_id,
34
- :body => { "fields" => fields_for_update }.to_json,
35
- :headers => { "Content-type" => "application/json" }).parsed_response
36
- if result.present? && result["id"].present?
37
- Record.new(result_attributes(result))
38
- else # failed
39
- false
40
- end
41
- end
42
-
43
- end
44
- end
@@ -2,31 +2,27 @@ module Airmodel
2
2
  class Model < Airtable::Record
3
3
  extend Utils
4
4
 
5
- # returns all records in the database, making as many calls as necessary
6
- # to work around Airtable's 100-record per page design
5
+ # returns all records in a table, making as many calls as necessary
6
+ # to work around Airtable's 100-record per page design. This can be VERY
7
+ # slow, and should not be used in production unless you cache it agressively.
8
+ # Where possible, use Model.some instead.
7
9
  def self.all(args={sort: default_sort})
8
10
  puts "RUNNING EXPENSIVE API QUERY TO AIRTABLE (#{self.name})"
9
11
  self.classify tables(args).map{|tbl| tbl.all(args)}.flatten
10
12
  end
11
13
 
12
14
  # returns up to 100 records from Airtable
13
- def self.records(args={sort: default_sort})
15
+ def self.some(args={sort: default_sort})
14
16
  puts "RUNNING EXPENSIVE API QUERY TO AIRTABLE (#{self.name})"
15
17
  self.classify tables(args).map{|tbl| tbl.records(args) }.flatten
16
18
  end
17
19
 
18
- # default to whatever order airtable returns
19
- # this method gets overridden on Airtabled classes
20
- def self.default_sort
21
- nil
22
- end
23
-
24
- # find records that match the filters
20
+ # find up to 100 records that match the filters
25
21
  def self.where(filters)
26
22
  shard = filters.delete(:shard)
27
23
  order = filters.delete(:sort)
28
24
  formula = "AND(" + filters.map{|k,v| "{#{k}}='#{v}'" }.join(',') + ")"
29
- records(
25
+ some(
30
26
  shard: shard,
31
27
  sort: order,
32
28
  filterByFormula: formula,
@@ -40,7 +36,7 @@ module Airmodel
40
36
  results = self.classify tables(shard: shard).map{|tbl| tbl.find(filters[:id]) }
41
37
  else
42
38
  formula = "AND(" + filters.map{|k,v| "{#{k}}='#{v}'" }.join(',') + ")"
43
- results = records(
39
+ results = some(
44
40
  shard: shard,
45
41
  filterByFormula: formula,
46
42
  limit: 1
@@ -49,17 +45,23 @@ module Airmodel
49
45
  results.count == 0 ? nil : results.first
50
46
  end
51
47
 
48
+ # default to whatever order Airtable returns
49
+ # override this method if you want to sort by something else
50
+ def self.default_sort
51
+ nil
52
+ end
53
+
52
54
  # return the first record
53
55
  def self.first
54
- results = records(
56
+ results = some(
55
57
  limit: 1
56
58
  )
57
59
  results.count == 0 ? nil : results.first
58
60
  end
59
61
 
60
62
  # create a new record and save it to Airtable
61
- def self.create(*records)
62
- results = records.map{|r|
63
+ def self.create(*models)
64
+ results = models.map{|r|
63
65
  record = self.new(r)
64
66
  tables.map{|tbl| tbl.create(record) }.first
65
67
  }
@@ -1,3 +1,3 @@
1
1
  module Airmodel
2
- VERSION = '0.0.1pre'
2
+ VERSION = '0.0.1'
3
3
  end
@@ -41,9 +41,9 @@ describe TestModel do
41
41
  end
42
42
  end
43
43
 
44
- describe "records" do
44
+ describe "some" do
45
45
  it "should return a list of airtable records" do
46
- records = TestModel.records
46
+ records = TestModel.some
47
47
  expect(records.first.id).to eq "recXYZ"
48
48
  end
49
49
  end
@@ -268,7 +268,7 @@ end
268
268
  describe BaselessTestModel do
269
269
  describe "it should raise a NoSuchBaseError when no base is defined" do
270
270
  begin
271
- records = BaselessTestModel.records
271
+ records = BaselessTestModel.some
272
272
  false
273
273
  rescue Airmodel::NoSuchBase
274
274
  true
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.1pre
4
+ version: 0.0.1
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-17 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.0.8
89
+ version: 0.0.9
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.0.8
96
+ version: 0.0.9
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: activesupport
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -143,9 +143,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
- - - ">"
146
+ - - ">="
147
147
  - !ruby/object:Gem::Version
148
- version: 1.3.1
148
+ version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
151
  rubygems_version: 2.6.4