app_rail-airtable 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +24 -23
- data/lib/app_rail/airtable/application_record.rb +22 -10
- data/lib/app_rail/airtable/sinatra.rb +1 -1
- data/lib/app_rail/airtable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2aa2acf23c1a19d2da51975f9ffcc4df977bb2161671c17ec353fa927180ddc
|
4
|
+
data.tar.gz: 139e1d42de5b43f560e738b48675e8142b02f02662b67744d5a325c157f0e7be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2338dcc79c15c783900d9d5054e635f6dda8e6ca78802fb06d2cb3b9bdc2391e1be9839e6dc527a2d2746c64d56e5490256c6c1789240b3f54a81dad7e05d524
|
7
|
+
data.tar.gz: da5ba11679f264dc1c96f2f123ff0aa04d5288d55405be12d539f874b6d96bd53cba4d950b735cb7de5a71322f052e018a86719454f202a44e0c7fe637aa608f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# App Rail Airtable
|
2
2
|
|
3
|
-
|
3
|
+
App Rail Airtable is a micro-framework based on Sinatra and [Airrecord](https://github.com/sirupsen/airrecord) which faciliates use of Airtable as a backend for App Rail Apps. You can deploy a template repo to Heroku for fast start.
|
4
4
|
|
5
|
-
|
5
|
+
## Quick Start
|
6
|
+
|
7
|
+
Visit [App Rail Airtable Template](https://github.com/FutureWorkshops/AppRailAirtableTemplate) and follow instructions.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -12,28 +14,27 @@ Add this line to your application's Gemfile:
|
|
12
14
|
gem 'app_rail-airtable'
|
13
15
|
```
|
14
16
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install app_rail-airtable
|
22
|
-
|
23
17
|
## Usage
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
19
|
+
App Rail Airtable has two important concepts, models and servers. The [App Rail Petshop](https://github.com/FutureWorkshops/ar-petshop-airtable) provides useful examples.
|
20
|
+
|
21
|
+
### Models
|
22
|
+
App Rail Airtable makes the following assumptions
|
23
|
+
1. Your App will connect to a single Airtable Base
|
24
|
+
2. Your Airtable Base implements a normalised datamodel
|
25
|
+
3. Your tables in Airtable are plural versions of the models you create in Ruby
|
26
|
+
|
27
|
+
**API keys have account scope in Airtable so it is recommended to create a new account for each project so that API keys do not leak data, e.g. bob+<project name>@gmail.com. You can share the project with your main account so you don't need to login to separate accounts for each project.**
|
28
|
+
|
29
|
+
You should create a model class for each table you want to use in your App. Model classes should extend `AppRail::Airtable::ApplicationRecord` and define [table name](https://github.com/sirupsen/airrecord#table) and [associations](https://github.com/sirupsen/airrecord#associations)
|
30
|
+
|
31
|
+
To provide support for routes, models can implement
|
32
|
+
* ar_list_item (index)
|
33
|
+
* ar_stack (show)
|
34
|
+
* self.create_from_params (create)
|
35
|
+
|
36
|
+
### Servers
|
37
|
+
You should create a single server which extends `AppRail::Airtable::Sinatra`, then add routes with the `resources` macro to add `index`, `show` and `create` routes. You can also provide your own routes.
|
37
38
|
|
38
39
|
## License
|
39
40
|
|
@@ -1,18 +1,33 @@
|
|
1
1
|
require 'airrecord'
|
2
|
+
require 'active_support/core_ext/string/inflections'
|
3
|
+
|
4
|
+
class String
|
5
|
+
def snake_case
|
6
|
+
gsub(" ", "_").underscore
|
7
|
+
end
|
8
|
+
end
|
2
9
|
|
3
10
|
module AppRail
|
4
11
|
module Airtable
|
5
12
|
class ApplicationRecord < Airrecord::Table
|
13
|
+
include ActiveSupport::Inflector
|
14
|
+
|
15
|
+
def self.airtable_attr(*attributes)
|
16
|
+
attributes.each do |attribute|
|
17
|
+
define_method(attribute.to_s.snake_case) { self[attribute] }
|
18
|
+
end
|
19
|
+
end
|
6
20
|
|
21
|
+
# Step utilities
|
7
22
|
def self.ar_list_item(text:, detail_text:, image: nil, sf_symbol: nil, material_icon: nil)
|
8
23
|
define_method(:ar_list_item_as_json) do
|
9
24
|
{
|
10
25
|
id: self.id,
|
11
|
-
text:
|
12
|
-
detailText:
|
13
|
-
imageURL:
|
14
|
-
sfSymbolName: sf_symbol,
|
15
|
-
materialIconName: material_icon
|
26
|
+
text: method_value(text).to_s,
|
27
|
+
detailText: method_value(detail_text).to_s,
|
28
|
+
imageURL: method_value(image),
|
29
|
+
sfSymbolName: method_value(sf_symbol),
|
30
|
+
materialIconName: method_value(material_icon)
|
16
31
|
}.compact
|
17
32
|
end
|
18
33
|
end
|
@@ -32,11 +47,8 @@ module AppRail
|
|
32
47
|
|
33
48
|
private
|
34
49
|
|
35
|
-
|
36
|
-
|
37
|
-
return nil unless name
|
38
|
-
|
39
|
-
respond_to?(name) ? send(name) : self[name]
|
50
|
+
def method_value(name)
|
51
|
+
send(name) if name.present?
|
40
52
|
end
|
41
53
|
|
42
54
|
# size is either :small, :large or :full
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_rail-airtable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|