jobshop 0.0.157 → 0.0.163

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/app/email_handlers/jobshop/rfq_handler.rb +43 -0
  4. data/app/models/jobshop/collection.rb +6 -11
  5. data/app/models/jobshop/company.rb +25 -12
  6. data/app/models/jobshop/company/type.rb +17 -0
  7. data/app/models/jobshop/company_person.rb +15 -0
  8. data/app/models/jobshop/inspection.rb +2 -0
  9. data/app/models/jobshop/inspection/boolean_criterion.rb +13 -10
  10. data/app/models/jobshop/inspection/criterion.rb +8 -11
  11. data/app/models/jobshop/inspection/deviation_criterion.rb +13 -10
  12. data/app/models/jobshop/inspection/limit_criterion.rb +9 -7
  13. data/app/models/jobshop/inspection/report.rb +11 -15
  14. data/app/models/jobshop/inspection/result.rb +9 -5
  15. data/app/models/jobshop/inspection/tuple.rb +7 -3
  16. data/app/models/jobshop/mailman.rb +11 -0
  17. data/app/models/jobshop/order.rb +12 -14
  18. data/app/models/jobshop/order_line.rb +10 -5
  19. data/app/models/jobshop/organization.rb +35 -8
  20. data/app/models/jobshop/person.rb +30 -0
  21. data/app/models/jobshop/place.rb +3 -1
  22. data/app/models/jobshop/product.rb +10 -12
  23. data/app/models/jobshop/rfq.rb +22 -0
  24. data/app/models/jobshop/rfq_line.rb +12 -0
  25. data/app/models/jobshop/role.rb +6 -13
  26. data/app/models/jobshop/role_assignment.rb +4 -2
  27. data/app/models/jobshop/routing_process.rb +8 -11
  28. data/app/models/jobshop/routing_step.rb +4 -2
  29. data/app/models/jobshop/thing.rb +6 -11
  30. data/app/models/jobshop/user.rb +10 -17
  31. data/db/migrate/20170311194758_initialize_jobshop.rb +3 -1
  32. data/db/migrate/20171216021339_create_organizations.rb +4 -2
  33. data/db/migrate/20171216021554_create_people.rb +48 -0
  34. data/db/migrate/20171216021853_create_companies.rb +47 -8
  35. data/db/migrate/20171216022020_create_places.rb +3 -3
  36. data/db/migrate/20171216022135_create_products.rb +5 -3
  37. data/db/migrate/20171216022605_create_orders.rb +9 -7
  38. data/db/migrate/20171216023018_create_roles.rb +18 -16
  39. data/db/migrate/20171216023022_create_sessions.rb +9 -7
  40. data/db/migrate/20171216035357_create_things.rb +7 -5
  41. data/db/migrate/20171219022118_create_routing_processes.rb +10 -8
  42. data/db/migrate/{20180107203241_create_inspection.rb → 20180107203241_create_inspections.rb} +21 -16
  43. data/db/migrate/20181117023949_create_rfqs.rb +40 -0
  44. data/db/migrate/20181118014603_create_mailmen.rb +29 -0
  45. data/exe/jobshop +1 -1
  46. data/lib/generators/jobshop/app/app_generator.rb +12 -23
  47. data/lib/generators/jobshop/app/templates/Procfile.tt +1 -0
  48. data/lib/generators/jobshop/config/templates/config/initializers/jobshop.rb.tt +5 -0
  49. data/lib/generators/jobshop/dummy/dummy_generator.rb +4 -5
  50. data/lib/jobshop.rb +8 -4
  51. data/lib/jobshop/cli.rb +58 -47
  52. data/lib/jobshop/configuration.rb +17 -5
  53. data/lib/jobshop/dummy_app.rb +27 -15
  54. data/lib/jobshop/engine.rb +28 -15
  55. data/lib/jobshop/helpers/migration.rb +6 -2
  56. data/lib/jobshop/postmaster.rb +89 -0
  57. data/lib/jobshop/version.rb +2 -2
  58. data/lib/tasks/jobshop_tasks.rake +11 -0
  59. metadata +83 -16
  60. data/db/migrate/20171216021717_create_users.rb +0 -30
