mobile_workflow 0.5.11 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24e4161405736a8da53f830ee7f46f84a58930a3f4d7e5fd28456005f4d1f99f
4
- data.tar.gz: 9f13aa23db9a97150e0c0bd9c3a64b6b5161460df709c14a56a2af87ce3db784
3
+ metadata.gz: 74a57b5231432fa5532bc2757c6785604c833bf0b637770c15ea34faa41b3b13
4
+ data.tar.gz: 33a6f90850d5e6fb2522d76012336899b585ab1b8fd7db6dc768018c12eeca2b
5
5
  SHA512:
6
- metadata.gz: 2e6056e6a06c99156d2106114ea885caedf5eb5ec83d62a02469aa645b7fb2498ab4ccf5fcc73bd1de5def857f64b8532fc65e669c870ed073d865e7c228d7e5
7
- data.tar.gz: 8e6fc1fd000da48eddc130b84dec03ee8c1db5a0a1e95a5783d544a0fd720e364800b2c9b8cd769e222817a1304e4d32892664b61e159ae63c5520f1be132e71
6
+ metadata.gz: 54c3c9504079480aaba63c9974a17eb2c428254503568230ca058ad52a71119a0a6d469d30142cd7a41843b8757e4d24fcf94fccffeefe8fe06b5ab14e88b6a5
7
+ data.tar.gz: 62a5f5d474522fa2ade3fdccfb5a7f84b66f02d0c612a998cb235baee27e09cb33f0c12fc82019a010cfabd666fd614c5b98710d3a149914ac889048746cd2fe
@@ -1,12 +1,10 @@
1
1
  require "rails/generators/base"
2
+ require "mobile_workflow/open_api_spec/parser"
2
3
 
3
4
  module MobileWorkflow
4
5
  module Generators
5
6
  class InstallGenerator < Rails::Generators::Base
6
7
 
7
- # Schemas to avoid generating models for (static items from MW)
8
- SKIP_SCHEMAS = ["attachment", "ListItem", "DisplayItem", "DisplayText", "DisplayButton", "DisplayImage", "DisplayVideo"]
9
-
10
8
  source_root File.expand_path("../templates", __FILE__)
11
9
 
12
10
  class_option :open_api_spec_path, type: :string, default: "config/open_api_spec.json"
@@ -40,25 +38,33 @@ module MobileWorkflow
40
38
  end
41
39
 
42
40
  def generate_models
41
+ say "Loading OpenAPI Spec: #{open_api_spec_path}"
43
42
  say "Generating models"
44
- @model_properties = {}
45
- open_api_spec[:components][:schemas].each_pair do |model_name, schema|
46
- next if SKIP_SCHEMAS.include? model_name # Don't generate schemas for MW schemas
47
-
48
- model_name = model_name.underscore
49
- model_properties = model_properties(model_name, schema)
50
- generate(:model, "#{model_name} #{model_properties}")
51
- @model_properties[model_name] = model_properties
43
+ model_name_to_properties.each_pair do |model_name, model_properties|
44
+ if interactive? && !yes?("Use generated schema #{model_name}(#{model_properties})[yn]?")
45
+ model_properties = ask "Specify schema for #{model_name}: (e.g. text:string image:attachment region:reference)"
46
+ end
47
+
48
+ generate_model(model_name, model_properties)
49
+ @model_name_to_properties[model_name] = model_properties
52
50
  end
53
51
  end
54
52
 
55
53
  def generate_controllers_and_routes
56
54
  say "Generating controllers"
57
- route "root to: 'admin/#{controller_names.first}#index'"
55
+ route "root to: 'admin/#{open_api_spec.controller_names.first}#index'"
58
56
 
59
- controller_names.each do |plural_controller_name|
57
+ open_api_spec.controller_names.each do |plural_controller_name|
60
58
  controller_name = plural_controller_name.singularize
