app_rail-airtable 0.1.0 → 0.2.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: f9ec1d3dd50d2b81b46a1f6804319b97424192accf1e825830ade564c4901aa5
4
- data.tar.gz: '0220939ea9dfd1ca57806f60328ca0bd4ea09417fdc2aeb1b61e70687024aeef'
3
+ metadata.gz: b2aa2acf23c1a19d2da51975f9ffcc4df977bb2161671c17ec353fa927180ddc
4
+ data.tar.gz: 139e1d42de5b43f560e738b48675e8142b02f02662b67744d5a325c157f0e7be
5
5
  SHA512:
6
- metadata.gz: d13146f0116ea27771ac901dcc514938fa5e3b23e1b1342f6123a76a7e39bdb3b1dd1c7a2ce1bd477cc2a579a7c313ed44e521652f99ca9e8dcb78dba6b7a364
7
- data.tar.gz: e6cfc76d2a99c122d3643dd587bdef60a5e7131f04c4f7d0de0ed60ed76c2c130f6ded6d74123864fa6cb45c15cb904e0c7fcd2e4500720ce2479f4de6ae3132
6
+ metadata.gz: 2338dcc79c15c783900d9d5054e635f6dda8e6ca78802fb06d2cb3b9bdc2391e1be9839e6dc527a2d2746c64d56e5490256c6c1789240b3f54a81dad7e05d524
7
+ data.tar.gz: da5ba11679f264dc1c96f2f123ff0aa04d5288d55405be12d539f874b6d96bd53cba4d950b735cb7de5a71322f052e018a86719454f202a44e0c7fe637aa608f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_rail-airtable (0.1.0)
4
+ app_rail-airtable (0.2.0)
5
5
  activesupport
6
6
  airrecord
7
7
  sinatra
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # AppRail::Airtable
1
+ # App Rail Airtable
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/app_rail/airtable`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/app_rail-airtable.
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: method_value_or_property(text).to_s,
12
- detailText: method_value_or_property(detail_text).to_s,
13
- imageURL: method_value_or_property(image),
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
- # TODO: Method call not working?
36
- def method_value_or_property(name)
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
@@ -24,7 +24,7 @@ module AppRail
24
24
  module Airtable
25
25
  class Sinatra < Sinatra::Base
26
26
 
27
- def self.resource(name)
27
+ def self.resources(name)
28
28
  get "/#{name.to_s}" do
29
29
  name.classify_constantize.index.map(&:ar_list_item_as_json).to_json
30
30
  end
@@ -1,5 +1,5 @@
1
1
  module AppRail
2
2
  module Airtable
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
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.1.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-15 00:00:00.000000000 Z
11
+ date: 2021-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport