mobile_workflow 0.6.4 → 0.6.10
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 +19 -2
- data/lib/generators/mobile_workflow/install/install_generator.rb +34 -9
- data/lib/generators/mobile_workflow/install/templates/Gemfile.erb +1 -0
- 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/install/templates/spec/factories/users.rb +6 -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 -7
- 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 +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e72adcc8d3a21ec01476098c7f16fe849c2ab8348f0164fe15ffde1872b156
|
4
|
+
data.tar.gz: 5c361e5591040d4a5636aa425dbf77ec533cddbad38e150a6f1f94a1fdca360e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b66dbaa49b726bc92618c6405af04e3cac7476809ffafeda4d7d444ec3275a993fae2c4a4b6c534ecd5569467c3c8fb4402c97a7b96d1238d1f0c5c34190148
|
7
|
+
data.tar.gz: 67bd8a5575e05e1ec46653b42eadf089a81c05e64ea0c1e6f9702b6e0621e9fd6212e577f13ccbf085a299f53fd1bf288df2db01fd46b2b52d9a748f07aa0518
|
@@ -30,8 +30,25 @@ module MobileWorkflow
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def permitted_params
|
33
|
-
|
34
|
-
|
33
|
+
permitted_attributes = attributes_names.dup
|
34
|
+
permitted_attributes.delete('user')
|
35
|
+
permitted_attributes.map{ |name| ":#{name}" }.join(", ")
|
36
|
+
end
|
37
|
+
|
38
|
+
def index_action?
|
39
|
+
actions.include?("index")
|
40
|
+
end
|
41
|
+
|
42
|
+
def show_action?
|
43
|
+
actions.include?("show")
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_action?
|
47
|
+
actions.include?("create")
|
48
|
+
end
|
49
|
+
|
50
|
+
def actions
|
51
|
+
options[:actions]
|
35
52
|
end
|
36
53
|
end
|
37
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,37 @@ 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")
|
45
|
+
copy_file("spec/factories/users.rb")
|
39
46
|
end
|
40
47
|
|
41
48
|
def generate_models
|
42
49
|
say "Loading OpenAPI Spec: #{open_api_spec_path}"
|
43
50
|
say "Generating models"
|
44
|
-
model_name_to_properties.each_pair do |model_name, model_properties|
|
51
|
+
model_name_to_properties.each_pair do |model_name, model_properties|
|
52
|
+
|
53
|
+
if doorkeeper_oauth?
|
54
|
+
model_properties = "#{model_properties} user:references"
|
55
|
+
@model_name_to_properties[model_name] = model_properties
|
56
|
+
end
|
57
|
+
|
45
58
|
if interactive? && !yes?("Use generated schema #{model_name}(#{model_properties})[yn]?")
|
46
59
|
model_properties = ask "Specify schema for #{model_name}: (e.g. text:string image:attachment region:reference)"
|
60
|
+
@model_name_to_properties[model_name] = model_properties
|
47
61
|
end
|
48
62
|
|
49
63
|
generate_model(model_name, model_properties)
|
50
|
-
@model_name_to_properties[model_name] = model_properties
|
51
64
|
end
|
52
65
|
end
|
53
66
|
|
54
67
|
def generate_controllers_and_routes
|
55
68
|
say "Generating controllers"
|
56
|
-
|
69
|
+
controller_name_to_actions = open_api_spec.controller_name_to_actions
|
70
|
+
route "root to: 'admin/#{controller_name_to_actions.keys.first}#index'"
|
57
71
|
|
58
|
-
|
72
|
+
controller_name_to_actions.each_pair do |plural_controller_name, actions|
|
59
73
|
controller_name = plural_controller_name.singularize
|
60
74
|
model_properties = model_name_to_properties[controller_name]
|
61
75
|
|
@@ -66,8 +80,8 @@ module MobileWorkflow
|
|
66
80
|
generate_model(controller_name, model_properties)
|
67
81
|
end
|
68
82
|
|
69
|
-
generate "mobile_workflow:controller #{controller_name} --attributes #{model_properties} #{
|
70
|
-
route "resources :#{plural_controller_name}, only: [
|
83
|
+
generate "mobile_workflow:controller #{controller_name} --actions #{actions.join(" ")} --attributes #{model_properties} #{generate_controller_args}".strip
|
84
|
+
route "resources :#{plural_controller_name}, only: [#{actions.map{|a| ":#{a}"}.join(", ")}]"
|
71
85
|
end
|
72
86
|
end
|
73
87
|
|
@@ -81,6 +95,13 @@ module MobileWorkflow
|
|
81
95
|
generate("mobile_workflow:model #{model_name} #{model_properties}")
|
82
96
|
end
|
83
97
|
|
98
|
+
def generate_controller_args
|
99
|
+
args = ''
|
100
|
+
args += ' --s3-storage' if s3_storage?
|
101
|
+
args += ' --doorkeeper-oauth' if doorkeeper_oauth?
|
102
|
+
args.strip
|
103
|
+
end
|
104
|
+
|
84
105
|
def model_name_to_properties
|
85
106
|
@model_name_to_properties ||= open_api_spec.model_name_to_properties
|
86
107
|
end
|
@@ -88,6 +109,10 @@ module MobileWorkflow
|
|
88
109
|
def open_api_spec
|
89
110
|
@open_api_spec ||= ::MobileWorkflow::OpenApiSpec::Parser.new(File.read(open_api_spec_path))
|
90
111
|
end
|
112
|
+
|
113
|
+
def doorkeeper_oauth?
|
114
|
+
options[:doorkeeper_oauth]
|
115
|
+
end
|
91
116
|
|
92
117
|
def s3_storage?
|
93
118
|
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 %>.user = 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
|
@@ -18,13 +18,19 @@ module MobileWorkflow::Cli
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def factory_bot
|
21
|
-
inject_into_file 'spec/rails_helper.rb',
|
22
|
-
"
|
21
|
+
inject_into_file 'spec/rails_helper.rb', after: "RSpec.configure do |config|\n" do
|
22
|
+
"\tconfig.include FactoryBot::Syntax::Methods\n"
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
def migrate_db
|
27
|
+
rails_command("db:drop")
|
28
|
+
rails_command("db:create")
|
29
|
+
rails_command("db:migrate")
|
30
|
+
end
|
25
31
|
|
26
32
|
def administrate_generator
|
27
|
-
|
33
|
+
generate 'administrate:install'
|
28
34
|
|
29
35
|
file 'app/assets/config/manifest.js', <<-CODE
|
30
36
|
//= link administrate/application.css
|
@@ -39,7 +45,7 @@ module Admin
|
|
39
45
|
end
|
40
46
|
CODE
|
41
47
|
|
42
|
-
|
48
|
+
generate 'administrate:routes'
|
43
49
|
end
|
44
50
|
|
45
51
|
def ability_generator
|
@@ -57,9 +63,10 @@ CODE
|
|
57
63
|
gen_opts = ""
|
58
64
|
gen_opts += "--doorkeeper_oauth" if options[:doorkeeper_oauth]
|
59
65
|
generate "mobile_workflow:install #{gen_opts}"
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
end
|
67
|
+
|
68
|
+
def format_source
|
69
|
+
run 'rufo .'
|
63
70
|
end
|
64
71
|
|
65
72
|
def s3_backend(region)
|
@@ -82,6 +89,7 @@ CODE
|
|
82
89
|
heroku_backend.create
|
83
90
|
heroku_backend.configure_activestorage if options[:s3_storage]
|
84
91
|
heroku_backend.deploy
|
92
|
+
heroku_backend.seed_db
|
85
93
|
heroku_backend.sync_dotenv
|
86
94
|
end
|
87
95
|
|
@@ -37,8 +37,9 @@ module MobileWorkflow::Cli
|
|
37
37
|
build :ability_generator
|
38
38
|
build :active_storage if options[:s3_storage]
|
39
39
|
build :mobile_workflow_generator, ARGV[1]
|
40
|
-
|
40
|
+
build :migrate_db
|
41
41
|
build :administrate_generator
|
42
|
+
build :format_source
|
42
43
|
|
43
44
|
generate_dot_env
|
44
45
|
initial_git_commit
|
@@ -58,14 +59,6 @@ module MobileWorkflow::Cli
|
|
58
59
|
# Todo: MBS - move these methods to the builder class
|
59
60
|
# Ideally override RailsBuilder methods
|
60
61
|
private
|
61
|
-
def setup_db
|
62
|
-
Bundler.with_unbundled_env do
|
63
|
-
rails_command("db:drop")
|
64
|
-
rails_command("db:create")
|
65
|
-
rails_command("db:migrate")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
62
|
def initial_git_commit
|
70
63
|
git add: "."
|
71
64
|
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.10
|
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,15 @@ 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
|
120
|
+
- lib/generators/mobile_workflow/install/templates/spec/factories/users.rb
|
118
121
|
- lib/generators/mobile_workflow/install/templates/storage.s3.yml
|
119
122
|
- 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
123
|
- lib/generators/mobile_workflow/model_generator.rb
|
123
124
|
- lib/generators/mobile_workflow/templates/controller.rb.erb
|
124
125
|
- lib/generators/mobile_workflow/templates/controller_spec.rb.erb
|