mobile_workflow 0.6.2 → 0.6.8

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: c7aad19ae34447ff0513404bca010009eb92413363c1f4f996f3f10a2812163f
4
- data.tar.gz: 2c5199aa42f002fe72ea127d3d00b2b14df54461a6ed708ae662f1d0f94a0165
3
+ metadata.gz: 685158e15df7ff0f9d893db92dcb1446827e3a8ad61db0a18f76ca95904b4d29
4
+ data.tar.gz: 223f09dd75966eec26028fa1c17bdcc2ab7ddaf01a5c73a119817c22064b81f7
5
5
  SHA512:
6
- metadata.gz: acb8e199bc5db264b097e64b0f1541d3e6fe2f88a994b9ddd2224f5b9beece21dafc14fabafdba8a527ab35c9519aa5ef7fdfadb810c93f6a874ce7e371073cb
7
- data.tar.gz: b0e6e18c2493e1f4a903f4bab3af64ddb39b2e59898856c90e0968d8589c34a1912ac650edd0bdd36004d9a81299e7656f3de12c3593823e302d6af1d6d270c4
6
+ metadata.gz: ae81fb8cfc35faf25aacb35ecab0a46deb91c706c7c280aaa3b41d090dd9ff88a8c2480ce21d07c2f2e6190268c8fa7794dc4565ef441e488c19146ede830258
7
+ data.tar.gz: 99801e61d43ccf7d64a533b7c786001444359a7e3b244b4443805d588310de9f4dfa4b14979be40fa19867ecd70436cda26f308b840d1fe00157ba919158decc
@@ -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
@@ -33,29 +33,36 @@ module MobileWorkflow
33
33
  route "resources :sessions, only: [:new, :create]"
34
34
 
35
35
  # 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")
36
+ copy_file("app/views/layouts/application.html.erb")
37
+ copy_file("app/views/sessions/new.html.erb")
38
+ copy_file("app/helpers/application_helper.rb")
39
39
  end
40
40
 
41
41
  def generate_models
42
42
  say "Loading OpenAPI Spec: #{open_api_spec_path}"
43
43
  say "Generating models"
44
- model_name_to_properties.each_pair do |model_name, model_properties|
44
+ model_name_to_properties.each_pair do |model_name, model_properties|
45
+
46
+ if doorkeeper_oauth?
47
+ model_properties = "#{model_properties} user:references"
48
+ @model_name_to_properties[model_name] = model_properties
49
+ end
50
+
45
51
  if interactive? && !yes?("Use generated schema #{model_name}(#{model_properties})[yn]?")
46
52
  model_properties = ask "Specify schema for #{model_name}: (e.g. text:string image:attachment region:reference)"
53
+ @model_name_to_properties[model_name] = model_properties
47
54
  end
48
55
 
49
56
  generate_model(model_name, model_properties)
50
- @model_name_to_properties[model_name] = model_properties
51
57
  end
52
58
  end
53
59
 
54
60
  def generate_controllers_and_routes
55
61
  say "Generating controllers"
56
- route "root to: 'admin/#{open_api_spec.controller_names.first}#index'"
62
+ controller_name_to_actions = open_api_spec.controller_name_to_actions
63
+ route "root to: 'admin/#{controller_name_to_actions.keys.first}#index'"
57
64
 
58
- open_api_spec.controller_names.each do |plural_controller_name|
65
+ controller_name_to_actions.each_pair do |plural_controller_name, actions|
59
66
  controller_name = plural_controller_name.singularize
60
67
  model_properties = model_name_to_properties[controller_name]
61
68
 
@@ -66,8 +73,8 @@ module MobileWorkflow
66
73
  generate_model(controller_name, model_properties)
67
74
  end
68
75
 
