app_rail-airtable 0.2.1 → 0.2.5

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: ad788bfb14babba5e0216173a01c6e58d815756b8fcce1282d0acf86d1c3ffbc
4
- data.tar.gz: d3dc7df90a92d215f0ceaab252aa914000b8a08bf0c3acc6ee8f36011611ad56
3
+ metadata.gz: bfc0c7a8abdd811b4b70a4ef1bf1d5a42a9212712cfdf35fada50d1db81c670b
4
+ data.tar.gz: 133f6b44dc502297d1bdfeb085f896a62eb155d0483ce8cf60c493ee2db84c7d
5
5
  SHA512:
6
- metadata.gz: 8b8eb9d1d13e0a6f11494363b278fa4449912b925883dc9ba9b2b9224249ef0f80dd6b9c647baf4f26210898600992710bdd50622f75bf6a2edaed57fb0f413d
7
- data.tar.gz: 1669de508317bc09821dc97bb3e4ea7fa5fb6c5b389bb8a32a9ac2702757ca9aa03b474f6d8dc9906e814b67eed4714bc36012ad63c29a39cb42d696139849aa
6
+ metadata.gz: 482b3617a8e4ee7d2628e1efb7d6a4674ecf258c77dbd1594aaa1246dcfa0d06d56846f0606e75de39c76902b3101c2e10646e6587ccf98ef06965f5eca8eca8
7
+ data.tar.gz: 2d3fdcd70ed7f14166fa8c301a5745b5aa8aeaaef6dd0202da440570dfe8d537ffad48eb6debd1d4fa05092a560bd8bdd396aad7c523a9aefbda23b8abb1c769
data/.byebug_history ADDED
@@ -0,0 +1,14 @@
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
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+ gem "thor"
9
+ gem "byebug"
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_rail-airtable (0.2.1)
4
+ app_rail-airtable (0.2.5)
5
5
  activesupport
6
6
  airrecord
7
7
  sinatra
8
+ thor
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -18,6 +19,7 @@ GEM
18
19
  airrecord (1.0.7)
19
20
  faraday (>= 0.10, < 2.0)
20
21
  net-http-persistent
22
+ byebug (11.1.3)
21
23
  concurrent-ruby (1.1.9)
22
24
  connection_pool (2.2.5)
23
25
  diff-lcs (1.4.4)
@@ -73,6 +75,7 @@ GEM
73
75
  rack (~> 2.2)
74
76
  rack-protection (= 2.1.0)
75
77
  tilt (~> 2.0)
78
+ thor (1.1.0)
76
79
  tilt (2.0.10)
77
80
  tzinfo (2.0.4)
78
81
  concurrent-ruby (~> 1.0)
@@ -83,9 +86,11 @@ PLATFORMS
83
86
 
84
87
  DEPENDENCIES
85
88
  app_rail-airtable!
89
+ byebug
86
90
  rack-test
87
91
  rake (~> 12.0)
88
92
  rspec (~> 3.0)
93
+ thor
89
94
 
90
95
  BUNDLED WITH
91
96
  2.1.4
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'activesupport'
24
24
  spec.add_dependency 'sinatra'
25
25
  spec.add_dependency 'airrecord'
26
+ spec.add_dependency 'thor'
26
27
 
27
28
  spec.add_development_dependency 'rspec'
28
29
  spec.add_development_dependency 'rack-test'
data/bin/ara_generator ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require 'app_rail/airtable'
4
+ require 'byebug'
5
+
6
+ AppRail::Airtable::Generator.start(ARGV)
@@ -1,12 +1,6 @@
1
1
  require 'airrecord'
2
2
  require 'active_support/core_ext/string/inflections'
3
3
 
4
- class String
5
- def snake_case
6
- gsub(" ", "_").underscore
7
- end
8
- end
9
-
10
4
  module AppRail
11
5
  module Airtable
12
6
  class ApplicationRecord < Airrecord::Table
@@ -27,7 +21,7 @@ module AppRail
27
21
  end
28
22
 
29
23
  # Step utilities
30
- def self.ar_list_item(text:, detail_text:, image: nil, sf_symbol: nil, material_icon: nil)
24
+ def self.ar_list_item(text:, detail_text: nil, image: nil, sf_symbol: nil, material_icon: nil)
31
25
  define_method(:ar_list_item_as_json) do
