decko 0.11.5 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/lib/card_controller.rb +4 -0
  3. data/lib/card_controller/errors.rb +11 -13
  4. data/lib/card_controller/response.rb +0 -12
  5. data/lib/card_controller/rest.rb +14 -4
  6. data/lib/decko.rb +2 -15
  7. data/lib/decko/all.rb +2 -0
  8. data/lib/decko/application.rb +8 -89
  9. data/lib/decko/cli.rb +1 -7
  10. data/lib/decko/commands.rb +17 -110
  11. data/lib/decko/commands/application.rb +2 -2
  12. data/lib/decko/commands/cucumber_command.rb +8 -7
  13. data/lib/decko/commands/cucumber_command/parser.rb +2 -2
  14. data/lib/decko/engine.rb +1 -45
  15. data/lib/decko/generators.rb +17 -0
  16. data/lib/decko/mods_spec_helper.rb +1 -1
  17. data/lib/decko/railtie.rb +27 -0
  18. data/lib/decko/script_decko_loader.rb +5 -38
  19. data/lib/decko/tasks/cucumber.rake +25 -16
  20. data/lib/decko/tasks/decko.rake +7 -28
  21. data/lib/decko/tasks/decko/benchmark.rake +38 -0
  22. data/lib/decko/tasks/decko/docs.rake +1 -1
  23. data/lib/decko/tasks/decko/seed.rake +16 -7
  24. data/lib/generators/deck/deck_generator.rb +12 -0
  25. metadata +25 -72
  26. data/lib/decko/commands/command.rb +0 -28
  27. data/lib/decko/commands/rake_command.rb +0 -42
  28. data/lib/decko/commands/rake_command/parser.rb +0 -35
  29. data/lib/decko/commands/rspec_command.rb +0 -36
  30. data/lib/decko/commands/rspec_command/parser.rb +0 -97
  31. data/lib/decko/config/environments/cucumber.rb +0 -41
  32. data/lib/decko/config/environments/cypress.rb +0 -100
  33. data/lib/decko/config/environments/development.rb +0 -95
  34. data/lib/decko/config/environments/production.rb +0 -75
  35. data/lib/decko/config/environments/profile.rb +0 -33
  36. data/lib/decko/config/environments/test.rb +0 -69
  37. data/lib/decko/config/initializers/secret_token.rb +0 -15
  38. data/lib/decko/config/initializers/sedate_parser.rb +0 -8
  39. data/lib/decko/config/initializers/session_store.rb +0 -2
  40. data/lib/decko/generators/deck/USAGE +0 -9
  41. data/lib/decko/generators/deck/deck_generator.rb +0 -134
  42. data/lib/decko/generators/deck/deck_generator/deck_helper.rb +0 -110
  43. data/lib/decko/generators/deck/deck_generator/interactive.rb +0 -120
  44. data/lib/decko/generators/deck/deck_generator/rails_overrides.rb +0 -54
  45. data/lib/decko/generators/deck/templates/Gemfile.erb +0 -56
  46. data/lib/decko/generators/deck/templates/Rakefile.erb +0 -6
  47. data/lib/decko/generators/deck/templates/bin/spring.erb +0 -20
  48. data/lib/decko/generators/deck/templates/config.ru.erb +0 -11
  49. data/lib/decko/generators/deck/templates/config/application.rb.erb +0 -107
  50. data/lib/decko/generators/deck/templates/config/boot.rb.erb +0 -11
  51. data/lib/decko/generators/deck/templates/config/cucumber.yml +0 -1
  52. data/lib/decko/generators/deck/templates/config/databases/frontbase.yml +0 -34
  53. data/lib/decko/generators/deck/templates/config/databases/ibm_db.yml +0 -89
  54. data/lib/decko/generators/deck/templates/config/databases/jdbc.yml +0 -65
  55. data/lib/decko/generators/deck/templates/config/databases/jdbcmysql.yml +0 -36
  56. data/lib/decko/generators/deck/templates/config/databases/jdbcpostgresql.yml +0 -46
  57. data/lib/decko/generators/deck/templates/config/databases/jdbcsqlite3.yml +0 -23
  58. data/lib/decko/generators/deck/templates/config/databases/mysql.yml +0 -37
  59. data/lib/decko/generators/deck/templates/config/databases/oracle.yml +0 -42
  60. data/lib/decko/generators/deck/templates/config/databases/postgresql.yml +0 -39
  61. data/lib/decko/generators/deck/templates/config/databases/sqlite3.yml +0 -21
  62. data/lib/decko/generators/deck/templates/config/deck.yml +0 -10
  63. data/lib/decko/generators/deck/templates/config/environment.rb.erb +0 -5
  64. data/lib/decko/generators/deck/templates/config/initializers/cypress.rb +0 -12
  65. data/lib/decko/generators/deck/templates/config/puma.rb +0 -16
  66. data/lib/decko/generators/deck/templates/config/routes.rb.erb +0 -11
  67. data/lib/decko/generators/deck/templates/config/storage.yml +0 -0
  68. data/lib/decko/generators/deck/templates/gitignore +0 -18
  69. data/lib/decko/generators/deck/templates/pryrc +0 -6
  70. data/lib/decko/generators/deck/templates/public/files/htaccess +0 -9
  71. data/lib/decko/generators/deck/templates/public/robots.txt +0 -13
  72. data/lib/decko/generators/deck/templates/rspec.erb +0 -6
  73. data/lib/decko/generators/deck/templates/script/decko +0 -6
  74. data/lib/decko/generators/deck/templates/script/decko_cucumber +0 -8
  75. data/lib/decko/generators/deck/templates/script/decko_rspec +0 -8
  76. data/lib/decko/generators/deck/templates/script/delayed_job +0 -5
  77. data/lib/decko/generators/deck/templates/simplecov.rb.erb +0 -34
  78. data/lib/decko/generators/deck/templates/spec/javascripts/support/deck_jasmine.yml.erb +0 -56
  79. data/lib/decko/generators/deck/templates/spec/javascripts/support/decko_jasmine.yml.erb +0 -74
  80. data/lib/decko/generators/deck/templates/spec/spec_helper.rb +0 -1
  81. data/rails/application-routes.rb +0 -3
  82. data/rails/assets/external_link.png +0 -0
  83. data/rails/assets/jasmine/404.html +0 -27
  84. data/rails/assets/jasmine/500.html +0 -28
  85. data/rails/assets/jasmine/card_form.html +0 -13
  86. data/rails/assets/jquery.min.map +0 -1
  87. data/rails/engine-routes.rb +0 -53
  88. data/script/autospec +0 -4
  89. data/script/decko +0 -6
  90. data/script/rails +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c726ee70f0d8daba2891b23aab64090c43d088cc3300290a52eddee922dc7d0
