mobile_workflow 0.6.9 → 0.6.14

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: 913509d1248a7a63226904e313ba1e56c700df9b95f0e393bb642d8f512c94b5
4
- data.tar.gz: f1718f9a7e22d33c90ff546215c3ed6047118fca4148ccff6344ec34bedb375c
3
+ metadata.gz: 799110824fce9c1897c4418e504215c23e19a29107dc3833d3b44ef633ffd695
4
+ data.tar.gz: a8606dc9b5b382ffff495fb7eecd20b17b737f4c5234821318402222f677c419
5
5
  SHA512:
6
- metadata.gz: 2bc79973227c2db3e308c4329076ea441364ed7c65f2b095fabb201e23fedd2d736883c872ed051aa0ee17e2a94e626f4a99c3dbb95a058d8dbf568dc9d25a05
7
- data.tar.gz: 5689ffc81f5df062ac81e25fdbe04da2986c10e434ba5bc9ce27d502381a3fbc63da5c8d8ffa698e4d85571b56ea3b74a0e26936c9178874dd66e60b773aa50a
6
+ metadata.gz: 611d110892aa6a03b97c6aa7d0ce9ba3e7aaa810eaf05b313ca7db18b8260b76cadfb3ac64f9af972b8f12759eb10ce21cc65258b8047226155e2238da14cc3d
7
+ data.tar.gz: fa196418587eae7166549b881cfea04b89b9539738c39c0f6c159e4de450c480d5a8d14c88530c0527ec4b135fd0c803622ae367a235299314d2826da084bddd
@@ -4,20 +4,27 @@ module MobileWorkflow
4
4
  include Rails.application.routes.url_helpers
5
5
 
6
6
  ON_SUCCESS_OPTIONS = [:none, :reload, :backward, :forward]
7
- BUTTON_STYLES = [:primary, :outline, :danger]
8
-
7
+ BUTTON_STYLES = [:primary, :outline, :danger]
8
+ CONTENT_MODE_OPTIONS = [:scale_aspect_fill, :scale_aspect_fit]
9
+
9
10
  def mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, image_attachment: nil)
10
11
  mw_list_item = {id: id, text: text, detailText: detail_text, sfSymbolName: sf_symbol_name}
11
12
  mw_list_item[:imageURL] = preview_url(image_attachment, options: { resize_to_fill: [100, 100] }) if image_attachment
12
- mw_list_item.compact
13
+ mw_list_item.compact
14
+ end
15
+
16
+ def mw_map_item(id: self.id, text:, detail_text: nil, latitude:, longitude:)
17
+ {id: id, text: text, detailText: detail_text, latitude: latitude, longitude: longitude}.compact
13
18
  end
14
19
 
15
20
  def mw_display_text(text:, label: nil)
16
21
  {type: :text, label: label, text: text.to_s}.compact
17
22
  end
18
23
 
19
- def mw_display_image(attachment, options: { resize_to_fill: [600, 1200] })
20
- {type: :image, previewURL: preview_url(attachment, options: options), url: attachment_url(attachment)}
24
+ def mw_display_image(attachment, content_mode: :scale_aspect_fill, options: { resize_to_fill: [600, 1200] })
25
+ validate_content_mode!(content_mode)
26
+
27
+ {type: :image, contentMode: content_mode.to_s.camelize(:lower), previewURL: preview_url(attachment, options: options), url: attachment_url(attachment)}
21
28
  end
22
29
 
23
30
  def mw_display_unsplash_image(image_url)
@@ -54,6 +61,13 @@ module MobileWorkflow
54
61
  {type: :button, label: label, url: url, method: method, style: style, onSuccess: on_success}
55
62
  end
56
63
 
64
+ def mw_display_button_for_system_url(label:, apple_system_url:, method: :put, style: :primary, on_success: :none)
65
+ validate_on_success!(on_success)
66
+ validate_button_style!(style)
67
+
68
+ {type: :button, label: label, appleSystemURL: apple_system_url, method: method, style: style, onSuccess: on_success}
69
+ end
70
+
57
71
  def mw_display_button_for_modal_workflow(label:, modal_workflow_name:, style: :primary, on_success: :none)
58
72
  validate_on_success!(on_success)
59
73
  validate_button_style!(style)
@@ -66,6 +80,10 @@ module MobileWorkflow
66
80
  raise 'Unknown on_success action' unless ON_SUCCESS_OPTIONS.include?(on_success)
67
81
  end
68
82
 
