mobile_workflow 0.6.0 → 0.6.6

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: 74a57b5231432fa5532bc2757c6785604c833bf0b637770c15ea34faa41b3b13
4
- data.tar.gz: 33a6f90850d5e6fb2522d76012336899b585ab1b8fd7db6dc768018c12eeca2b
3
+ metadata.gz: bceba9fe508e85d21cd026ac5b26d49f06cec0eb18127a250745d902268b761b
4
+ data.tar.gz: 311c915a764228757fe6f16bfbf382fb6710092a77ad075670de8b1a6548bf45
5
5
  SHA512:
6
- metadata.gz: 54c3c9504079480aaba63c9974a17eb2c428254503568230ca058ad52a71119a0a6d469d30142cd7a41843b8757e4d24fcf94fccffeefe8fe06b5ab14e88b6a5
7
- data.tar.gz: 62a5f5d474522fa2ade3fdccfb5a7f84b66f02d0c612a998cb235baee27e09cb33f0c12fc82019a010cfabd666fd614c5b98710d3a149914ac889048746cd2fe
6
+ metadata.gz: 0df8bee9d328897f6b8b92448d0b8df828896b386fd4494453589f21c8321f1db5aef0497396e9f4b0d10430e6f8be57815a16bc84e05a4fef1cdaf2a58d8e54
7
+ data.tar.gz: e7e5ce8cb555596c9c6f856ecee3b553dab36159951b3012a4a74646353b3ffbca5d32deb69501599fae14fd1ff0916ac2a71c4a9289185b9c044ab68cf40b05
@@ -9,6 +9,7 @@ module MobileWorkflow
9
9
  class_option :attributes, type: :array, default: [], banner: "field:type field:type"
10
10
  class_option :actions, type: :array, default: [], banner: "index create update destroy"
11
11
  class_option :doorkeeper_oauth, type: :boolean, default: false
12
+ class_option :s3_storage, type: :boolean, default: false
12
13
 
13
14
  def copy_controller_and_spec_files
14
15
  template "controller.rb.erb", File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
@@ -20,6 +21,10 @@ module MobileWorkflow
20
21
  options[:doorkeeper_oauth]
21
22
  end
22
23
 
24
+ def s3_storage?
25
+ options[:s3_storage]
26
+ end
27
+
23
28
  def attributes_names
24
29
  options[:attributes].map{ |attribute| attribute.split(":").first }
25
30
  end
@@ -9,6 +9,7 @@ module MobileWorkflow
9
9
 
10
10
  class_option :open_api_spec_path, type: :string, default: "config/open_api_spec.json"
11
11
  class_option :doorkeeper_oauth, type: :boolean, default: false
12
+ class_option :s3_storage, type: :boolean, default: false
12
13
  class_option :interactive, type: :boolean, default: false
13
14
 
14
15
  def create_api_controller
@@ -32,9 +33,9 @@ module MobileWorkflow
32
33
  route "resources :sessions, only: [:new, :create]"
33
34
 
34
35
  # View related for login screen
35
- copy_file("views/layouts/application.html.erb")
36
- copy_file("views/sessions/new.html.erb")
37
- 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")
38
39
  end
39
40
 
40
41
  def generate_models
@@ -52,9 +53,10 @@ module MobileWorkflow
52
53
 
53
54
  def generate_controllers_and_routes
54
55
  say "Generating controllers"
55
- route "root to: 'admin/#{open_api_spec.controller_names.first}#index'"
56
+ controller_name_to_actions = open_api_spec.controller_name_to_actions
57
+ route "root to: 'admin/#{controller_name_to_actions.keys.first}#index'"
56
58
 
57
- open_api_spec.controller_names.each do |plural_controller_name|
59
+ controller_name_to_actions.each_pair do |plural_controller_name, actions|
58
60
  controller_name = plural_controller_name.singularize
59
61
  model_properties = model_name_to_properties[controller_name]
60
62
 
@@ -65,8 +67,8 @@ module MobileWorkflow
65
67
  generate_model(controller_name, model_properties)
66
68
  end
67
69
 
68
- generate "mobile_workflow:controller #{controller_name} --attributes #{model_properties}"
69
- route "resources :#{plural_controller_name}, only: [:index, :show, :create]"
70
+ generate "mobile_workflow:controller #{controller_name} #{actions.join(" ")} --attributes #{model_properties} #{s3_storage? ? '--s3-storage' : ''}".strip
71
+ route "resources :#{plural_controller_name}, only: [#{actions.map{|a| ":#{a}"}.join(", ")}]"
70
72
  end
71
73
  end
72
74
 
@@ -88,6 +90,10 @@ module MobileWorkflow
88
90
  @open_api_spec ||= ::MobileWorkflow::OpenApiSpec::Parser.new(File.read(open_api_spec_path))
89
91
  end
90
92
 
93
+ def s3_storage?
94
+ options[:s3_storage]
95
+ end
96
+
91
97
  def open_api_spec_path
92
98
  options[:open_api_spec_path]
93
99
  end
@@ -1,6 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= controller_class_name %>Controller < ApiController
3
- # include MobileWorkflow::S3Storable
3
+ <%= s3_storage? ? "include MobileWorkflow::S3Storable" : "" %>
4
4
  before_action :rewrite_payload, only: :create
5
5
 
6
6
  load_and_authorize_resource
@@ -15,7 +15,11 @@ class <%= controller_class_name %>Controller < ApiController
15
15
 
16
16
  def create
17
17
  if @<%= singular_table_name %>.save
18
+ <% if s3_storage? -%>
18
19
  render json: { binary_urls: binary_urls(@<%= singular_table_name %>), response: @<%= singular_table_name %> }, status: :created
20
+ <% else -%>
21
+ render json: { response: @<%= singular_table_name %> }, status: :created
22
+ <% end -%>
19
23
  else
20
24
  head :unprocessable_entity
21
25
  end
@@ -54,7 +54,9 @@ RSpec.describe <%= controller_class_name %>Controller do
54
54
  context 'ok' do
55
55
  it { expect(<%= controller_class_name.singularize %>.count).to eq 1 }
56
56
  it { expect(response.status).to eq 201 }
57
+ <% if s3_storage? -%>
57
58
  it { expect(json_response[:binary_urls]).to_not be_nil }
59
+ <% end %>
58
60
  end
59
61
  end
60
62
  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' }
@@ -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,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.0'
2
+ VERSION = '0.6.6'
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.0
4
+ version: 0.6.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-01-24 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