4
- data.tar.gz: c3e610b82510c510d2dfb16ecd1c408fe0be17c7e0b1d1209ce92432d52513e9
3
+ metadata.gz: 563f8b4de0ed787b40924054ae28cf77715706b1432823dd0d08d13d3d22cc63
4
+ data.tar.gz: 44512dca21464c88c0eb5b1920afa12cc3645e478f843680761b72f353d44cba
5
5
  SHA512:
6
- metadata.gz: 8c18ed07879923d174cea1cc75a860406a5f6548dfbc56dfe4d27610ee64d29ce0df3cbfdd500362b2ce2780948d48f2e54aac487d437141e0b91c29a78d9935
7
- data.tar.gz: a76d39182e7d95ac2192a4a90017dd337f07d786379379dc3a5166765a2f7241b3abc8b025ae8a7210aa0dd7431552dab7c1ce877acc4c394801d4cd410e2250
6
+ metadata.gz: eb06c6d1d8b6f1639199c0dd10c27f14191769109948da5a4fc3a797eaf784130457acac8f66ced45de49827ae737705e883342212c974083bf555bf35394fec
7
+ data.tar.gz: 9c0e95dbd4f8903afe755f415543e33fa934d6ae7b58bd4da8b44b46b0c3c8f25200c867ad77a6a3d24ae73511da7a4d52ba10a4dccf4575e299f9956aacaa7a
@@ -6,6 +6,7 @@ class CardController < ActionController::Base
6
6
  include Rest