61
- model_properties = @model_properties[controller_name]
59
+ model_properties = model_name_to_properties[controller_name]
60
+
61
+ unless model_properties
62
+ # Generate a model because it probably wasnt present in the schema
63
+ # And set default attributes
64
+ model_properties = "text:string"
65
+ generate_model(controller_name, model_properties)
66
+ end
67
+
62
68
  generate "mobile_workflow:controller #{controller_name} --attributes #{model_properties}"
63
69
  route "resources :#{plural_controller_name}, only: [:index, :show, :create]"
64
70
  end
@@ -69,21 +75,17 @@ module MobileWorkflow
69
75
  end
70
76
 
71
77
  private
72
- def controller_names
73
- @controller_names ||= oai_spec_paths.collect{|url_path| url_path.split('/')[1] }.uniq
74
- end
75
78
 
76
- def oai_spec_paths
77
- @oai_spec_paths ||= open_api_spec[:paths].keys
79
+ def generate_model(model_name, model_properties)
80
+ generate("mobile_workflow:model #{model_name} #{model_properties}")
78
81
  end
79
82
 
80
- def open_api_spec
81
- @open_api_spec ||= read_openapi_spec
83
+ def model_name_to_properties
84
+ @model_name_to_properties ||= open_api_spec.model_name_to_properties
82
85
  end
83
86
 
84
- def read_openapi_spec
85
- say "Loading OpenAPI Spec: #{open_api_spec_path}"
86
- return JSON.parse(File.read(open_api_spec_path)).with_indifferent_access
87
+ def open_api_spec
88
+ @open_api_spec ||= ::MobileWorkflow::OpenApiSpec::Parser.new(File.read(open_api_spec_path))
87
89
  end
88
90
 
89
91
  def open_api_spec_path
@@ -93,22 +95,6 @@ module MobileWorkflow
93
95
  def interactive?
94
96
  options[:interactive]
95
97
  end
96
-
97
- def model_properties(name, schema)
98
- generated_properties_args = schema["properties"].keys.collect{|key| "#{key}:#{model_property_type(schema["properties"][key])}" }.join(" ")
99
- if !interactive? || yes?("Use generated schema #{name}(#{generated_properties_args})[yn]?")
100
- generated_properties_args
101
- else
102
- ask "Specify schema for #{name}: (e.g. text:string image:attachment region:reference)"
103
- end
104
- end
105
-
106
- def model_property_type(property)
107
- return property["type"] unless property["type"].blank?
108
- return 'attachment' if property['$ref'] == "#/components/schemas/attachment"
109
-
110
- raise 'Unknown property type'
111
- end
112
98
  end
113
99
  end
114
100
  end
@@ -31,6 +31,9 @@ gem 'aws-sdk-s3', '~> 1.60', '>= 1.60.1'
31
31
  gem 'aws-sdk-sns', '~> 1.23'
32
32
  <%- end %>
33
33
 
34
+ # FFI for Mac M1
35
+ gem 'ffi', github: 'ffi/ffi'
36
+
34
37
  group :development do
35
38
  gem 'web-console', '>= 3.3.0'
36
39
  gem 'listen', '>= 3.0.5', '< 3.2'
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/active_record/model/model_generator'
2
+
3
+ module MobileWorkflow
4
+ module Generators
5
+
6
+ class ModelGenerator < ActiveRecord::Generators::ModelGenerator
7
+ source_root File.join(File.dirname(ActiveRecord::Generators::ModelGenerator.instance_method(:create_migration_file).source_location.first), "templates")
8
+
9
+ def create_model_file
10
+ template File.join(File.dirname(__FILE__), "templates", "model.rb.erb"), File.join('app/models', class_path, "#{file_name}.rb")
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -17,7 +17,10 @@ class <%= class_name %> < <%= parent_class_name.classify %>
17
17
  end
18
18
 
19
19
  def display_as_json
