app_rail-airtable 0.2.5 → 0.2.6

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
  SHA256:
3
- metadata.gz: bfc0c7a8abdd811b4b70a4ef1bf1d5a42a9212712cfdf35fada50d1db81c670b
4
- data.tar.gz: 133f6b44dc502297d1bdfeb085f896a62eb155d0483ce8cf60c493ee2db84c7d
3
+ metadata.gz: 0d893dd5ef7b42015a34fe0dd55738ef1296799ba40bd235c4fd1c84665d6048
4
+ data.tar.gz: 0bd37ae820e88d1198cd7e82a0d8a965d893d0d4c8dc32bc33975f7f7a95cbcc
5
5
  SHA512:
6
- metadata.gz: 482b3617a8e4ee7d2628e1efb7d6a4674ecf258c77dbd1594aaa1246dcfa0d06d56846f0606e75de39c76902b3101c2e10646e6587ccf98ef06965f5eca8eca8
7
- data.tar.gz: 2d3fdcd70ed7f14166fa8c301a5745b5aa8aeaaef6dd0202da440570dfe8d537ffad48eb6debd1d4fa05092a560bd8bdd396aad7c523a9aefbda23b8abb1c769
6
+ metadata.gz: 4a4fe2f30b7b4ef404062e5396d304abf584873b1bfb5bf32d81ed3f8d5f04a01172bac29600ed83f7e347ba28267e670ce083e5aa0b93e886357b00042bfe73
7
+ data.tar.gz: 23cf52db82ae5ba37f9ea00751f867a93b7d1f800f480810b21e932e4cfec3792eede5a3569b3b0baba1143991d415e6a09c031bee7d981196d8ebcbfca2cfaf
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .byebug_history
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_rail-airtable (0.2.5)
4
+ app_rail-airtable (0.2.6)
5
5
  activesupport
6
6
  airrecord
7
7
  sinatra
data/bin/ara_generator CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "bundler/setup"
3
- require 'app_rail/airtable'
3
+ require 'app_rail/airtable/generator'
4
4
  require 'byebug'
5
5
 
6
6
  AppRail::Airtable::Generator.start(ARGV)
@@ -1,7 +1,7 @@
1
1
  require 'active_support/core_ext/string/inflections'
2
+ require 'app_rail/airtable/string_ext'
2
3
  require 'thor'
3
4
  require 'airrecord'
4
- require 'app_rail/airtable/string_ext'
5
5
 
6
6
  module AppRail
7
7
  module Airtable
@@ -23,24 +23,42 @@ end
23
23
  module AppRail
24
24
  module Airtable
25
25
  class Sinatra < Sinatra::Base
26
+
27
+ helpers do
28
+ def request_body_as_json
29
+ request.body.rewind
30
+ JSON.parse(request.body.read)
31
+ end
32
+ end
26
33
 
27
- def self.resources(name)
34
+ def self.resources(name, only: [:index, :show, :create])
35
+ only = [only] if only.is_a?(Symbol)
36
+
37
+ index_route(name) if only.include?(:index)
38
+ show_route(name) if only.include?(:show)
39
+ create_route(name) if only.include?(:create)
40
+ end
41
+
42
+ def self.index_route(name)
28
43
  get "/#{name.to_s}" do
29
44
  name.classify_constantize.index.map(&:ar_list_item_as_json).to_json
30
45
  end
31
-
46
+ end
47
+
48
+ def self.show_route(name)
32
49
  get "/#{name.to_s}/:id" do
33
50
  name.classify_constantize.find(params['id']).ar_stack_as_json.to_json
34
51
  end
35
-
52
+ end
53
+
54
+ def self.create_route(name)
36
55
  post "/#{name.to_s}" do
37
56
  request.body.rewind # in case someone already read it
38
57
  data = JSON.parse(request.body.read)
39
- new_record = name.classify_constantize.create_from_params(data.merge(params))
40
- [201, {id: new_record.id}.to_json]
58
+ as_json = name.classify_constantize.create_with_params_as_json(data.merge(params))
59
+ [201, as_json.to_json]
41
60
  end
42
61
  end
43
-
44
62
  end
45
63
  end
46
64
  end
@@ -1,5 +1,5 @@
1
1
  module AppRail
2
2
  module Airtable
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
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.2.5
4
+ version: 0.2.6
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-20 00:00:00.000000000 Z
11
+ date: 2021-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,7 +102,6 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".DS_Store"
105
- - ".byebug_history"
106
105
  - ".gitignore"
107
106
  - ".rspec"
108
107
  - ".travis.yml"
data/.byebug_history DELETED
@@ -1,14 +0,0 @@
1
- exit
2
- @table_definitions.first.all.first.fields.keys
3
- @table_definitions.first.all.first.fields
4
- @table_definitions.first.all.first
5
- @table_definitions.first.first
6
- @table_definitions.first.instance_variable_get("@fields")
7
- @table_definitions.first.instance_variable_get("fields")
8
- @table_definitions.first.instance_variable_get("@fields")
9
- @table_definitions.first.fields
10
- @table_definitions.first.table_name
11
- @table_definitions.first.name
12
- @table_definitions.first.all
13
- @table_definitions.first
14
- @table_definitions