7
7
  include Response
8
8
  include Errors
9
+ extend Errors::Rescue
9
10
 
10
11
  # NOTE: including Card::Env::Location triggers card loading, which triggers mod loading,
11
12
  # which can include initializers that add to the CardController class.
@@ -22,4 +23,7 @@ class CardController < ActionController::Base
22
23
  before_action :load_card, except: [:asset]
23
24
  before_action :load_action, only: [:read]
24
25
  before_action :refresh_card, only: %i[create update delete]
26
+
27
+ rescue_from_class(*Card::Error::UserError.user_error_classes)
28
+ rescue_from_class StandardError if rescue_all?
25
29
  end
@@ -1,19 +1,20 @@
1
1
  # Decko's only controller.
2
2
  class CardController
3
- class << self
4
- def rescue_from_class *klasses
5
- klasses.each do |klass|
6
- rescue_from(klass) { |exception| handle_exception exception }
3
+ # controller error handling
4
+ module Errors
5
+ # controller class method to handle top-level error rescuing
6
+ module Rescue
7
+ def rescue_from_class *klasses
8
+ klasses.each do |klass|
9
+ rescue_from(klass) { |exception| handle_exception exception }
10
+ end
7
11
  end
8
- end
9
12
 
10
- def rescue_all?
11
- Cardio.config.rescue_all_in_controller
13
+ def rescue_all?
14
+ Cardio.config.rescue_all_in_controller
15
+ end
12
16
  end
13
- end
14
17
 
15
- # controller error handling
16
- module Errors
17
18
  def handle_exception exception
18
19
  raise exception if debug_exception?(exception)
19
20
 
@@ -30,7 +31,4 @@ class CardController
30
31
  Card[:debugger]&.content =~ /on/ # && !Card::Env.ajax?
31
32
  end
32
33
  end
33
-
34
- rescue_from_class(*Card::Error::UserError.user_error_classes)
35
- rescue_from_class StandardError if rescue_all?
36
34
  end
@@ -76,18 +76,6 @@ class CardController
76
76
  raise Card::Error, "tried to do soft redirect without a card"
77
77
  end
78
78
 
79
- def asset_file_path filename
80
- path = Decko::Engine.paths["gem-assets"].existent.first
81
- path = File.join path, filename
82
- validate_path filename, path
83
- path
84
- end
85
-
86
- def validate_path filename, path
87
- # for security, block relative paths
88
- raise Card::Error::BadAddress if filename.include?("../") || !::File.exist?(path)
89
- end
90
-
91
79
  # TODO: everything below should go in a separate file
92
80
  # below is about beginning (initialization). above is about end (response)
93
81
  # Both this file and that would make sense as submodules of CardController
@@ -1,6 +1,8 @@
1
1
  class CardController
2
2
  # RESTful action methods for card
3
3
  module Rest
4
+ include ActionController::HttpAuthentication::Token
5
+
4
6
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
7
  # PUBLIC METHODS
6
8
 
@@ -22,8 +24,8 @@ class CardController
22
24
 
23
25
  # @deprecated
24
26
  def asset
25
- body = "Decko installation error: missing asset symlinks"
26
- Rails.logger.info "#{body}.\n >>> Try `rake decko:update_assets_symlink`"
27
+ body = "Decko installation error: missing public directory symlinks"
28
+ Rails.logger.info "#{body}.\n >>> Try `rake card:mod:symlink`"
27
29
  render body: body, status: 404
28
30
  end
29
31
 
@@ -33,13 +35,21 @@ class CardController
33
35
  private
34
36
 
35
37
  def setup