20
- [mw_display_text(label: 'ID', text: id.to_s)]
20
+ [
21
+ mw_display_text(label: 'ID', text: id.to_s),
22
+ mw_display_text(label: 'Text', text: text)
23
+ ]
21
24
  end
22
25
 
23
26
  end
@@ -0,0 +1,59 @@
1
+ module MobileWorkflow
2
+ module OpenApiSpec
3
+ class Parser
4
+
5
+ # Schemas to avoid generating models for (static items from MW)
6
+ SKIP_SCHEMAS = ["attachment", "ListItem", "DisplayItem", "DisplayText", "DisplayButton", "DisplayImage", "DisplayVideo"]
7
+
8
+ def initialize(open_api_spec_string)
9
+ @open_api_spec_string = open_api_spec_string
10
+ end
11
+
12
+ def model_name_to_properties
13
+ @model_properties = {}
14
+ schemas.each_pair do |model_name, schema|
15
+ next if SKIP_SCHEMAS.include? model_name # Don't generate schemas for MW schemas
16
+
17
+ model_name = model_name.underscore
18
+ model_properties = schema_model_properties(model_name, schema)
19
+
20
+ @model_properties[model_name] = model_properties
21
+ end
22
+ @model_properties
23
+ end
24
+
25
+ def controller_names
26
+ @controller_names ||= paths.collect{|url_path| url_path.split('/')[1] }.uniq
27
+ end
28
+
29
+ def paths
30
+ @paths ||= open_api_spec[:paths].keys
31
+ end
32
+
33
+ def schemas
34
+ @schemas ||= open_api_spec[:components][:schemas]
35
+ end
36
+
37
+ private
38
+ def open_api_spec
39
+ @open_api_spec ||= read_openapi_spec
40
+ end
41
+
42
+ def schema_model_properties(name, schema)
43
+ schema["properties"].keys.collect{|key| "#{key}:#{model_property_type(schema["properties"][key])}" }.join(" ")
44
+ end
45
+
46
+ def model_property_type(property)
47
+ return property["type"] unless property["type"].blank?
48
+ return 'attachment' if property['$ref'] == "#/components/schemas/attachment"
49
+
50
+ raise 'Unknown property type'
51
+ end
52
+
53
+ def read_openapi_spec
54
+ @read_openapi_spec ||= JSON.parse(@open_api_spec_string).with_indifferent_access
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -1,5 +1,5 @@
1
1
  module MobileWorkflow
2
- VERSION = '0.5.11'
2
+ VERSION = '0.6.0'
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.5.11
4
+ version: 0.6.0
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-19 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -119,8 +119,10 @@ files:
119
119
  - lib/generators/mobile_workflow/install/templates/user.rb.erb
120
120
  - lib/generators/mobile_workflow/install/templates/views/layouts/application.html.erb
121
121
  - lib/generators/mobile_workflow/install/templates/views/sessions/new.html.erb
122
+ - lib/generators/mobile_workflow/model_generator.rb
122
123
  - lib/generators/mobile_workflow/templates/controller.rb.erb
123
124
  - lib/generators/mobile_workflow/templates/controller_spec.rb.erb
125
+ - lib/generators/mobile_workflow/templates/model.rb.erb
124
126
  - lib/mobile_workflow.rb
125
127
  - lib/mobile_workflow/cli.rb
126
128
  - lib/mobile_workflow/cli/app_builder.rb
@@ -130,8 +132,8 @@ files:
130
132
  - lib/mobile_workflow/cli/dokku_backend.rb
131
133
  - lib/mobile_workflow/cli/heroku_backend.rb
132
134
  - lib/mobile_workflow/engine.rb
135
+ - lib/mobile_workflow/open_api_spec/parser.rb
133
136
  - lib/mobile_workflow/version.rb
134
- - lib/templates/active_record/model/model.rb.erb
135
137
  homepage: https://github.com/futureworkshops/mobile_workflow
136
138
  licenses:
137
139
  - MIT