norairrecord 0.3.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: 0f5fc9903052fc25fe8bdd071a9989ab92561387d0dabc70ad82045a8335eab1
4
- data.tar.gz: d445e59398dbb6c10e08ce645ad12f2dd8dd763ca16334f4ca93477ebe8c9d37
3
+ metadata.gz: 2d6cb01e5b17df2640cfc26b6e719deb69d04b21cbb89eb8f31b4dffc052c998
4
+ data.tar.gz: 66406d3ffbcda723cdc524447555d646e58578b8ea56b7c25f3170bfb754eb93
5
5
  SHA512:
6
- metadata.gz: 6c78431764c880fbf87535717d223b9ce805c7b6a38a45a64dcf649b073c6dae6d4d322a7130a59d5f0e3cef51389887858568f260a83f34c8cca6e66ef1f3d8
7
- data.tar.gz: c97892cf8cb38a5ac9103e6e5358c4993e3fcca8f0e5e42a8d68ac9e22daad3d83320dcf9cc8592e46bd26965ff394fac9fbfdce385d341682aa6f6ab73467eb
6
+ metadata.gz: 352e8b49946a4b54657140b5736c246f56f9381c8e6225176674bb93438b6d25b9e9f3ba2a60596996760a5adf6be5d8318cf98951102f09cd0d6a19e990cd9a
7
+ data.tar.gz: 6570f39459f17d523fb963c4274c8d8e3831b9281659e257c44c45d799556d6c3df10c733061ed6ec1dc5dbdbea56733d7f7c9ed85b0c2b2cc686f5821ac2536
data/README.md CHANGED
@@ -55,4 +55,7 @@ stuff not in the OG:
55
55
  * `Table#first`, `Table#first_where`
56
56
  * you're not gonna believe it:
57
57
  * `Table.batch_`{update,upsert,create,save}
58
- * makes ratelimits much less painful
58
+ * makes ratelimits much less painful
59
+ * `Util` (those little methods we have to keep writing again and again, now in one place)
60
+ * custom RPS limit
61
+ * `Norairrecord.rps_limit = 3`
@@ -23,7 +23,7 @@ module Norairrecord
23
23
  },
24
24
  ) do |conn|
25
25
  if Norairrecord.throttle?
26
- conn.request :airrecord_rate_limiter, requests_per_second: AIRTABLE_RPS_LIMIT
26
+ conn.request :airrecord_rate_limiter, requests_per_second: Norairrecord.rps_limit || AIRTABLE_RPS_LIMIT
27
27
  end
28
28
  conn.adapter :net_http_persistent
29
29
  end
@@ -7,6 +7,8 @@ module Norairrecord
7
7
  class << self
8
8
  attr_writer :api_key, :base_key, :table_name
9
9
 
10
+ include Norairrecord::Util
11
+
10
12
  def base_key
11
13
  @base_key || (superclass < Table ? superclass.base_key : nil)
12
14
  end
@@ -15,6 +17,16 @@ module Norairrecord
15
17
  @table_name || (superclass < Table ? superclass.table_name : nil)
16
18
  end
17
19
 
20
+
21
+ # finds the actual parent class of a (possibly) subtype class
22
+ def responsible_class
23
+ if @base_key
24
+ self.class
25
+ else
26
+ superclass < Table ? superclass.responsible_class : nil
27
+ end
28
+ end
29
+
18
30
  def client
19
31
  @@clients ||= {}
20
32
  @@clients[api_key] ||= Client.new(api_key)
@@ -66,9 +78,8 @@ module Norairrecord
66
78
  def find_many(ids, where: nil, sort: nil)
67
79
  return [] if ids.empty?
68
80
 
69
- or_args = ids.map { |id| "RECORD_ID() = '#{id}'" }.join(',')
70
- formula = "OR(#{or_args})"
71
- formula = "AND(#{formula},#{where})" if where
81
+ formula = any_of(ids.map { |id| "RECORD_ID() = '#{id}'" })
82
+ formula = all_of(formula, where) if where
72
83
  records(filter: formula, sort:).sort_by { |record| or_args.index(record.id) }
73
84
  end
74
85
 
@@ -0,0 +1,24 @@
1
+ module Norairrecord
2
+ module Util
3
+ class << self
4
+ def all_of(*args)
5
+ "AND(#{args.join(',')})"
6
+ end
7
+ def any_of(*args)
8
+ "OR(#{args.join(',')})"
9
+ end
10
+ def none_of(*args)
11
+ "NOT(#{all_of(*args)})"
12
+ end
13
+ def field_is_any(field, *args)
14
+ any_of(*args.map { |arg| "#{field}='#{sanitize(arg)}'"})
15
+ end
16
+ def sanitize(arg)
17
+ arg.gsub(/['"]/, '\\\\\0')
18
+ end
19
+ def mass_sanitize(*args)
20
+ args.map { |arg| sanitize(arg) }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Norairrecord
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/norairrecord.rb CHANGED
@@ -2,13 +2,14 @@ require "json"
2
2
  require "faraday"
3
3
  require 'faraday/net_http_persistent'
4
4
  require "time"
5
+ require "norairrecord/util"
5
6
  require "norairrecord/version"
6
7
  require "norairrecord/client"
7
8
  require "norairrecord/table"
8
9
 
9
10
  module Norairrecord
10
11
  extend self
11
- attr_accessor :api_key, :throttle, :base_url, :user_agent
12
+ attr_accessor :api_key, :throttle, :base_url, :user_agent, :rps_limit
12
13
 
13
14
  Error = Class.new(StandardError)
14
15
  UnknownTypeError = Class.new(Error)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norairrecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nora
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-05 00:00:00.000000000 Z
11
+ date: 2025-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -107,6 +107,7 @@ files:
107
107
  - lib/norairrecord/client.rb
108
108
  - lib/norairrecord/faraday_rate_limiter.rb
109
109
  - lib/norairrecord/table.rb
110
+ - lib/norairrecord/util.rb
110
111
  - lib/norairrecord/version.rb
111
112
  - norairrecord.gemspec
112
113
  homepage: https://github.com/24c02/norairrecord