36
- Card::Machine.refresh_script_and_style unless params[:explicit_file]
38
+ Card::Machine.refresh_assets unless params[:explicit_file]
37
39
  Card::Cache.renew
38
40
  Card::Env.reset controller: self
39
41
  end
40
42
 
41
43
  def authenticate
42
- Card::Auth.signin_with params
44
+ Card::Auth.signin_with(**authenticators)
45
+ end
46
+
47
+ def authenticators
48
+ { token: token_from_header || params[:token] }
49
+ end
50
+
51
+ def token_from_header
52
+ token_and_options(request)&.first
43
53
  end
44
54
 
45
55
  def load_card
data/lib/decko.rb CHANGED
@@ -2,21 +2,8 @@ module Decko
2
2
  DECKO_GEM_ROOT = File.expand_path("..", __dir__)
3
3
 
4
4
  class << self
5
- def root
6
- Rails.root
7
- end
8
-
9
- def application
10
- Rails.application
11
- end
12
-
13
- def config
14
- application.config
15
- end
16
-
17
- def paths
18
- application.paths
19
- end
5
+ delegate :application, :root, to: :Rails
6
+ delegate :config, :paths, to: :application
20
7
 
21
8
  def gem_root
22
9
  DECKO_GEM_ROOT
data/lib/decko/all.rb CHANGED
@@ -1 +1,3 @@
1
+ # backwards compatibility for old decks that require decko/all
2
+
1
3
  require "decko/application"
@@ -1,93 +1,12 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- require "decko/engine"
4
- require_relative "config/initializers/sedate_parser"
5
-
6
- Bundler.require :default, *Rails.groups
7
-
8
- module Decko
9
- class Application < Rails::Application
10
- initializer :load_decko_environment_config,
11
- before: :load_environment_config, group: :all do
12
- add_path paths, "lib/decko/config/environments", glob: "#{Rails.env}.rb"
13
- paths["lib/decko/config/environments"].existent.each do |environment|
14
- require environment
15
- end
16
- end
17
-
18
- class << self
19
- def inherited base
20
- super
21
- Rails.app_class = base
22
- add_lib_to_load_path!(find_root(base.called_from))
23
- ActiveSupport.run_load_hooks(:before_configuration, base.instance)
24
- end
25
- end
26
-
27
- def add_path paths, path, options={}
28
- root = options.delete(:root) || Decko.gem_root
29
- options[:with] = File.join(root, (options[:with] || path))
30
- paths.add path, options
31
- end
32
-
33
- def config
34
- @config ||= begin
35
- config = super
36
-
37
- Cardio.set_config config
38
-
39
- # any config settings below:
40
- # (a) do not apply to Card used outside of a Decko context
41
- # (b) cannot be overridden in a deck's application.rb, but
42
- # (c) CAN be overridden in an environment file
43
-
44
- # therefore, in general, they should be restricted to settings that
45
- # (1) are specific to the web environment, and
46
- # (2) should not be overridden
47
- # ..and we should address (c) above!
3
+ require "cardio/all"
4
+ require "action_controller/railtie"
5
+ require "decko/railtie"
6
+ require "cardio/application"
48
7
 
49
- # general card settings (overridable and not) should be in cardio.rb
50
- # overridable decko-specific settings don't have a place yet
51
- # but should probably follow the cardio pattern.
52
-
53
- # config.load_defaults "6.0"
54
- config.autoloader = :zeitwerk
55
- config.load_default = "6.0"
56
- config.i18n.enforce_available_locales = true
57
- # config.active_record.raise_in_transactional_callbacks = true
58
-
59
- config.allow_concurrency = false
60
- config.assets.enabled = false
61
- config.assets.version = "1.0"
62
-
63
- config.filter_parameters += [:password]
64
-
65
- # Rails.autoloaders.log!
66
- Rails.autoloaders.main.ignore(
67
- File.join(Cardio.gem_root, "lib/card/seed_consts.rb")
68
- )
69
- config
70
- end
71
- end
72
-
73
- def paths
74
- @paths ||= begin
75
- paths = super
76
- Cardio.set_paths paths
77
-
78
- paths.add "files"
79
-
80
- paths["app/models"] = []
81
- paths["app/mailers"] = []
82
- paths["app/controllers"] = []
83
-
84
- unless paths["config/routes.rb"].existent.present?
85
- add_path paths, "config/routes.rb",
86
- with: "rails/application-routes.rb"
87
- end
8
+ # require_relative "config/initializers/sedate_parser"
9
+ require "decko/engine"
88
10
 