@@ -0,0 +1,29 @@
1
+ require "jobshop/helpers/migration.rb"
2
+
3
+ class CreateMailmen < ActiveRecord::Migration[5.2]
4
+ include Jobshop::Helpers::Migration
5
+
6
+ def change
7
+ create_table :jobshop_mailmen, id: false do |t|
8
+ t.uuid :organization_id, null: false
9
+ t.citext :address, null: false
10
+ t.index %i[ organization_id address ], unique: true,
11
+ name: "idx_jobshop_mailmen_pkey"
12
+
13
+ t.string :handler_type, null: false
14
+
15
+ t.timestamps
16
+ end
17
+
18
+ execute <<~SQL
19
+ ALTER TABLE jobshop_mailmen
20
+ ADD CONSTRAINT valid_handler_type
21
+ CHECK (handler_type IN (
22
+ 'Jobshop::RFQHandler'
23
+ ))
24
+ SQL
25
+
26
+ idx_table_name_pkey "jobshop_mailmen"
27
+ fk_organization_id "jobshop_mailmen"
28
+ end
29
+ end
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "jobshop/cli"
4
4
 
5
- Jobshop::CLI.start
5
+ Jobshop::CLI.start(ARGV)
@@ -9,6 +9,10 @@ module Jobshop
9
9
  template "README.md.tt"
10
10
  end
11
11
 
12
+ def procfile
13
+ template "Procfile"
14
+ end
15
+
12
16
  def gemfile
13
17
  super
14
18
  append_to_file "Gemfile", <<~GEMFILE
@@ -17,33 +21,17 @@ module Jobshop
17
21
  end
18
22
 
19
23
  def config_schema_format
24
+ return if options[:pretend]
25
+
20
26
  data = "config.active_record.schema_format = :sql"
21
27
  sentinel = /class [a-z_:]+ < Rails::Application/i
22
28
  inject_into_file("config/application.rb", "\n #{data}",
23
29
  after: sentinel, verbose: true)
24
30
  end
25
31
 
26
- def credentials
27
- return if options[:pretend] || options[:dummy_app]
28
-
29
- require "active_support/encrypted_configuration"
30
- credentials = ActiveSupport::EncryptedConfiguration.new(
31
- config_path: "config/credentials.yml.enc",
32
- key_path: "config/master.key",
33
- env_key: "RAILS_MASTER_KEY",
34
- raise_if_missing_key: true
35
- )
36
- credentials_template = <<~YAML
37
- # aws:
38
- # access_key_id: 123
39
- # secret_access_key: 345
40
- # Used the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
41
- secret_key_base: #{SecureRandom.hex(64)}
42
- YAML
43
- credentials.write(credentials_template)
44
- end
45
-
46
32
  def mount_engine
33
+ return if options[:pretend]
34
+
47
35
  route %Q(mount Jobshop::Engine => "/")
48
36
  end
49
37
  end
@@ -74,8 +62,9 @@ module Jobshop
74
62
  self.options = options.merge(jobshop_options).freeze
75
63
  end
76
64
 
77
- def self.banner
78
- "jobshop new #{arguments.map(&:usage).join(' ')} [options]"
65
+ def create_root_files
66
+ super
67
+ build :procfile
79
68
  end
80
69
 
81
70
  def remove_session_store_initializer_until_rails_5_1
@@ -83,7 +72,7 @@ module Jobshop
83
72
  end
84
73
 
85
74
  def finish_template
86
- generate "jobshop:config"
75
+ generate "jobshop:config" unless options[:pretend]
87
76
  build :config_schema_format
88
77
  build :mount_engine
89
78
  super