69
- generate "mobile_workflow:controller #{controller_name} --attributes #{model_properties} #{s3_storage? ? '--s3-storage' : ''}".strip
70
- route "resources :#{plural_controller_name}, only: [:index, :show, :create]"
76
+ generate "mobile_workflow:controller #{controller_name} --actions #{actions.join(" ")} --attributes #{model_properties} #{s3_storage? ? '--s3-storage' : ''}".strip
77
+ route "resources :#{plural_controller_name}, only: [#{actions.map{|a| ":#{a}"}.join(", ")}]"
71
78
  end
72
79
  end
73
80
 
@@ -88,6 +95,10 @@ module MobileWorkflow
88
95
  def open_api_spec
89
96
  @open_api_spec ||= ::MobileWorkflow::OpenApiSpec::Parser.new(File.read(open_api_spec_path))
90
97
  end
98
+
99
+ def doorkeeper_oauth?
100
+ options[:doorkeeper_oauth]
101
+ end
91
102
 
92
103
  def s3_storage?
93
104
  options[:s3_storage]
@@ -4,22 +4,30 @@ 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
20
28
  <% else -%>
21
29
  render json: { response: @<%= singular_table_name %> }, status: :created
22
- <% end %>
30
+ <% end -%>
23
31
  else
24
32
  head :unprocessable_entity
25
33
  end
@@ -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
@@ -13,13 +13,13 @@ class <%= class_name %> < <%= parent_class_name.classify %>
13
13
  <% end -%>
14
14
 
15
15
  def list_item_as_json
16
- mw_list_item(text: text)
16
+ mw_list_item(text: <%= attributes.first.name %>)
17
17
  end
18
18
 
19
19
  def display_as_json
20
20
  [
21
21
  mw_display_text(label: 'ID', text: id.to_s),
22
- mw_display_text(label: 'Text', text: text)
22
+ mw_display_text(label: 'Text', text: <%= attributes.first.name %>)
23
23
  ]
24
24
  end
25
25
 
@@ -16,6 +16,12 @@ 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
19
25
 
20
26
  def administrate_generator
21
27
  Bundler.with_unbundled_env { generate 'administrate:install' }
@@ -76,6 +82,7 @@ CODE
76
82
  heroku_backend.create
77
83
  heroku_backend.configure_activestorage if options[:s3_storage]
78
84
  heroku_backend.deploy
85
+ heroku_backend.seed_db
79
86
  heroku_backend.sync_dotenv
80
87
  end
81
88
 
@@ -33,6 +33,7 @@ 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]
@@ -21,6 +21,10 @@ module MobileWorkflow::Cli
21
21
  def deploy
22
22
  heroku_command "git push"
23
23
  end
24
+
25
+ def seed_db
26
+ heroku_command "heroku run rails db:seed"
27
+ end
24
28
 
25
29
  def sync_dotenv
26
30
  env = File.read(".env").split.join(" ")
@@ -21,9 +21,9 @@ module MobileWorkflow
21
21
  end
22
22
  @model_properties
23
23
  end
24
-
25
- def controller_names
26
- @controller_names ||= paths.collect{|url_path| url_path.split('/')[1] }.uniq
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
@@ -1,5 +1,5 @@
1
1
  module MobileWorkflow
2
- VERSION = '0.6.2'
2
+ VERSION = '0.6.8'
3
3
  RUBY_VERSION = '2.7.2'
4
4
  RAILS_VERSION = '6.1.0'
5
5
  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.2
4
+ version: 0.6.8
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-27 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -112,13 +112,13 @@ files:
112
112
  - lib/generators/mobile_workflow/install/templates/README.md.erb
113
113
  - lib/generators/mobile_workflow/install/templates/ability.rb
114
114
  - lib/generators/mobile_workflow/install/templates/api_controller.rb.erb
115
- - lib/generators/mobile_workflow/install/templates/helpers/application_helper.rb
115
+ - lib/generators/mobile_workflow/install/templates/app/helpers/application_helper.rb
116
+ - lib/generators/mobile_workflow/install/templates/app/views/layouts/application.html.erb
117
+ - lib/generators/mobile_workflow/install/templates/app/views/sessions/new.html.erb
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