89
- paths
90
- end
91
- end
92
- end
93
- end
11
+ # The application class from which decko applications inherit
12
+ Decko::Application = Rails::Application
data/lib/decko/cli.rb CHANGED
@@ -6,12 +6,6 @@ require "decko/script_decko_loader"
6
6
  Decko::ScriptDeckoLoader.exec!
7
7
 
8
8
  require "rails/ruby_version_check"
9
- Signal.trap("INT") { puts; exit(1) }
10
-
11
- # if ARGV.first == 'plugin'
12
- # ARGV.shift
13
- # require 'decko/commands/plugin_new'
14
- # else
9
+ Signal.trap("INT") { exit(1) }
15
10
 
16
11
  require "decko/commands/application"
17
- # end
@@ -1,121 +1,28 @@
1
- # add method in? to Object class
2
- require "active_support/core_ext/object/inclusion"
1
+ ENV["CARDIO_COMMANDS"] = "NO_RUN"
3
2
 
4
- def load_rake_tasks
5
- require "./config/environment"
6
- require "rake"
7
- Decko::Application.load_tasks
8
- end
9
-
10
- RAILS_COMMANDS = %w[ generate destroy plugin benchmarker profiler console
11
- server dbconsole application runner ].freeze
12
- DECKO_COMMANDS = %w[new cucumber rspec jasmine].freeze
13
- DECKO_DB_COMMANDS = %w[seed reseed load update].freeze
14
-
15
- ALIAS = {
16
- "rs" => "rspec",
17
- "cc" => "cucumber",
18
- "jm" => "jasmine",
19
- "g" => "generate",
20
- "d" => "destroy",
21
- "c" => "console",
22
- "s" => "server",
23
- "db" => "dbconsole",
24
- "r" => "runner"
25
- }.freeze
26
-
27
- def supported_rails_command? arg
28
- arg.in?(RAILS_COMMANDS) || ALIAS[arg].in?(RAILS_COMMANDS)
29
- end
30
-
31
- ARGV << "--help" if ARGV.empty?
3
+ require "cardio/commands"
32
4
 
33
5
  module Decko
34
- module Commands
35
- class << self
36
- def run_new
37
- if ARGV.first.in?(["-h", "--help"])
38
- require "decko/commands/application"
39
- else
40
- puts "Can't initialize a new deck within the directory of another, " \
41
- "please change to a non-deck directory first.\n"
42
- puts "Type 'decko' for help."
43
- exit(1)
44
- end
45
- end
46
-
47
- def run_rspec
48
- require "decko/commands/rspec_command"
49
- RspecCommand.new(ARGV).run
50
- end
51
-
52
- def run_cucumber
53
- require "decko/commands/cucumber_command"
54
- CucumberCommand.new(ARGV).run
55
- end
6
+ class Commands < Cardio::Commands
7
+ extend Cardio::Commands::Accessors
56
8
 
57
- def run_db_task command
58
- require "decko/commands/rake_command"
59
- RakeCommand.new("decko:#{command}", ARGV).run
60
- end
9
+ commands[:rails] << (aliases["s"] = "server")
10
+ commands[:custom] << (aliases["cc"] = "cucumber")
61
11
 
62
- def run_jasmine
63
- require "decko/commands/rake_command"
64
- RakeCommand.new("spec:javascript", envs: "test").run
65
- end
12
+ def run_cucumber
13
+ require "decko/commands/cucumber_command"
14
+ CucumberCommand.new(args).run
66
15
  end