@@ -0,0 +1 @@
1
+ web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
@@ -1,2 +1,7 @@
1
1
  Jobshop.configure do |config|
2
+ # config.mailer_host = ENV["JOBSHOP_MAILER_HOST"]
3
+ # config.aws_access_key_id = ENV["JOBSHOP_AWS_ACCESS_KEY_ID"]
4
+ # config.aws_secret_access_key = ENV["JOBSHOP_AWS_SECRET_ACCESS_KEY"]
5
+ # config.aws_region = ENV["JOBSHOP_AWS_REGION"]
6
+ # config.s3_bucket = ENV["JOBSHOP_S3_BUCKET"]
2
7
  end
@@ -9,6 +9,7 @@ module Jobshop
9
9
 
10
10
  # Comment out username, password from production group.
11
11
  def config_database_yml
12
+ return if options[:pretend]
12
13
  gsub_file "config/database.yml",
13
14
  /^([ ]*[^#])(username: .*|password: .*)$/, '\1# \2'
14
15
  end
@@ -55,12 +56,9 @@ module Jobshop
55
56
  hide!
56
57
 
57
58
  def initialize(*args)
58
- DummyApp.destroy! if Jobshop::DummyApp.exist?
59
59
  super
60
- end
61
-
62
- def self.banner
63
- "jobshop dummy [options]"
60
+ return if options[:pretend]
61
+ DummyApp.destroy! if Jobshop::DummyApp.exist?
64
62
  end
65
63
 
66
64
  def create_boot_file
@@ -77,6 +75,7 @@ module Jobshop
77
75
 
78
76
  def run_bundle
79
77
  super
78
+ return if options[:pretend]
80
79
  bundle_command("exec rails db:drop:all")
81
80
  bundle_command("exec rails db:create")
82
81
  bundle_command("exec rails db:migrate")
@@ -1,3 +1,11 @@
1
+ # Dependencies
2
+ require "fast_jsonapi"
3
+ require "jwt"
4
+ require "rack/cors"
5
+ require "redis-rails"
6
+ require "unitwise"
7
+
8
+ # Jobshop Version
1
9
  require "jobshop/version"
2
10
 
3
11
  # Jobshop Configuration
@@ -5,7 +13,3 @@ require "jobshop/configuration"
5
13
 
6
14
  # Jobshop Engine
7
15
  require "jobshop/engine"
8
-
9
- module Jobshop
10
- # Your code goes here...
11
- end
@@ -7,7 +7,47 @@ require "generators/jobshop/dummy/dummy_generator"
7
7
 
8
8
  module Jobshop
9
9
  module CLI
10
- class App < Thor
10
+ class << self
11
+ def start(*args)
12
+ if [ "-v", "--version" ].include?(args[0])
13
+ require "jobshop/version"
14
+ puts "Jobshop #{Jobshop.gem_version}"
15
+ exit 0
16
+ elsif application?
17
+ puts "No tasks available for the application environment yet"
18
+ elsif development?
19
+ Jobshop::CLI::Development.start
20
+ else
21
+ Jobshop::CLI::Apps.start
22
+ end
23
+ end
24
+
25
+ def application?
26
+ has_executable? && !has_gemspec?
27
+ end
28
+
29
+ def development?
30
+ has_executable? && has_gemspec?
31
+ end
32
+
33
+ private def has_executable?
34
+ @has_executable ||= File.file?("bin/jobshop")
35
+ end
36
+
37
+ private def has_gemspec?
38
+ @jobshop_development ||= File.file?("jobshop.gemspec")
39
+ end
40
+ end
41
+
42
+ class Apps < Thor
43
+ desc "list", "List known Jobshop applications"
44
+ long_desc <<~DESC
45
+ TODO: List all known Jobshop instances.
46
+ DESC
47
+ default_command def list
48
+ abort "No apps found"
49
+ end
50
+
11
51
  desc "new [options]", "Create a new Jobshop application"
12
52
  long_desc <<~DESC
13
53
  All the the normal options to `rails new` are applicable but the
@@ -15,32 +55,33 @@ module Jobshop
15
55
 
16
56
  --database=postgresql
17
57
  DESC
18
- default_command def new(*)
58
+ def new(*args)
19
59
  Jobshop::Generators::AppGenerator.start(args, jobshop_options: {
20
60
  database: "postgresql"
21
61
  })
22
62
  end
23
-
24
- def help
25
- Jobshop::Generators::AppGenerator.help(shell)
26
- end
27
63
  end
28
64
 
29
- class Dummy < Thor
30
- desc "create [options]", "Create the dummy app used for running tests"
65
+ class Dev < Thor
66
+ desc "reset [options]", "Create the app used for running tests"
31
67
  long_desc <<~DESC
32
68
  All the the normal options to `rails new` are applicable but the
33
- following will be set regardless of input:
69
+ following options may not be changed:
34
70
 
35
- --database=postgresql
71
+ --database=postgresql
72
+ --skip-bundle
73
+ --skip-gemfile
74
+ --skip-git
75
+ --skip-listen
76
+ --skip-test
36
77
  DESC
37
- def create(*args)
78
+ def reset(*args)
38
79
  Jobshop::Generators::DummyGenerator.start(
39
80
  args.unshift(Jobshop::DummyApp.path),
40
81
  jobshop_options: {
41
82
  database: "postgresql",
42
- skip_gemfile: true,
43
83
  skip_bundle: true,
84
+ skip_gemfile: true,
44
85
  skip_git: true,
45
86
  skip_listen: true,
46
87
  skip_test: true
@@ -48,12 +89,12 @@ module Jobshop
48
89
  )
49
90
  end
50
91
 
51
- desc "seed", "Seed the dummy app"
92
+ desc "seed", "Seed the test app"
52
93
  def seed
53
94
  Jobshop::DummyApp.seed
54
95
  end
55
96
 
56
- desc "routes", "Dummy app routes"
97
+ desc "routes", "Test app routes"
57
98
  def routes
58
99
  Dir.chdir(Jobshop::DummyApp.path)
59
100
  exec %Q(rails routes)
@@ -61,39 +102,9 @@ module Jobshop
61
102
  end
62
103
 
63
104
  class Development < Thor
64
- register Jobshop::CLI::App, "app", "app COMMAND [options]", "Create test apps in development"
65
- register Jobshop::CLI::Dummy, "dummy", "dummy COMMAND [options]", "Manage dummy app used for tests"
66
- end
67
-
68
- class << self
69
- def start
70
- if [ "-v", "--version" ].include?(ARGV[0])
71
- require "jobshop/version"
72
- puts "Jobshop #{Jobshop.gem_version}"
73
- exit 0
74
- elsif jobshop_application?
75
- puts "No tasks available for the application environment yet"
76
- elsif jobshop_development?
77
- Jobshop::CLI::Development.start
78
- else
79
- Jobshop::CLI::App.start
80
- end
81
- end
82
-
83
- private def jobshop_application?
84
- has_executable? && !has_gemspec?
85
- end
86
-
87
- private def jobshop_development?
88
- has_executable? && has_gemspec?
89
- end
90
-
91
- private def has_executable?
92
- @has_executable ||= File.file?("bin/jobshop")
93
- end
94
-
95
- private def has_gemspec?
96
- @jobshop_development ||= File.file?("jobshop.gemspec")
105
+ register Jobshop::CLI::Apps, "apps", "apps COMMAND [options]", "Manage jobshop applications"
106
+ if Jobshop::CLI.development?
107
+ register Jobshop::CLI::Dev, "dev", "dev COMMAND [options]", "Manage test app used for tests"
97
108
  end
98
109
  end
99
110
  end
@@ -1,12 +1,24 @@
1
1
  module Jobshop
2
2
  class Configuration
3
- attr_accessor :mailer_host
4
- attr_accessor :session_store_url
3
+ extend Forwardable
4
+
5
+ attr_accessor :mailer_host, :session_store_url
6
+ def_delegators :aws, :access_key_id, :secret_access_key, :region,
7
+ :s3_bucket, :incoming_email_queue
5
8
 
6
9
  def initialize
7
- @mailer_host = begin
8
- ENV.fetch("JOBSHOP_MAILER_HOST", "localhost:3000")
9
- end
10
+ self.mailer_host = ENV.fetch("JOBSHOP_MAILER_HOST", "localhost:3000")
11
+ self.session_store_url = ENV.fetch("JOBSHOP_SESSION_STORE_URL", "")
12
+
13
+ aws.access_key_id = ENV.fetch("JOBSHOP_AWS_ACCESS_KEY_ID", "")
14
+ aws.secret_access_key = ENV.fetch("JOBSHOP_AWS_SECRET_ACCESS_KEY", "")
15
+ aws.region = ENV.fetch("JOBSHOP_AWS_REGION", "")
16
+ aws.s3_bucket = ENV.fetch("JOBSHOP_S3_BUCKET", "")
17
+ aws.incoming_email_queue = ENV.fetch("JOBSHOP_INCOMING_EMAIL_QUEUE", "")
18
+ end
19
+
20
+ def aws
21
+ @aws ||= ActiveSupport::OrderedOptions.new
10
22
  end
11
23
  end
12
24
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literals: true
2
+
1
3
  require "rails/version"
2
4
 
3
5
  require "jobshop/cli"
@@ -64,7 +66,7 @@ module Jobshop
64
66
  [ Jobshop::Engine.root.join("spec", "factories") ]
65
67
  end
66
68
 
67
- def seed
69
+ def seed # rubocop:disable Metrics/MethodLength
68
70
  with_dummy_app do
69
71
  do_with_spinner("Loading factories") do
70
72
  require "factory_bot_rails"
@@ -76,30 +78,30 @@ module Jobshop
76
78
  clean_database
77
79
  end
78
80
 
79
- @org = do_with_spinner("Creating sample Organization") do
81
+ @org = do_with_spinner("Creating test Organization") do
80
82
  FactoryBot.create(:organization)
81
83
  end
82
84
 
83
- @ceo = do_with_spinner("Creating first User") do
84
- FactoryBot.create(:user, :ceo, organization: @org)
85
+ @ceo = do_with_spinner("Creating test Person") do
86
+ FactoryBot.create(:person, :ceo, organization: @org)
85
87
  end
86
88
 
87
- @places = do_with_spinner("Creating sample Places") do
89
+ @places = do_with_spinner("Creating test Places") do
88
90
  FactoryBot.create_list(:place, 10, organization: @org)
89
91
  end
90
92
 
91
- @companies = do_with_spinner("Creating sample companies") do
92
- FactoryBot.create_list(:company, 100, organization: @org,
93
+ @companies = do_with_spinner("Creating test companies") do
94
+ FactoryBot.create_list(:company, 10, organization: @org,
93
95
  created_by: @ceo)
94
96
  end
95
97
 
96
- @products = do_with_spinner("Creating sample Products") do
97
- FactoryBot.create_list(:product, 50,
98
+ @products = do_with_spinner("Creating test Products") do
99
+ FactoryBot.create_list(:product, 10,
98
100
  organization: @org,
99
101
  created_by: @ceo)
100
102
  end
101
103
 
102
- do_with_spinner("Creating Routers for Products") do
104
+ do_with_spinner("Creating test Routers for Products") do
103
105
  @products.each do |product|
104
106
  rp = FactoryBot.create(:routing_process, organization: @org,
105
107
  product: product)
@@ -136,14 +138,14 @@ module Jobshop
136
138
  end
137
139
 
138
140
  do_with_spinner("Creating Inspection Reports") do
139
- 10.times do
141
+ 5.times do
140
142
  report = FactoryBot.create(:inspection_report, organization: @org)
141
- 8.times do |index|
143
+ 5.times do |index|
142
144
  FactoryBot.create(Jobshop::Inspection::CRITERION_TYPES.sample,
143
145
  organization: @org, report: report,
144
146
  position: (index + 1))
145
147
  end
146
- 10.times do |index|
148
+ 5.times do |index|
147
149
  tuple = FactoryBot.create(:inspection_tuple, organization: @org,
148
150
  report: report, position: (index + 1))
149
151
  report.criteria.each do |criterion|
@@ -154,11 +156,21 @@ module Jobshop
154
156
  end
155
157
  end
156
158
  end
157
- #binding.pry
159
+
160
+ do_with_spinner("Creating RFQ Mailman") do
161
+ @org.mailmen.create!(address: "rfq@jobshop.io", handler_type: "Jobshop::RFQHandler")
162
+ end
163
+
164
+ do_with_spinner("Creating sample RFQs") do
165
+ 50.times do
166
+ FactoryBot.create(:rfq, organization: @org,
167
+ company: @companies.sample)
168
+ end
169
+ end
158
170
  end
159
171
  end
160
172
 
161
- private def with_dummy_app(&block)
173
+ private def with_dummy_app(*)
162
174
  begin
163
175
  require "#{Jobshop::DummyApp.path}/config/environment"
164
176
  rescue LoadError
@@ -1,17 +1,9 @@
1
- require "active_support/lazy_load_hooks"
2
- require "activerecord_json_validator"
3
- require "composite_primary_keys"
4
- require "fast_jsonapi"
5
- require "jwt"
6
- require "rack/cors"
7
- require "rails/all"
8
- require "redis-rails"
9
- require "unitwise"
10
-
11
1
  module Jobshop
12
2
  class Engine < ::Rails::Engine
13
3
  isolate_namespace Jobshop
14
4
 
5
+ config.eager_load_namespaces << Jobshop
6
+
15
7
  config.generators.api_only = true
16
8
 
17
9
  config.generators do |g|
@@ -21,6 +13,20 @@ module Jobshop
21
13
  g.javascripts false
22
14
  end
23
15
 
16
+ ActiveSupport::Inflector.inflections do |inflect|
17
+ inflect.irregular "criterion", "criteria"
18
+ inflect.acronym "JWT"
19
+ inflect.acronym "RFQ"
20
+ inflect.acronym "RFQs"
21
+ end
22
+
23
+ initializer "jobshop.active_record_enhancements" do
24
+ ActiveSupport.on_load(:active_record) do
25
+ require "activerecord_json_validator"
26
+ require "composite_primary_keys"
27
+ end
28
+ end
29
+
24
30
  initializer "jobshop.middleware" do
25
31
  config.middleware.use Rack::Cors do
26
32
  allow do
@@ -33,11 +39,6 @@ module Jobshop
33
39
  end
34
40
  end
35
41
 
36
- ActiveSupport::Inflector.inflections do |inflect|
37
- inflect.irregular "criterion", "criteria"
38
- inflect.acronym "jwt"
39
- end
40
-
41
42
  initializer "jobshop.append_paths", before: :load_config_initializers do |app|
42
43
  config.paths["db/migrate"].expanded.each do |expanded_path|
43
44
  app.config.paths["db/migrate"] << expanded_path
@@ -55,5 +56,17 @@ module Jobshop
55
56
  host: Jobshop.configuration.mailer_host
56
57
  }
57
58
  end
59
+
60
+ initializer "jobshop.aws.config" do
61
+ require "aws-sdk-core"
62
+
63
+ Aws.config.update({
64
+ credentials: Aws::Credentials.new(
65
+ Jobshop.configuration.aws.access_key_id,
66
+ Jobshop.configuration.aws.secret_access_key
67
+ ),
68
+ region: Jobshop.configuration.aws.region
69
+ })
70
+ end
58
71
  end
59
72
  end