mobile_workflow 0.6.3 → 0.6.9
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 +4 -4
- data/lib/generators/mobile_workflow/controller_generator.rb +16 -0
- data/lib/generators/mobile_workflow/install/install_generator.rb +26 -9
- data/lib/generators/mobile_workflow/install/templates/{helpers → app/helpers}/application_helper.rb +0 -0
- data/lib/generators/mobile_workflow/install/templates/{views → app/views}/layouts/application.html.erb +0 -0
- data/lib/generators/mobile_workflow/install/templates/{views → app/views}/sessions/new.html.erb +0 -0
- data/{db/migrate/20200823174210_create_users.rb → lib/generators/mobile_workflow/install/templates/create_users.rb} +0 -0
- data/lib/generators/mobile_workflow/templates/controller.rb.erb +12 -3
- data/lib/generators/mobile_workflow/templates/controller_spec.rb.erb +8 -3
- data/lib/mobile_workflow/cli/app_builder.rb +15 -5
- data/lib/mobile_workflow/cli/app_server_generator.rb +2 -9
- data/lib/mobile_workflow/cli/heroku_backend.rb +4 -0
- data/lib/mobile_workflow/open_api_spec/parser.rb +19 -3
- data/lib/mobile_workflow/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 913509d1248a7a63226904e313ba1e56c700df9b95f0e393bb642d8f512c94b5
|
4
|
+
data.tar.gz: f1718f9a7e22d33c90ff546215c3ed6047118fca4148ccff6344ec34bedb375c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bc79973227c2db3e308c4329076ea441364ed7c65f2b095fabb201e23fedd2d736883c872ed051aa0ee17e2a94e626f4a99c3dbb95a058d8dbf568dc9d25a05
|
7
|
+
data.tar.gz: 5689ffc81f5df062ac81e25fdbe04da2986c10e434ba5bc9ce27d502381a3fbc63da5c8d8ffa698e4d85571b56ea3b74a0e26936c9178874dd66e60b773aa50a
|
@@ -33,6 +33,22 @@ module MobileWorkflow
|
|
33
33
|
params = attributes_names.map{ |name| ":#{name}" }
|
34
34
|
params.join(", ")
|
35
35
|
end
|
36
|
+
|
37
|
+
def index_action?
|
38
|
+
actions.include?("index")
|
39
|
+
end
|
40
|
+
|
41
|
+
def show_action?
|
42
|
+
actions.include?("show")
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_action?
|
46
|
+
actions.include?("create")
|
47
|
+
end
|
48
|
+
|
49
|
+
def actions
|
50
|
+
options[:actions]
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
38
54
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require "rails/generators/base"
|
2
|
+
require "rails/generators/active_model"
|
3
|
+
require "rails/generators/active_record/migration"
|
4
|
+
require "active_record"
|
2
5
|
require "mobile_workflow/open_api_spec/parser"
|
3
6
|
|
4
7
|
module MobileWorkflow
|
5
8
|
module Generators
|
6
9
|
class InstallGenerator < Rails::Generators::Base
|
10
|
+
include ActiveRecord::Generators::Migration
|
7
11
|
|
8
12
|
source_root File.expand_path("../templates", __FILE__)
|
9
13
|
|
@@ -24,6 +28,8 @@ module MobileWorkflow
|
|
24
28
|
return unless options[:doorkeeper_oauth]
|
25
29
|
say "Generating Doorkeeper OAuth"
|
26
30
|
|
31
|
+
migration_template "create_users.rb", "db/migrate/create_users.rb"
|
32
|
+
|
27
33
|
generate 'doorkeeper:install'
|
28
34
|
gsub_file 'config/initializers/doorkeeper.rb', 'raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"', 'User.find_by_id(session[:user_id]) || redirect_to(new_session_url(return_to: request.fullpath))'
|
29
35
|
generate 'doorkeeper:migration'
|
@@ -33,29 +39,36 @@ module MobileWorkflow
|
|
33
39
|
route "resources :sessions, only: [:new, :create]"
|
34
40
|
|
35
41
|
# View related for login screen
|
36
|
-
copy_file("views/layouts/application.html.erb")
|
37
|
-
copy_file("views/sessions/new.html.erb")
|
38
|
-
copy_file("helpers/application_helper.rb")
|
42
|
+
copy_file("app/views/layouts/application.html.erb")
|
43
|
+
copy_file("app/views/sessions/new.html.erb")
|
44
|
+
copy_file("app/helpers/application_helper.rb")
|
39
45
|
end
|
40
46
|
|
41
47
|
def generate_models
|
42
48
|
say "Loading OpenAPI Spec: #{open_api_spec_path}"
|
43
49
|
say "Generating models"
|
44
|
-
model_name_to_properties.each_pair do |model_name, model_properties|
|
50
|
+
model_name_to_properties.each_pair do |model_name, model_properties|
|
51
|
+
|
52
|
+
if doorkeeper_oauth?
|
53
|
+
model_properties = "#{model_properties} user:references"
|
54
|
+
@model_name_to_properties[model_name] = model_properties
|
55
|
+
end
|
56
|
+
|
45
57
|
if interactive? && !yes?("Use generated schema #{model_name}(#{model_properties})[yn]?")
|
46
58
|
model_properties = ask "Specify schema for #{model_name}: (e.g. text:string image:attachment region:reference)"
|
59
|
+
@model_name_to_properties[model_name] = model_properties
|
47
60
|
end
|
48
61
|
|
49
62
|
generate_model(model_name, model_properties)
|
50
|
-
@model_name_to_properties[model_name] = model_properties
|
51
63
|
end
|
52
64
|
end
|
53
65
|
|
54
66
|
def generate_controllers_and_routes
|
55
67
|
say "Generating controllers"
|
56
|
-
|
68
|
+
controller_name_to_actions = open_api_spec.controller_name_to_actions
|
69
|
+
route "root to: 'admin/#{controller_name_to_actions.keys.first}#index'"
|
57
70
|
|
58
|
-
|
71
|
+
controller_name_to_actions.each_pair do |plural_controller_name, actions|
|
59
72
|
controller_name = plural_controller_name.singularize
|
60
73
|
model_properties = model_name_to_properties[controller_name]
|
61
74
|
|
@@ -66,8 +79,8 @@ module MobileWorkflow
|
|
66
79
|
generate_model(controller_name, model_properties)
|
67
80
|
end
|
68
81
|
|
69
|
-
generate "mobile_workflow:controller #{controller_name} --attributes #{model_properties} #{s3_storage? ? '--s3-storage' : ''}".strip
|
70
|
-
route "resources :#{plural_controller_name}, only: [
|
82
|
+
generate "mobile_workflow:controller #{controller_name} --actions #{actions.join(" ")} --attributes #{model_properties} #{s3_storage? ? '--s3-storage' : ''}".strip
|
83
|
+
route "resources :#{plural_controller_name}, only: [#{actions.map{|a| ":#{a}"}.join(", ")}]"
|
71
84
|
end
|
72
85
|
end
|
73
86
|
|
@@ -88,6 +101,10 @@ module MobileWorkflow
|
|
88
101
|
def open_api_spec
|
89
102
|
@open_api_spec ||= ::MobileWorkflow::OpenApiSpec::Parser.new(File.read(open_api_spec_path))
|
90
103
|
end
|
104
|
+
|
105
|
+
def doorkeeper_oauth?
|
106
|
+
options[:doorkeeper_oauth]
|
107
|
+
end
|
91
108
|
|
92
109
|
def s3_storage?
|
93
110
|
options[:s3_storage]
|
data/lib/generators/mobile_workflow/install/templates/{helpers → app/helpers}/application_helper.rb
RENAMED
File without changes
|
File without changes
|
data/lib/generators/mobile_workflow/install/templates/{views → app/views}/sessions/new.html.erb
RENAMED
File without changes
|
File without changes
|
@@ -4,16 +4,24 @@ class <%= controller_class_name %>Controller < ApiController
|
|
4
4
|
before_action :rewrite_payload, only: :create
|
5
5
|
|
6
6
|
load_and_authorize_resource
|
7
|
-
|
7
|
+
|
8
|
+
<% if index_action? -%>
|
8
9
|
def index
|
9
10
|
render json: @<%= plural_table_name %>.collect(&:list_item_as_json)
|
10
11
|
end
|
11
|
-
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
<% if show_action? -%>
|
12
15
|
def show
|
13
16
|
render json: @<%= singular_table_name %>.display_as_json
|
14
17
|
end
|
15
|
-
|
18
|
+
|
19
|
+
<% end -%>
|
20
|
+
<% if create_action? -%>
|
16
21
|
def create
|
22
|
+
<% if doorkeeper_oauth? -%>
|
23
|
+
@<%= singular_table_name %> = current_user
|
24
|
+
<% end -%>
|
17
25
|
if @<%= singular_table_name %>.save
|
18
26
|
<% if s3_storage? -%>
|
19
27
|
render json: { binary_urls: binary_urls(@<%= singular_table_name %>), response: @<%= singular_table_name %> }, status: :created
|
@@ -39,5 +47,6 @@ class <%= controller_class_name %>Controller < ApiController
|
|
39
47
|
def <%= singular_table_name.underscore %>_params
|
40
48
|
params.require(:payload).permit(<%= permitted_params %>)
|
41
49
|
end
|
50
|
+
<% end -%>
|
42
51
|
end
|
43
52
|
<% end %>
|
@@ -10,7 +10,8 @@ RSpec.describe <%= controller_class_name %>Controller do
|
|
10
10
|
let(:user) { create(:user) }
|
11
11
|
let(:token) { instance_double('Doorkeeper::AccessToken', :accessible? => true, :acceptable? => true, resource_owner_id: user.id) }
|
12
12
|
<% end -%>
|
13
|
-
|
13
|
+
|
14
|
+
<% if index_action? -%>
|
14
15
|
describe 'GET #index' do
|
15
16
|
let!(:<%= controller_class_name.singularize.underscore %>) { create(:<%= controller_class_name.singularize.underscore %>) }
|
16
17
|
before(:each) do
|
@@ -25,7 +26,8 @@ RSpec.describe <%= controller_class_name %>Controller do
|
|
25
26
|
it { expect(response.status).to eq 200 }
|
26
27
|
end
|
27
28
|
end
|
28
|
-
|
29
|
+
<% end -%>
|
30
|
+
<% if show_action? -%>
|
29
31
|
describe 'GET #show' do
|
30
32
|
let(:<%= controller_class_name.singularize.underscore %>) { create(:<%= controller_class_name.singularize.underscore %>) }
|
31
33
|
let(:params) { { id: <%= controller_class_name.singularize.underscore %>.id } }
|
@@ -40,7 +42,9 @@ RSpec.describe <%= controller_class_name %>Controller do
|
|
40
42
|
it { expect(response.status).to eq 200 }
|
41
43
|
end
|
42
44
|
end
|
43
|
-
|
45
|
+
|
46
|
+
<% end -%>
|
47
|
+
<% if create_action? -%>
|
44
48
|
describe 'POST #create' do
|
45
49
|
let(:payload_params) { {text: 'OK'} }
|
46
50
|
let(:params) { { payload: payload_params, binaries: [{identifier: 'record', mimetype: 'video/mp4'}] } }
|
@@ -59,4 +63,5 @@ RSpec.describe <%= controller_class_name %>Controller do
|
|
59
63
|
<% end %>
|
60
64
|
end
|
61
65
|
end
|
66
|
+
<% end -%>
|
62
67
|
end
|
@@ -16,9 +16,21 @@ module MobileWorkflow::Cli
|
|
16
16
|
def rspec_generator
|
17
17
|
generate 'rspec:install'
|
18
18
|
end
|
19
|
+
|
20
|
+
def factory_bot
|
21
|
+
inject_into_file 'spec/rails_helper.rb', before: "end\n" do
|
22
|
+
"config.include FactoryBot::Syntax::Methods"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def migrate_db
|
27
|
+
rails_command("db:drop")
|
28
|
+
rails_command("db:create")
|
29
|
+
rails_command("db:migrate")
|
30
|
+
end
|
19
31
|
|
20
32
|
def administrate_generator
|
21
|
-
|
33
|
+
generate 'administrate:install'
|
22
34
|
|
23
35
|
file 'app/assets/config/manifest.js', <<-CODE
|
24
36
|
//= link administrate/application.css
|
@@ -33,7 +45,7 @@ module Admin
|
|
33
45
|
end
|
34
46
|
CODE
|
35
47
|
|
36
|
-
|
48
|
+
generate 'administrate:routes'
|
37
49
|
end
|
38
50
|
|
39
51
|
def ability_generator
|
@@ -51,9 +63,6 @@ CODE
|
|
51
63
|
gen_opts = ""
|
52
64
|
gen_opts += "--doorkeeper_oauth" if options[:doorkeeper_oauth]
|
53
65
|
generate "mobile_workflow:install #{gen_opts}"
|
54
|
-
|
55
|
-
# Copy user migrations if needed
|
56
|
-
rails_command 'mobile_workflow:install:migrations' if options[:doorkeeper_oauth]
|
57
66
|
end
|
58
67
|
|
59
68
|
def s3_backend(region)
|
@@ -76,6 +85,7 @@ CODE
|
|
76
85
|
heroku_backend.create
|
77
86
|
heroku_backend.configure_activestorage if options[:s3_storage]
|
78
87
|
heroku_backend.deploy
|
88
|
+
heroku_backend.seed_db
|
79
89
|
heroku_backend.sync_dotenv
|
80
90
|
end
|
81
91
|
|
@@ -33,10 +33,11 @@ module MobileWorkflow::Cli
|
|
33
33
|
after_bundle do
|
34
34
|
build :procfiles
|
35
35
|
build :rspec_generator
|
36
|
+
build :factory_bot
|
36
37
|
build :ability_generator
|
37
38
|
build :active_storage if options[:s3_storage]
|
38
39
|
build :mobile_workflow_generator, ARGV[1]
|
39
|
-
|
40
|
+
build :migrate_db
|
40
41
|
build :administrate_generator
|
41
42
|
|
42
43
|
generate_dot_env
|
@@ -57,14 +58,6 @@ module MobileWorkflow::Cli
|
|
57
58
|
# Todo: MBS - move these methods to the builder class
|
58
59
|
# Ideally override RailsBuilder methods
|
59
60
|
private
|
60
|
-
def setup_db
|
61
|
-
Bundler.with_unbundled_env do
|
62
|
-
rails_command("db:drop")
|
63
|
-
rails_command("db:create")
|
64
|
-
rails_command("db:migrate")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
61
|
def initial_git_commit
|
69
62
|
git add: "."
|
70
63
|
git commit: %Q{ -m 'Initial commit' }
|
@@ -21,9 +21,9 @@ module MobileWorkflow
|
|
21
21
|
end
|
22
22
|
@model_properties
|
23
23
|
end
|
24
|
-
|
25
|
-
def
|
26
|
-
@
|
24
|
+
|
25
|
+
def controller_name_to_actions
|
26
|
+
@controller_name_to_actions ||= parse_controller_names_to_actions
|
27
27
|
end
|
28
28
|
|
29
29
|
def paths
|
@@ -35,6 +35,22 @@ module MobileWorkflow
|
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
38
|
+
def parse_controller_names_to_actions
|
39
|
+
controllers = {}
|
40
|
+
paths.each do |path|
|
41
|
+
path_items = path.split('/')
|
42
|
+
controller_name = path_items[1]
|
43
|
+
controllers[controller_name] = [] unless controllers.key?(controller_name)
|
44
|
+
|
45
|
+
open_api_spec[:paths][path].keys.each do |method|
|
46
|
+
controllers[controller_name] << 'create' if path_items.count == 2 && method == 'post'
|
47
|
+
controllers[controller_name] << 'index' if path_items.count == 2 && method == 'get'
|
48
|
+
controllers[controller_name] << 'show' if path_items.count == 3 && method == 'get'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
controllers
|
52
|
+
end
|
53
|
+
|
38
54
|
def open_api_spec
|
39
55
|
@open_api_spec ||= read_openapi_spec
|
40
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobile_workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.9
|
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-01
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -103,7 +103,6 @@ files:
|
|
103
103
|
- app/views/layouts/mobile_workflow/application.html.erb
|
104
104
|
- bin/mwf
|
105
105
|
- config/routes.rb
|
106
|
-
- db/migrate/20200823174210_create_users.rb
|
107
106
|
- lib/generators/mobile_workflow/controller_generator.rb
|
108
107
|
- lib/generators/mobile_workflow/install/install_generator.rb
|
109
108
|
- lib/generators/mobile_workflow/install/templates/Gemfile.erb
|
@@ -112,13 +111,14 @@ files:
|
|
112
111
|
- lib/generators/mobile_workflow/install/templates/README.md.erb
|
113
112
|
- lib/generators/mobile_workflow/install/templates/ability.rb
|
114
113
|
- lib/generators/mobile_workflow/install/templates/api_controller.rb.erb
|
115
|
-
- lib/generators/mobile_workflow/install/templates/helpers/application_helper.rb
|
114
|
+
- lib/generators/mobile_workflow/install/templates/app/helpers/application_helper.rb
|
115
|
+
- lib/generators/mobile_workflow/install/templates/app/views/layouts/application.html.erb
|
116
|
+
- lib/generators/mobile_workflow/install/templates/app/views/sessions/new.html.erb
|
117
|
+
- lib/generators/mobile_workflow/install/templates/create_users.rb
|
116
118
|
- lib/generators/mobile_workflow/install/templates/seeds.rb.erb
|
117
119
|
- lib/generators/mobile_workflow/install/templates/sessions_controller.rb.erb
|
118
120
|
- lib/generators/mobile_workflow/install/templates/storage.s3.yml
|
119
121
|
- lib/generators/mobile_workflow/install/templates/user.rb.erb
|
120
|
-
- lib/generators/mobile_workflow/install/templates/views/layouts/application.html.erb
|
121
|
-
- lib/generators/mobile_workflow/install/templates/views/sessions/new.html.erb
|
122
122
|
- lib/generators/mobile_workflow/model_generator.rb
|
123
123
|
- lib/generators/mobile_workflow/templates/controller.rb.erb
|
124
124
|
- lib/generators/mobile_workflow/templates/controller_spec.rb.erb
|