67
- end
68
- end
69
-
70
- command = ARGV.first
71
- command = ALIAS[command] || command
72
- if supported_rails_command? command
73
- ENV["PRY_RESCUE_RAILS"] = "1" if ARGV.delete("--rescue")
74
-
75
- # without this, the card generators don't list with: decko g --help
76
- require "generators/card" if command == "generate"
77
- require "rails/commands"
78
- else
79
- ARGV.shift
80
- case command
81
- when "--version", "-v"
82
- puts "Decko #{Card::Version.release}"
83
- when *DECKO_COMMANDS
84
- Decko::Commands.send("run_#{command}")
85
- when *DECKO_DB_COMMANDS
86
- Decko::Commands.run_db_task command
87
- else
88
- puts "Error: Command not recognized" unless command.in?(["-h", "--help"])
89
- puts <<-EOT
90
- Usage: decko COMMAND [ARGS]
91
16
 
92
- The most common decko commands are:
93
- new Create a new Decko deck. "decko new my_deck" creates a
94
- new deck called MyDeck in "./my_deck"
95
- seed Create and seed the database specified in config/database.yml
96
-
97
- server Start the Rails server (short-cut alias: "s")
98
- console Start the Rails console (short-cut alias: "c")
99
- dbconsole Start a console for the database specified in config/database.yml
100
- (short-cut alias: "db")
101
-
102
- For core developers
103
- cucumber Run cucumber features (short-cut alias: "cc")
104
- rspec Run rspec tests (short-cut alias: "rs")
105
- update Run card migrations
106
- load Load bootstrap data into database
17
+ def rake_prefix
18
+ "decko"
19
+ end
107
20
 
108
- In addition to those, there are the standard rails commands:
109
- generate Generate new code (short-cut alias: "g")
110
- application Generate the Rails application code
111
- destroy Undo code generated with "generate" (short-cut alias: "d")
112
- benchmarker See how fast a piece of code runs
113
- profiler Get profile information from a piece of code
114
- plugin Install a plugin
115
- runner Run a piece of code in the application environment (short-cut alias: "r")
21
+ def run_rails
22
+ require "decko/generators" if command == "generate"
23
+ super
24
+ end
116
25
 
117
- All commands can be run with -h (or --help) for more information.
118
- EOT
119
- exit(1)
26
+ new(ARGV).run
120
27
  end
121
28
  end
@@ -1,5 +1,5 @@
1
1
  require "rails/generators"
2
- require File.expand_path("../generators/deck/deck_generator", __dir__)
2
+ require File.expand_path("../../../generators/deck/deck_generator", __FILE__)
3
3
 
4
4
  if ARGV.first != "new"
5
5
  ARGV[0] = "--help"
@@ -7,4 +7,4 @@ else
7
7
  ARGV.shift
8
8
  end
9
9
 
10
- Decko::Generators::Deck::DeckGenerator.start
10
+ Cardio::Generators::Deck::DeckGenerator.start
@@ -1,11 +1,14 @@
1
- require File.expand_path("command", __dir__)
1
+ # load the application so we can look in mods
2
+ require APP_PATH
3
+ require "cardio/commands/command"
4
+ require "cardio/mod/dirs"
2
5
 
3
6
  module Decko
4
- module Commands
5
- class CucumberCommand < Command
7
+ class Commands
8
+ class CucumberCommand < Cardio::Commands::Command
9
+ require "decko/commands/cucumber_command/parser"
10
+
6
11
  def initialize args
7
- require "decko"
8
- require "./config/environment"
9
12
  @decko_args, @cucumber_args = split_args args
10
13
  @opts = {}
11
14
  Parser.new(@opts).parse!(@decko_args)
@@ -44,5 +47,3 @@ module Decko
44
47
  end
45
48
  end
46
49
  end
47
-
48
- require File.expand_path("cucumber_command/parser", __dir__)