83
+ def validate_content_mode!(on_success)
84
+ raise 'Unknown content_mode' unless CONTENT_MODE_OPTIONS.include?(on_success)
85
+ end
86
+
69
87
  def validate_button_style!(style)
70
88
  raise 'Unknown style' unless BUTTON_STYLES.include?(style)
71
89
  end
@@ -30,8 +30,9 @@ module MobileWorkflow
30
30
  end
31
31
 
32
32
  def permitted_params
33
- params = attributes_names.map{ |name| ":#{name}" }
34
- params.join(", ")
33
+ permitted_attributes = attributes_names.dup
34
+ permitted_attributes.delete('user')
35
+ permitted_attributes.map{ |name| ":#{name}" }.join(", ")
35
36
  end
36
37
 
37
38
  def index_action?
@@ -24,6 +24,10 @@ module MobileWorkflow
24
24
  route "mount MobileWorkflow::Engine => '/'"
25
25
  end
26
26
 
27
+ def copy_rake_tasks
28
+ copy_file("lib/tasks/mobile_workflow_doorkeeper.rake") if options[:doorkeeper_oauth]
29
+ end
30
+
27
31
  def generate_doorkeeper
28
32
  return unless options[:doorkeeper_oauth]
29
33
  say "Generating Doorkeeper OAuth"
@@ -42,6 +46,7 @@ module MobileWorkflow
42
46
  copy_file("app/views/layouts/application.html.erb")
43
47
  copy_file("app/views/sessions/new.html.erb")
44
48
  copy_file("app/helpers/application_helper.rb")
49
+ copy_file("spec/factories/users.rb")
45
50
  end
46
51
 
47
52
  def generate_models
@@ -79,7 +84,7 @@ module MobileWorkflow
79
84
  generate_model(controller_name, model_properties)
80
85
  end
81
86
 
82
- generate "mobile_workflow:controller #{controller_name} --actions #{actions.join(" ")} --attributes #{model_properties} #{s3_storage? ? '--s3-storage' : ''}".strip
87
+ generate "mobile_workflow:controller #{controller_name} --actions #{actions.join(" ")} --attributes #{model_properties} #{generate_controller_args}".strip
83
88
  route "resources :#{plural_controller_name}, only: [#{actions.map{|a| ":#{a}"}.join(", ")}]"
84
89
  end
85
90
  end
@@ -94,6 +99,13 @@ module MobileWorkflow
94
99
  generate("mobile_workflow:model #{model_name} #{model_properties}")
95
100
  end
96
101
 
102
+ def generate_controller_args
103
+ args = ''
104
+ args += ' --s3-storage' if s3_storage?
105
+ args += ' --doorkeeper-oauth' if doorkeeper_oauth?
106
+ args.strip
107
+ end
108
+
97
109
  def model_name_to_properties
98
110
  @model_name_to_properties ||= open_api_spec.model_name_to_properties
99
111
  end
@@ -45,6 +45,7 @@ group :development, :test do
45
45
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
46
46
  gem 'dotenv-rails'
47
47
  gem 'factory_bot_rails'
48
+ gem "rufo"
48
49
  end
49
50
 
50
51
  group :production do
@@ -0,0 +1,5 @@
1
+ desc "Log the first Doorkeeper App details"
2
+ task print_oauth_app: :environment do
3
+ puts Doorkeeper::Application.first.uid
4
+ puts Doorkeeper::Application.first.secret
5
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :user do
3
+ sequence(:email) { |n| "person#{n}@example.com" }
4
+ password { 'Password123' }
5
+ end
6
+ end
@@ -20,7 +20,7 @@ class <%= controller_class_name %>Controller < ApiController
20
20
  <% if create_action? -%>
21
21
  def create
22
22
  <% if doorkeeper_oauth? -%>
23
- @<%= singular_table_name %> = current_user
23
+ @<%= singular_table_name %>.user = current_user
24
24
  <% end -%>
25
25
  if @<%= singular_table_name %>.save
26
26
  <% if s3_storage? -%>
@@ -29,7 +29,7 @@ class <%= controller_class_name %>Controller < ApiController
29
29
  render json: { response: @<%= singular_table_name %> }, status: :created
30
30
  <% end -%>
31
31
  else
32
- head :unprocessable_entity
32
+ render json: { message: @<%= singular_table_name %>.errors.full_messages.to_sentence }, status: :unprocessable_entity
33
33
  end
34
34
  end
35
35
 
@@ -8,7 +8,7 @@ RSpec.describe <%= controller_class_name %>Controller do
8
8
  let(:json_response) { JSON.parse(response.body, symbolize_names: true) }