32
26
  {
33
27
  id: self.id,
@@ -61,7 +55,7 @@ module AppRail
61
55
 
62
56
  # size is either :small, :large or :full
63
57
  def image(name, index: 0, size: :full)
64
- self[name][index]["thumbnails"][size.to_s]["url"]
58
+ self[name][index]["thumbnails"][size.to_s]["url"] if self[name] && self[name].length > index
65
59
  end
66
60
 
67
61
  end
@@ -0,0 +1,31 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'thor'
3
+ require 'airrecord'
4
+ require 'app_rail/airtable/string_ext'
5
+
6
+ module AppRail
7
+ module Airtable
8
+ class Generator < Thor::Group
9
+ include Thor::Actions
10
+
11
+ argument :output_directory
12
+ argument :api_key
13
+ argument :base_id
14
+ argument :tables
15
+
16
+ def self.source_root
17
+ File.join(File.dirname(__FILE__), "..", "..", "..")
18
+ end
19
+
20
+ def create_project
21
+ # Build tables
22
+ @table_definitions = tables.split(",").map {|t| Airrecord.table(api_key, base_id, t.strip) }
23
+ directory('templates/project', output_directory)
24
+ end
25
+
26
+ def self.exit_on_failure?
27
+ true
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def snake_case
3
+ gsub(" ", "_").underscore
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module AppRail
2
2
  module Airtable
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
@@ -1,6 +1,8 @@
1
1
  require "app_rail/airtable/version"
2
2
  require "app_rail/airtable/application_record"
3
3
  require "app_rail/airtable/sinatra"
4
+ require "app_rail/airtable/generator"
5
+ require "app_rail/airtable/string_ext"
4
6
 
5
7
  module AppRail
6
8
  module Airtable
@@ -0,0 +1,2 @@
1
+ AIRTABLE_API_KEY=<%= api_key %>
2
+ AIRTABLE_BASE_ID=<%= base_id %>
@@ -0,0 +1,8 @@
1
+ .DS_STORE
2
+ *.swp
3
+ *.rbc
4
+ *.sass-cache
5
+ /pkg
6
+ /coverage
7
+ .yardoc
8
+ /doc
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ ruby '2.7.4'
7
+
8
+ gem 'app_rail-airtable'
9
+
10
+ # dev
11
+ gem 'dotenv'
12
+
13
+ # test
14
+ gem "rspec"
15
+ gem "rack-test"
@@ -0,0 +1,90 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (6.1.4.1)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 1.6, < 2)
7
+ minitest (>= 5.1)
8
+ tzinfo (~> 2.0)
9
+ zeitwerk (~> 2.3)
10
+ airrecord (1.0.7)
11
+ faraday (>= 0.10, < 2.0)
12
+ net-http-persistent
13
+ app_rail-airtable (0.2.2)
14
+ activesupport
15
+ airrecord
16
+ sinatra
17
+ concurrent-ruby (1.1.9)
18
+ connection_pool (2.2.5)
19
+ diff-lcs (1.4.4)
20
+ dotenv (2.7.6)
21
+ faraday (1.8.0)
22
+ faraday-em_http (~> 1.0)
23
+ faraday-em_synchrony (~> 1.0)
24
+ faraday-excon (~> 1.1)
25
+ faraday-httpclient (~> 1.0.1)
26
+ faraday-net_http (~> 1.0)
27
+ faraday-net_http_persistent (~> 1.1)
28
+ faraday-patron (~> 1.0)
29
+ faraday-rack (~> 1.0)
30
+ multipart-post (>= 1.2, < 3)
31
+ ruby2_keywords (>= 0.0.4)
32
+ faraday-em_http (1.0.0)
33
+ faraday-em_synchrony (1.0.0)
34
+ faraday-excon (1.1.0)
35
+ faraday-httpclient (1.0.1)
36
+ faraday-net_http (1.0.1)
37
+ faraday-net_http_persistent (1.2.0)
38
+ faraday-patron (1.0.0)
39
+ faraday-rack (1.0.0)
40
+ i18n (1.8.10)
41
+ concurrent-ruby (~> 1.0)
42
+ minitest (5.14.4)
43
+ multipart-post (2.1.1)
44
+ mustermann (1.1.1)
45
+ ruby2_keywords (~> 0.0.1)
46
+ net-http-persistent (4.0.1)
47
+ connection_pool (~> 2.2)
48
+ rack (2.2.3)
49
+ rack-protection (2.1.0)
50
+ rack
51
+ rack-test (1.1.0)
52
+ rack (>= 1.0, < 3)
53
+ rspec (3.10.0)
54
+ rspec-core (~> 3.10.0)
55
+ rspec-expectations (~> 3.10.0)
56
+ rspec-mocks (~> 3.10.0)
57
+ rspec-core (3.10.1)
58
+ rspec-support (~> 3.10.0)
59
+ rspec-expectations (3.10.1)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.10.0)
62
+ rspec-mocks (3.10.2)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.10.0)
65
+ rspec-support (3.10.2)
66
+ ruby2_keywords (0.0.5)
67
+ sinatra (2.1.0)
68
+ mustermann (~> 1.0)
69
+ rack (~> 2.2)
70
+ rack-protection (= 2.1.0)
71
+ tilt (~> 2.0)
72
+ tilt (2.0.10)
73
+ tzinfo (2.0.4)
74
+ concurrent-ruby (~> 1.0)
75
+ zeitwerk (2.4.2)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ app_rail-airtable
82
+ dotenv
83
+ rack-test
84
+ rspec
85
+
86
+ RUBY VERSION
87
+ ruby 2.7.4p191
88
+
89
+ BUNDLED WITH
90
+ 2.1.4
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "App Rail Airtable Service",
3
+ "description": "A barebones template to convert Airtable data to App Rail format",
4
+ "buildpacks": [
5
+ {
6
+ "url": "heroku/ruby"
7
+ }
8
+ ],
9
+ "env": {
10
+ "AIRTABLE_API_KEY": {
11
+ "description": "Your Airtable API key."
12
+ },
13
+ "AIRTABLE_BASE_ID": {
14
+ "description": "The ID of the Base you'd like to connect to."
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,5 @@
1
+ $stdout.sync = true
2
+
3
+ require 'dotenv/load'
4
+ require './lib/server'
5
+ run Server
@@ -0,0 +1,15 @@
1
+ require 'app_rail/airtable'
2
+
3
+ <% @table_definitions.each do |td| -%>
4
+ <% keys = td.all.first.fields.keys -%>
5
+ class <%= td.table_name.singularize %> < AppRail::Airtable::ApplicationRecord
6
+ airtable_attr <%= keys.map{|f| "\"#{f}\""}.join(", ") %>
7
+ ar_list_item text: :<%= keys.first.snake_case %>
8
+ end
9
+
10
+ <% end -%>
11
+ class Server < AppRail::Airtable::Sinatra
12
+ <% @table_definitions.each do |td| -%>
13
+ resources :<%= td.table_name.snake_case %>
14
+ <% end -%>
15
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Server do
4
+
5
+ def app
6
+ Server
7
+ end
8
+
9
+ end
@@ -0,0 +1,115 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+
17
+ # Dummy ENV Setup
18
+ ENV['AIRTABLE_API_KEY'] = 'keyABC123'
19
+ ENV['AIRTABLE_BASE_ID'] = 'appABC123'
20
+ ENV['RACK_ENV'] = 'test'
21
+
22
+ require "rack/test"
23
+ require "app_rail/airtable"
24
+
25
+ require './lib/server'
26
+ require './lib/item_recommender'
27
+
28
+ RSpec.configure do |config|
29
+ # rspec-expectations config goes here. You can use an alternate
30
+ # assertion/expectation library such as wrong or the stdlib/minitest
31
+ # assertions if you prefer.
32
+ config.expect_with :rspec do |expectations|
33
+ # This option will default to `true` in RSpec 4. It makes the `description`
34
+ # and `failure_message` of custom matchers include text for helper methods
35
+ # defined using `chain`, e.g.:
36
+ # be_bigger_than(2).and_smaller_than(4).description
37
+ # # => "be bigger than 2 and smaller than 4"
38
+ # ...rather than:
39
+ # # => "be bigger than 2"
40
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
41
+ end
42
+
43
+ # rspec-mocks config goes here. You can use an alternate test double
44
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
45
+ config.mock_with :rspec do |mocks|
46
+ # Prevents you from mocking or stubbing a method that does not exist on
47
+ # a real object. This is generally recommended, and will default to
48
+ # `true` in RSpec 4.
49
+ mocks.verify_partial_doubles = true
50
+ end
51
+
52
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
53
+ # have no way to turn it off -- the option exists only for backwards
54
+ # compatibility in RSpec 3). It causes shared context metadata to be
55
+ # inherited by the metadata hash of host groups and examples, rather than
56
+ # triggering implicit auto-inclusion in groups with matching metadata.
57
+ config.shared_context_metadata_behavior = :apply_to_host_groups
58
+
59
+ # The settings below are suggested to provide a good initial experience
60
+ # with RSpec, but feel free to customize to your heart's content.
61
+ =begin
62
+ # This allows you to limit a spec run to individual examples or groups
63
+ # you care about by tagging them with `:focus` metadata. When nothing
64
+ # is tagged with `:focus`, all examples get run. RSpec also provides
65
+ # aliases for `it`, `describe`, and `context` that include `:focus`
66
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
67
+ config.filter_run_when_matching :focus
68
+
69
+ # Allows RSpec to persist some state between runs in order to support
70
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
71
+ # you configure your source control system to ignore this file.
72
+ config.example_status_persistence_file_path = "spec/examples.txt"
73
+
74
+ # Limits the available syntax to the non-monkey patched syntax that is
75
+ # recommended. For more details, see:
76
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
77
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
78
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
79
+ config.disable_monkey_patching!
80
+
81
+ # This setting enables warnings. It's recommended, but in some cases may
82
+ # be too noisy due to issues in dependencies.
83
+ config.warnings = true
84
+
85
+ # Many RSpec users commonly either run the entire suite or an individual
86
+ # file, and it's useful to allow more verbose output when running an
87
+ # individual spec file.
88
+ if config.files_to_run.one?
89
+ # Use the documentation formatter for detailed output,
90
+ # unless a formatter has already been configured
91
+ # (e.g. via a command-line flag).
92
+ config.default_formatter = "doc"
93
+ end
94
+
95
+ # Print the 10 slowest examples and example groups at the
96
+ # end of the spec run, to help surface which specs are running
97
+ # particularly slow.
98
+ config.profile_examples = 10
99
+
100
+ # Run specs in random order to surface order dependencies. If you find an
101
+ # order dependency and want to debug it, you can fix the order by providing
102
+ # the seed, which is printed after each run.
103
+ # --seed 1234
104
+ config.order = :random
105
+
106
+ # Seed global randomization in this process using the `--seed` CLI option.
107
+ # Setting this allows you to use `--seed` to deterministically reproduce
108
+ # test failures related to randomization by passing the same `--seed` value
109
+ # as the one that triggered the failure.
110
+ Kernel.srand config.seed
111
+ =end
112
+
113
+ config.include Rack::Test::Methods
114
+
115
+ 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.1
4
+ version: 0.2.5
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-18 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +102,7 @@ extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
104
  - ".DS_Store"
105
+ - ".byebug_history"
91
106
  - ".gitignore"
92
107
  - ".rspec"
93
108
  - ".travis.yml"
@@ -97,12 +112,24 @@ files:
97
112
  - README.md
98
113
  - Rakefile
99
114
  - app_rail-airtable.gemspec
115
+ - bin/ara_generator
100
116
  - bin/console
101
117
  - bin/setup
102
118
  - lib/app_rail/airtable.rb
103
119
  - lib/app_rail/airtable/application_record.rb
120
+ - lib/app_rail/airtable/generator.rb
104
121
  - lib/app_rail/airtable/sinatra.rb
122
+ - lib/app_rail/airtable/string_ext.rb
105
123
  - lib/app_rail/airtable/version.rb
124
+ - templates/project/.env.tt
125
+ - templates/project/.gitignore
126
+ - templates/project/Gemfile
127
+ - templates/project/Gemfile.lock
128
+ - templates/project/app.json
129
+ - templates/project/config.ru
130
+ - templates/project/lib/server.rb.tt
131
+ - templates/project/spec/server_spec.rb
132
+ - templates/project/spec/spec_helper.rb
106
133
  homepage: https://github.com/FutureWorkshops/app_rail-airtable
107
134
  licenses:
108
135
  - MIT