9
9
  <% if doorkeeper_oauth? -%>
10
10
  let(:user) { create(:user) }
11
- let(:token) { instance_double('Doorkeeper::AccessToken', :accessible? => true, :acceptable? => true, resource_owner_id: user.id) }
11
+ let(:token) { instance_double(Doorkeeper::AccessToken, accessible?: true, acceptable?: true, resource_owner_id: user.id) }
12
12
  <% end -%>
13
13
 
14
14
  <% if index_action? -%>
@@ -18,8 +18,8 @@ module MobileWorkflow::Cli
18
18
  end
19
19
 
20
20
  def factory_bot
21
- inject_into_file 'spec/rails_helper.rb', before: "end\n" do
22
- "config.include FactoryBot::Syntax::Methods"
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
25
 
@@ -65,6 +65,25 @@ CODE
65
65
  generate "mobile_workflow:install #{gen_opts}"
66
66
  end
67
67
 
68
+ def format_source
69
+ `rufo .`
70
+ end
71
+
72
+ def generate_dot_env
73
+ admin_user = 'admin'
74
+ admin_password = SecureRandom.base64(12)
75
+
76
+ file '.env', <<-CODE
77
+ ADMIN_USER=#{admin_user}
78
+ ADMIN_PASSWORD=#{admin_password}
79
+ CODE
80
+ end
81
+
82
+ def git_commit(message = 'Initial commit')
83
+ git add: "."
84
+ git commit: %Q{ -m '#{message}'}
85
+ end
86
+
68
87
  def s3_backend(region)
69
88
  @region = region
70
89
  aws_backend.create
@@ -39,10 +39,9 @@ module MobileWorkflow::Cli
39
39
  build :mobile_workflow_generator, ARGV[1]
40
40
  build :migrate_db
41
41
  build :administrate_generator
42
-
43
- generate_dot_env
44
- initial_git_commit
45
-
42
+ build :format_source
43
+ build :generate_dot_env
44
+ build :git_commit
46
45
  build :heroku if options[:heroku]
47
46
  build :dokku, options[:dokku_host] if options[:dokku]
48
47
  build :s3_backend, options[:aws_region] if options[:s3_storage]
@@ -55,22 +54,5 @@ module MobileWorkflow::Cli
55
54
  ::MobileWorkflow::Cli::AppBuilder
56
55
  end
57
56
 
58
- # Todo: MBS - move these methods to the builder class
59
- # Ideally override RailsBuilder methods
60
- private
61
- def initial_git_commit
62
- git add: "."
63
- git commit: %Q{ -m 'Initial commit' }
64
- end
65
-
66
- def generate_dot_env
67
- admin_user = 'admin'
68
- admin_password = SecureRandom.base64(12)
69
-
70
- file '.env', <<-CODE
71
- ADMIN_USER=#{admin_user}
72
- ADMIN_PASSWORD=#{admin_password}
73
- CODE
74
- end
75
57
  end
76
58
  end
@@ -5,7 +5,7 @@ module MobileWorkflow::Cli
5
5
 
6
6
  attr_accessor :access_id, :secret_key, :region, :bucket_name
7
7
 
8
- def initialize(app_name:, region:)
8
+ def initialize(app_name:, region: 'us-east-1')
9
9
  @app_name = app_name
10
10
  @aws_name = @app_name.gsub("_", "-")
11
11
  @region = region
@@ -1,5 +1,5 @@
1
1
  module MobileWorkflow
2
- VERSION = '0.6.9'
2
+ VERSION = '0.6.14'
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.9
4
+ version: 0.6.14
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-02-01 00:00:00.000000000 Z
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -115,8 +115,10 @@ files:
115
115
  - lib/generators/mobile_workflow/install/templates/app/views/layouts/application.html.erb
116
116
  - lib/generators/mobile_workflow/install/templates/app/views/sessions/new.html.erb
117
117
  - lib/generators/mobile_workflow/install/templates/create_users.rb
118
+ - lib/generators/mobile_workflow/install/templates/lib/tasks/mobile_workflow_doorkeeper.rake
118
119
  - lib/generators/mobile_workflow/install/templates/seeds.rb.erb
119
120
  - lib/generators/mobile_workflow/install/templates/sessions_controller.rb.erb
121
+ - lib/generators/mobile_workflow/install/templates/spec/factories/users.rb
120
122
  - lib/generators/mobile_workflow/install/templates/storage.s3.yml
121
123
  - lib/generators/mobile_workflow/install/templates/user.rb.erb
122
124
  - lib/generators/mobile_workflow/model_generator.rb