From a226648fd7b8d01a886eed7d5799007092c567b7 Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Mon, 5 Oct 2020 14:06:11 -0500 Subject: [PATCH 01/11] Restart, first lots of moves, rake loading, task list works, no rspec --- card/lib/cardio.rb | 49 +++++++++++-------- .../cardio/commands}/commands/application.rb | 0 .../lib/cardio/commands}/commands/command.rb | 0 .../commands}/commands/cucumber_command.rb | 0 .../commands/cucumber_command/parser.rb | 0 .../cardio/commands}/commands/rake_command.rb | 0 .../commands}/commands/rake_command/parser.rb | 0 .../commands}/commands/rspec_command.rb | 0 .../commands/rspec_command/parser.rb | 0 card/lib/{card => cardio}/mod.rb | 0 card/lib/{card => cardio}/mod/dirs.rb | 0 .../lib/{card => cardio}/mod/load_strategy.rb | 0 .../mod/load_strategy/eval.rb | 0 .../mod/load_strategy/pattern_tmp_files.rb | 0 .../mod/load_strategy/set_binding_magic.rb | 0 .../mod/load_strategy/set_tmp_files.rb | 0 .../mod/load_strategy/tmp_files.rb | 0 card/lib/{card => cardio}/mod/loader.rb | 0 .../{card => cardio}/mod/loader/set_loader.rb | 0 .../mod/loader/set_pattern_loader.rb | 0 .../{card => cardio}/mod/module_template.rb | 0 card/lib/{card => }/tasks/card.rake | 0 .../tasks/card/file_card_creator.rb | 0 .../file_card_creator/abstract_file_card.rb | 0 .../abstract_file_card/migration_file.rb | 0 .../abstract_file_card/ruby_file.rb | 0 .../abstract_file_card/source_file.rb | 0 .../tasks/card/file_card_creator/haml_card.rb | 0 .../card/file_card_creator/output_helper.rb | 0 .../card/file_card_creator/script_card.rb | 0 .../card/file_card_creator/style_card.rb | 0 .../{card/tasks/card => tasks}/create.rake | 0 {decko/lib/decko => card/lib}/tasks/db.rake | 0 .../{card/tasks/card => tasks}/migrate.rake | 0 .../tasks/decko => card/lib/tasks}/seed.rake | 0 decko/lib/decko.rb | 17 +------ decko/lib/decko/application.rb | 20 +++----- decko/lib/decko/engine.rb | 9 ++-- decko/lib/{decko => }/tasks/alias.rb | 0 decko/lib/{decko => }/tasks/cucumber.rake | 0 decko/lib/{decko => }/tasks/decko.rake | 2 +- .../{decko/tasks/decko => tasks}/docs.rake | 0 .../{decko/tasks/decko => tasks}/tmpsets.rake | 0 43 files changed, 42 insertions(+), 55 deletions(-) rename {decko/lib/decko => card/lib/cardio/commands}/commands/application.rb (100%) rename {decko/lib/decko => card/lib/cardio/commands}/commands/command.rb (100%) rename {decko/lib/decko => card/lib/cardio/commands}/commands/cucumber_command.rb (100%) rename {decko/lib/decko => card/lib/cardio/commands}/commands/cucumber_command/parser.rb (100%) rename {decko/lib/decko => card/lib/cardio/commands}/commands/rake_command.rb (100%) rename {decko/lib/decko => card/lib/cardio/commands}/commands/rake_command/parser.rb (100%) rename {decko/lib/decko => card/lib/cardio/commands}/commands/rspec_command.rb (100%) rename {decko/lib/decko => card/lib/cardio/commands}/commands/rspec_command/parser.rb (100%) rename card/lib/{card => cardio}/mod.rb (100%) rename card/lib/{card => cardio}/mod/dirs.rb (100%) rename card/lib/{card => cardio}/mod/load_strategy.rb (100%) rename card/lib/{card => cardio}/mod/load_strategy/eval.rb (100%) rename card/lib/{card => cardio}/mod/load_strategy/pattern_tmp_files.rb (100%) rename card/lib/{card => cardio}/mod/load_strategy/set_binding_magic.rb (100%) rename card/lib/{card => cardio}/mod/load_strategy/set_tmp_files.rb (100%) rename card/lib/{card => cardio}/mod/load_strategy/tmp_files.rb (100%) rename card/lib/{card => cardio}/mod/loader.rb (100%) rename card/lib/{card => cardio}/mod/loader/set_loader.rb (100%) rename card/lib/{card => cardio}/mod/loader/set_pattern_loader.rb (100%) rename card/lib/{card => cardio}/mod/module_template.rb (100%) rename card/lib/{card => }/tasks/card.rake (100%) rename card/lib/{card => }/tasks/card/file_card_creator.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/abstract_file_card.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/abstract_file_card/migration_file.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/abstract_file_card/source_file.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/haml_card.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/output_helper.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/script_card.rb (100%) rename card/lib/{card => }/tasks/card/file_card_creator/style_card.rb (100%) rename card/lib/{card/tasks/card => tasks}/create.rake (100%) rename {decko/lib/decko => card/lib}/tasks/db.rake (100%) rename card/lib/{card/tasks/card => tasks}/migrate.rake (100%) rename {decko/lib/decko/tasks/decko => card/lib/tasks}/seed.rake (100%) rename decko/lib/{decko => }/tasks/alias.rb (100%) rename decko/lib/{decko => }/tasks/cucumber.rake (100%) rename decko/lib/{decko => }/tasks/decko.rake (99%) rename decko/lib/{decko/tasks/decko => tasks}/docs.rake (100%) rename decko/lib/{decko/tasks/decko => tasks}/tmpsets.rake (100%) diff --git a/card/lib/cardio.rb b/card/lib/cardio.rb index 2e2a6504da..ee4248789b 100644 --- a/card/lib/cardio.rb +++ b/card/lib/cardio.rb @@ -19,9 +19,32 @@ module Cardio extend Delaying CARD_GEM_ROOT = File.expand_path("..", __dir__) - mattr_reader :paths, :config + module RailsConfigMethods + # FIXME: use in Deck, Engine, etc. + def root + Rails.root + end + + def application + Rails.application + end + + def config + application.config + end + + def paths + application.paths + end + end class << self + include RailsConfigMethods + + def gem_root + CARD_GEM_ROOT + end + def card_defined? const_defined? "Card" end @@ -32,11 +55,6 @@ def load_card? false end - def load_card! - require "card" - ActiveSupport.run_load_hooks :after_card - end - def cache @cache ||= ::Rails.cache end @@ -105,17 +123,15 @@ def default_configs } end - def set_config config - @@config = config - - add_lib_dirs_to_autoload_paths config + def set_config + add_lib_dirs_to_autoload_paths default_configs.each_pair do |setting, value| set_default_value(config, setting, *value) end end - def add_lib_dirs_to_autoload_paths config + def add_lib_dirs_to_autoload_paths config.autoload_paths += Dir["#{gem_root}/lib"] # TODO: this should use each_mod_path, but it's not available when this is run @@ -147,8 +163,7 @@ def set_default_value config, setting, *value config.send("#{setting}=", *value) unless config.respond_to? setting end - def set_paths paths - @@paths = paths + def set_paths %w[set set_pattern].each do |path| tmppath = "tmp/#{path}" add_path tmppath, root: root unless paths[tmppath]&.existent @@ -189,14 +204,6 @@ def add_initializers base_dir, mod=false, init_dir="initializers" end end - def root - @@config.root - end - - def gem_root - CARD_GEM_ROOT - end - def add_path path, options={} root = options.delete(:root) || gem_root options[:with] = File.join(root, (options[:with] || path)) diff --git a/decko/lib/decko/commands/application.rb b/card/lib/cardio/commands/commands/application.rb similarity index 100% rename from decko/lib/decko/commands/application.rb rename to card/lib/cardio/commands/commands/application.rb diff --git a/decko/lib/decko/commands/command.rb b/card/lib/cardio/commands/commands/command.rb similarity index 100% rename from decko/lib/decko/commands/command.rb rename to card/lib/cardio/commands/commands/command.rb diff --git a/decko/lib/decko/commands/cucumber_command.rb b/card/lib/cardio/commands/commands/cucumber_command.rb similarity index 100% rename from decko/lib/decko/commands/cucumber_command.rb rename to card/lib/cardio/commands/commands/cucumber_command.rb diff --git a/decko/lib/decko/commands/cucumber_command/parser.rb b/card/lib/cardio/commands/commands/cucumber_command/parser.rb similarity index 100% rename from decko/lib/decko/commands/cucumber_command/parser.rb rename to card/lib/cardio/commands/commands/cucumber_command/parser.rb diff --git a/decko/lib/decko/commands/rake_command.rb b/card/lib/cardio/commands/commands/rake_command.rb similarity index 100% rename from decko/lib/decko/commands/rake_command.rb rename to card/lib/cardio/commands/commands/rake_command.rb diff --git a/decko/lib/decko/commands/rake_command/parser.rb b/card/lib/cardio/commands/commands/rake_command/parser.rb similarity index 100% rename from decko/lib/decko/commands/rake_command/parser.rb rename to card/lib/cardio/commands/commands/rake_command/parser.rb diff --git a/decko/lib/decko/commands/rspec_command.rb b/card/lib/cardio/commands/commands/rspec_command.rb similarity index 100% rename from decko/lib/decko/commands/rspec_command.rb rename to card/lib/cardio/commands/commands/rspec_command.rb diff --git a/decko/lib/decko/commands/rspec_command/parser.rb b/card/lib/cardio/commands/commands/rspec_command/parser.rb similarity index 100% rename from decko/lib/decko/commands/rspec_command/parser.rb rename to card/lib/cardio/commands/commands/rspec_command/parser.rb diff --git a/card/lib/card/mod.rb b/card/lib/cardio/mod.rb similarity index 100% rename from card/lib/card/mod.rb rename to card/lib/cardio/mod.rb diff --git a/card/lib/card/mod/dirs.rb b/card/lib/cardio/mod/dirs.rb similarity index 100% rename from card/lib/card/mod/dirs.rb rename to card/lib/cardio/mod/dirs.rb diff --git a/card/lib/card/mod/load_strategy.rb b/card/lib/cardio/mod/load_strategy.rb similarity index 100% rename from card/lib/card/mod/load_strategy.rb rename to card/lib/cardio/mod/load_strategy.rb diff --git a/card/lib/card/mod/load_strategy/eval.rb b/card/lib/cardio/mod/load_strategy/eval.rb similarity index 100% rename from card/lib/card/mod/load_strategy/eval.rb rename to card/lib/cardio/mod/load_strategy/eval.rb diff --git a/card/lib/card/mod/load_strategy/pattern_tmp_files.rb b/card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb similarity index 100% rename from card/lib/card/mod/load_strategy/pattern_tmp_files.rb rename to card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb diff --git a/card/lib/card/mod/load_strategy/set_binding_magic.rb b/card/lib/cardio/mod/load_strategy/set_binding_magic.rb similarity index 100% rename from card/lib/card/mod/load_strategy/set_binding_magic.rb rename to card/lib/cardio/mod/load_strategy/set_binding_magic.rb diff --git a/card/lib/card/mod/load_strategy/set_tmp_files.rb b/card/lib/cardio/mod/load_strategy/set_tmp_files.rb similarity index 100% rename from card/lib/card/mod/load_strategy/set_tmp_files.rb rename to card/lib/cardio/mod/load_strategy/set_tmp_files.rb diff --git a/card/lib/card/mod/load_strategy/tmp_files.rb b/card/lib/cardio/mod/load_strategy/tmp_files.rb similarity index 100% rename from card/lib/card/mod/load_strategy/tmp_files.rb rename to card/lib/cardio/mod/load_strategy/tmp_files.rb diff --git a/card/lib/card/mod/loader.rb b/card/lib/cardio/mod/loader.rb similarity index 100% rename from card/lib/card/mod/loader.rb rename to card/lib/cardio/mod/loader.rb diff --git a/card/lib/card/mod/loader/set_loader.rb b/card/lib/cardio/mod/loader/set_loader.rb similarity index 100% rename from card/lib/card/mod/loader/set_loader.rb rename to card/lib/cardio/mod/loader/set_loader.rb diff --git a/card/lib/card/mod/loader/set_pattern_loader.rb b/card/lib/cardio/mod/loader/set_pattern_loader.rb similarity index 100% rename from card/lib/card/mod/loader/set_pattern_loader.rb rename to card/lib/cardio/mod/loader/set_pattern_loader.rb diff --git a/card/lib/card/mod/module_template.rb b/card/lib/cardio/mod/module_template.rb similarity index 100% rename from card/lib/card/mod/module_template.rb rename to card/lib/cardio/mod/module_template.rb diff --git a/card/lib/card/tasks/card.rake b/card/lib/tasks/card.rake similarity index 100% rename from card/lib/card/tasks/card.rake rename to card/lib/tasks/card.rake diff --git a/card/lib/card/tasks/card/file_card_creator.rb b/card/lib/tasks/card/file_card_creator.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator.rb rename to card/lib/tasks/card/file_card_creator.rb diff --git a/card/lib/card/tasks/card/file_card_creator/abstract_file_card.rb b/card/lib/tasks/card/file_card_creator/abstract_file_card.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/abstract_file_card.rb rename to card/lib/tasks/card/file_card_creator/abstract_file_card.rb diff --git a/card/lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb b/card/lib/tasks/card/file_card_creator/abstract_file_card/migration_file.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb rename to card/lib/tasks/card/file_card_creator/abstract_file_card/migration_file.rb diff --git a/card/lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb b/card/lib/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb rename to card/lib/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb diff --git a/card/lib/card/tasks/card/file_card_creator/abstract_file_card/source_file.rb b/card/lib/tasks/card/file_card_creator/abstract_file_card/source_file.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/abstract_file_card/source_file.rb rename to card/lib/tasks/card/file_card_creator/abstract_file_card/source_file.rb diff --git a/card/lib/card/tasks/card/file_card_creator/haml_card.rb b/card/lib/tasks/card/file_card_creator/haml_card.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/haml_card.rb rename to card/lib/tasks/card/file_card_creator/haml_card.rb diff --git a/card/lib/card/tasks/card/file_card_creator/output_helper.rb b/card/lib/tasks/card/file_card_creator/output_helper.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/output_helper.rb rename to card/lib/tasks/card/file_card_creator/output_helper.rb diff --git a/card/lib/card/tasks/card/file_card_creator/script_card.rb b/card/lib/tasks/card/file_card_creator/script_card.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/script_card.rb rename to card/lib/tasks/card/file_card_creator/script_card.rb diff --git a/card/lib/card/tasks/card/file_card_creator/style_card.rb b/card/lib/tasks/card/file_card_creator/style_card.rb similarity index 100% rename from card/lib/card/tasks/card/file_card_creator/style_card.rb rename to card/lib/tasks/card/file_card_creator/style_card.rb diff --git a/card/lib/card/tasks/card/create.rake b/card/lib/tasks/create.rake similarity index 100% rename from card/lib/card/tasks/card/create.rake rename to card/lib/tasks/create.rake diff --git a/decko/lib/decko/tasks/db.rake b/card/lib/tasks/db.rake similarity index 100% rename from decko/lib/decko/tasks/db.rake rename to card/lib/tasks/db.rake diff --git a/card/lib/card/tasks/card/migrate.rake b/card/lib/tasks/migrate.rake similarity index 100% rename from card/lib/card/tasks/card/migrate.rake rename to card/lib/tasks/migrate.rake diff --git a/decko/lib/decko/tasks/decko/seed.rake b/card/lib/tasks/seed.rake similarity index 100% rename from decko/lib/decko/tasks/decko/seed.rake rename to card/lib/tasks/seed.rake diff --git a/decko/lib/decko.rb b/decko/lib/decko.rb index 2f8965631d..bf4e7d67f0 100644 --- a/decko/lib/decko.rb +++ b/decko/lib/decko.rb @@ -2,22 +2,9 @@ module Decko DECKO_GEM_ROOT = File.expand_path("../..", __FILE__) - class << self - def root - Rails.root - end - - def application - Rails.application - end - def config - application.config - end - - def paths - application.paths - end + class << self + include Cardio::RailsConfigMethods def gem_root DECKO_GEM_ROOT diff --git a/decko/lib/decko/application.rb b/decko/lib/decko/application.rb index 7753e78112..0609f24524 100644 --- a/decko/lib/decko/application.rb +++ b/decko/lib/decko/application.rb @@ -30,17 +30,16 @@ def add_path paths, path, options={} paths.add path, options end - def config - @config ||= begin - config = super + def configure &block + super do - Cardio.set_config config + instance_eval(&block) if block_given? # any config settings below: # (a) do not apply to Card used outside of a Decko context # (b) cannot be overridden in a deck's application.rb, but # (c) CAN be overridden in an environment file - + # therefore, in general, they should be restricted to settings that # (1) are specific to the web environment, and # (2) should not be overridden @@ -64,14 +63,9 @@ def config # Rails.autoloaders.log! Rails.autoloaders.main.ignore(File.join(Cardio.gem_root, "lib/card/seed_consts.rb")) - config - end - end - def paths - @paths ||= begin - paths = super - Cardio.set_paths paths + # paths configurations + Cardio.set_paths paths.add "files" @@ -82,8 +76,6 @@ def paths add_path paths, "config/routes.rb", with: "rails/application-routes.rb" end - - paths end end end diff --git a/decko/lib/decko/engine.rb b/decko/lib/decko/engine.rb index 09e6cf9463..3a7099a15d 100644 --- a/decko/lib/decko/engine.rb +++ b/decko/lib/decko/engine.rb @@ -18,16 +18,17 @@ class Engine < ::Rails::Engine paths.add "app/controllers", with: "rails/controllers", eager_load: true paths.add "gem-assets", with: "rails/assets" paths.add "config/routes.rb", with: "rails/engine-routes.rb" - paths.add "lib/tasks", with: "#{::Decko.gem_root}/lib/decko/tasks", + paths.add "lib/tasks", with: "#{::Decko.gem_root}/lib/tasks", glob: "**/*.rake" - paths["lib/tasks"] << "#{::Cardio.gem_root}/lib/card/tasks" - paths.add "lib/decko/config/initializers", + # FIXME, belongs in parent + paths["lib/tasks"] << "#{::Cardio.gem_root}/lib/tasks" + paths.add "lib/config/initializers", with: File.join(Decko.gem_root, "lib/decko/config/initializers"), glob: "**/*.rb" initializer "decko.engine.load_config_initializers", after: :load_config_initializers do - paths["lib/decko/config/initializers"].existent.sort.each do |initializer| + paths["lib/config/initializers"].existent.sort.each do |initializer| load(initializer) end end diff --git a/decko/lib/decko/tasks/alias.rb b/decko/lib/tasks/alias.rb similarity index 100% rename from decko/lib/decko/tasks/alias.rb rename to decko/lib/tasks/alias.rb diff --git a/decko/lib/decko/tasks/cucumber.rake b/decko/lib/tasks/cucumber.rake similarity index 100% rename from decko/lib/decko/tasks/cucumber.rake rename to decko/lib/tasks/cucumber.rake diff --git a/decko/lib/decko/tasks/decko.rake b/decko/lib/tasks/decko.rake similarity index 99% rename from decko/lib/decko/tasks/decko.rake rename to decko/lib/tasks/decko.rake index 6087ea7483..9de8a20bc6 100644 --- a/decko/lib/decko/tasks/decko.rake +++ b/decko/lib/tasks/decko.rake @@ -1,5 +1,5 @@ require "decko/application" -require_relative "alias" +require "tasks/alias" require "card/seed_consts" CARD_TASKS = diff --git a/decko/lib/decko/tasks/decko/docs.rake b/decko/lib/tasks/docs.rake similarity index 100% rename from decko/lib/decko/tasks/decko/docs.rake rename to decko/lib/tasks/docs.rake diff --git a/decko/lib/decko/tasks/decko/tmpsets.rake b/decko/lib/tasks/tmpsets.rake similarity index 100% rename from decko/lib/decko/tasks/decko/tmpsets.rake rename to decko/lib/tasks/tmpsets.rake From a50df9f33718ef2efd13dab91f333f82d4a47d4f Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Mon, 5 Oct 2020 19:34:27 -0500 Subject: [PATCH 02/11] more Card to Cardio, and some application.rb changes --- card-mod-account/set/right/account/views.rb | 2 +- card-mod-account/set/right/api_key.rb | 2 +- .../set/type/user/setup_help.haml | 2 +- .../spec/set/right/account_spec.rb | 4 +- .../lib/carrier_wave/file_card_uploader.rb | 2 +- .../set/abstract/attachment/paths.rb | 2 +- card-mod-history/lib/card/act.rb | 2 +- card-mod-history/lib/card/action.rb | 2 +- .../set/all/history/act_listing.rb | 2 +- card/README.md | 6 +- card/card.gemspec | 5 +- .../initializers/02_patches/zeitwerk.rb | 4 +- .../20141119001955_make_symlinks_relative.rb | 2 +- .../20190204195039_add_rule_card.rb | 2 +- card/db/seeds.rb | 2 +- card/lib/card.rb | 4 +- card/lib/card/auth.rb | 2 +- card/lib/card/auth/permissions.rb | 2 +- card/lib/card/auth/token.rb | 2 +- card/lib/card/content/chunk.rb | 2 +- card/lib/card/env.rb | 2 +- card/lib/card/env/location.rb | 4 +- card/lib/card/env/request_assignments.rb | 4 +- card/lib/card/format.rb | 4 +- card/lib/card/format/error.rb | 4 +- card/lib/card/format/nesting.rb | 4 +- card/lib/card/mailer.rb | 2 +- card/lib/card/query/card_query.rb | 2 +- card/lib/card/query/sql_statement.rb | 2 +- card/lib/card/set.rb | 2 +- card/lib/card/set/event.rb | 4 +- card/lib/card/set/format.rb | 4 +- card/lib/card/set/format/abstract_format.rb | 2 +- card/lib/card/set/i18n_scope.rb | 2 +- card/lib/card/view/cache/cache_action.rb | 2 +- card/lib/cardio.rb | 2 +- card/lib/cardio/application.rb | 83 +++++++++++++++++++ .../commands/commands/cucumber_command.rb | 2 +- .../config/initializers/sedate_parser.rb | 0 card/lib/cardio/mod.rb | 4 +- card/lib/cardio/mod/dirs.rb | 2 +- .../mod/load_strategy/pattern_tmp_files.rb | 2 +- .../lib/cardio/mod/load_strategy/tmp_files.rb | 4 +- card/lib/cardio/mod/loader.rb | 12 +-- card/lib/cardio/modfiles.rb | 2 +- card/lib/tasks/migrate.rake | 2 +- card/mod/admin/set/self/admin.rb | 2 +- card/mod/admin/set/self/admin_info.rb | 2 +- card/mod/basic_formats/set/all/head.rb | 4 +- card/mod/core/set/abstract/code_file.rb | 2 +- card/mod/core/set/all/permissions.rb | 4 +- card/mod/core/set/all/trash.rb | 2 +- .../spec/set/abstract/machine_spec.rb | 2 +- card/mod/search/set/abstract/search/views.rb | 2 +- card/mod/search/set/self/search.rb | 2 +- card/mod/standard/set/all/path.rb | 2 +- card/mod/standard/set/all/rich_html/error.rb | 2 +- card/mod/standard/spec/set/all/path_spec.rb | 4 +- card/spec/card/content_spec.rb | 2 +- card/spec/card/loader_spec.rb | 6 +- card/spec/card/mod/loader/mod_dirs.rb | 4 +- card/spec/card/mod/loader/set_loader_spec.rb | 6 +- .../mod/loader/set_pattern_loader_spec.rb | 6 +- card/spec/card/mod_spec.rb | 2 +- card/spec/card/set/event_spec.rb | 2 +- card/spec/support/card_spec_helper.rb | 4 +- card/spec/support/card_spec_loader.rb | 2 +- decko/features/support/delayed_job.rb | 2 +- decko/lib/decko/application.rb | 30 +++---- decko/lib/tasks/decko.rake | 2 +- 70 files changed, 194 insertions(+), 116 deletions(-) create mode 100644 card/lib/cardio/application.rb rename {decko/lib/decko => card/lib/cardio}/config/initializers/sedate_parser.rb (100%) diff --git a/card-mod-account/set/right/account/views.rb b/card-mod-account/set/right/account/views.rb index e260738e06..534b5e6516 100644 --- a/card-mod-account/set/right/account/views.rb +++ b/card-mod-account/set/right/account/views.rb @@ -16,7 +16,7 @@ end view :token_days do - Card.config.token_expiry / 1.day + Cardio.config.token_expiry / 1.day end # DEPRECATED diff --git a/card-mod-account/set/right/api_key.rb b/card-mod-account/set/right/api_key.rb index d2467401eb..01caa5aba7 100644 --- a/card-mod-account/set/right/api_key.rb +++ b/card-mod-account/set/right/api_key.rb @@ -34,7 +34,7 @@ def validate! api_key # if expiration.present? # term_from_string expiration # else -# Card.config.token_expiry +# Cardio.config.token_expiry # end # end diff --git a/card-mod-account/set/type/user/setup_help.haml b/card-mod-account/set/type/user/setup_help.haml index 84c9120032..0a8b47dc29 100644 --- a/card-mod-account/set/type/user/setup_help.haml +++ b/card-mod-account/set/type/user/setup_help.haml @@ -4,7 +4,7 @@ permissioned roles. You can configure these roles at any time. -- if Card.config.action_mailer.perform_deliveries == false +- if Cardio.config.action_mailer.perform_deliveries == false .bg-warning.p-3 WARNING: Email delivery is turned off. Change settings in config/application.rb to send sign up notifications. diff --git a/card-mod-account/spec/set/right/account_spec.rb b/card-mod-account/spec/set/right/account_spec.rb index 0c23c6cc5c..c8190fba7b 100644 --- a/card-mod-account/spec/set/right/account_spec.rb +++ b/card-mod-account/spec/set/right/account_spec.rb @@ -78,7 +78,7 @@ end it "contains expiry days" do - msg = "valid for #{Card.config.token_expiry / 1.day} days" + msg = "valid for #{Cardio.config.token_expiry / 1.day} days" expect(@mail.parts[0].body.raw_source).to include(msg) end end @@ -124,7 +124,7 @@ end it "contains expiry days" do - url = "valid for #{Card.config.token_expiry / 1.day} days" + url = "valid for #{Cardio.config.token_expiry / 1.day} days" expect(@mail.parts[0].body.raw_source).to include(url) end end diff --git a/card-mod-carrierwave/lib/carrier_wave/file_card_uploader.rb b/card-mod-carrierwave/lib/carrier_wave/file_card_uploader.rb index e87820df42..03a2be47a9 100644 --- a/card-mod-carrierwave/lib/carrier_wave/file_card_uploader.rb +++ b/card-mod-carrierwave/lib/carrier_wave/file_card_uploader.rb @@ -1,7 +1,7 @@ module CarrierWave class << self def tmp_path - @tmp_path ||= Card.paths["tmp"].existent.first + @tmp_path ||= Cardio.paths["tmp"].existent.first end end diff --git a/card-mod-carrierwave/set/abstract/attachment/paths.rb b/card-mod-carrierwave/set/abstract/attachment/paths.rb index 210a30fe8e..0c4ddeae9b 100644 --- a/card-mod-carrierwave/set/abstract/attachment/paths.rb +++ b/card-mod-carrierwave/set/abstract/attachment/paths.rb @@ -29,7 +29,7 @@ def mod_dir new_mod=nil end def files_base_dir - dir = bucket ? bucket_config[:subdirectory] : Card.paths["files"].existent.first + dir = bucket ? bucket_config[:subdirectory] : Cardio.paths["files"].existent.first dir || files_base_dir_configuration_error end diff --git a/card-mod-history/lib/card/act.rb b/card-mod-history/lib/card/act.rb index 28b5d03341..cf36474e1c 100644 --- a/card-mod-history/lib/card/act.rb +++ b/card-mod-history/lib/card/act.rb @@ -16,7 +16,7 @@ class Card # - _acted_at_, a timestamp of the action # - the _ip_address_ of the actor where applicable. # - class Act < ApplicationRecord + class Act < Cardio::ApplicationRecord before_save :assign_actor has_many :ar_actions, -> { order :id }, foreign_key: :card_act_id, inverse_of: :act, diff --git a/card-mod-history/lib/card/action.rb b/card-mod-history/lib/card/action.rb index 8e2fbf3447..ace0a6ea7f 100644 --- a/card-mod-history/lib/card/action.rb +++ b/card-mod-history/lib/card/action.rb @@ -20,7 +20,7 @@ class Card # * a boolean indicated whether the action is a _draft_ # * a _comment_ (where applicable) # - class Action < ApplicationRecord + class Action < Cardio::ApplicationRecord include Differ extend Admin diff --git a/card-mod-history/set/all/history/act_listing.rb b/card-mod-history/set/all/history/act_listing.rb index 88e9e28791..c806cf5fc2 100644 --- a/card-mod-history/set/all/history/act_listing.rb +++ b/card-mod-history/set/all/history/act_listing.rb @@ -1,4 +1,4 @@ -ACTS_PER_PAGE = Card.config.acts_per_page +ACTS_PER_PAGE = Cardio.config.acts_per_page format :html do def act_from_context diff --git a/card/README.md b/card/README.md index c970b958e6..51b32d57b3 100644 --- a/card/README.md +++ b/card/README.md @@ -109,12 +109,12 @@ really), because Set functionality is almost always developed using our Set DSL, which automatically handles the ruby module naming based on the file name. -Cards, Formats, Sets, and other structures can all be developed via {Card::Mod +Cards, Formats, Sets, and other structures can all be developed via {Cardio::Mod Mods}. ## Mods -{Card::Mod Card Mods} (short for *modules* or *modifications*) are the primary +{Cardio::Mod Card Mods} (short for *modules* or *modifications*) are the primary mechanism for developing and sharing Decko code. If you're just getting -started as a Decko developer, learning about {Card::Mod Mods} is a great next +started as a Decko developer, learning about {Cardio::Mod Mods} is a great next step. diff --git a/card/card.gemspec b/card/card.gemspec index da16f07f7a..901fd1a054 100644 --- a/card/card.gemspec +++ b/card/card.gemspec @@ -11,9 +11,12 @@ DeckoGem.gem "card" do |s, d| 'Card "Sharks" use links, nests, types, patterned names, queries, views, ' \ "events, and rules to create rich structures." - s.files = Dir["VERSION", "README.md", "LICENSE", "GPL", ".yardopts", + s.files = Dir["VERSION", "README.rdoc", "LICENSE", "GPL", ".yardopts", "{config,db,lib,mod,tmpsets}/**/*"] + s.bindir = "bin" + s.executables = ["card"] + [ ["cardname", d.decko_version], diff --git a/card/config/initializers/02_patches/zeitwerk.rb b/card/config/initializers/02_patches/zeitwerk.rb index 8eb9b46cda..a4d27591f7 100644 --- a/card/config/initializers/02_patches/zeitwerk.rb +++ b/card/config/initializers/02_patches/zeitwerk.rb @@ -4,10 +4,10 @@ def reload super return unless reloading_enabled? - # reloading the Card class triggers also ::Card::Mod.load + # reloading the Card class triggers also ::Cardio::Mod.load # via the after_card hook ::Card - # ::Card::Mod.load + # ::Cardio::Mod.load end end end diff --git a/card/db/migrate_core_cards/20141119001955_make_symlinks_relative.rb b/card/db/migrate_core_cards/20141119001955_make_symlinks_relative.rb index 85b2c21dd9..8f731a1fc4 100644 --- a/card/db/migrate_core_cards/20141119001955_make_symlinks_relative.rb +++ b/card/db/migrate_core_cards/20141119001955_make_symlinks_relative.rb @@ -2,7 +2,7 @@ class MakeSymlinksRelative < Card::Migration def up - Card.paths["files"].each do |file_path| + Cardio.paths["files"].each do |file_path| files = Dir.glob(File.join file_path, "**", "*") symlinks = files.select { |f| File.symlink? f } symlinks.each do |symlink| diff --git a/card/db/migrate_core_cards/20190204195039_add_rule_card.rb b/card/db/migrate_core_cards/20190204195039_add_rule_card.rb index 539db1d4a1..cc9904d3d9 100644 --- a/card/db/migrate_core_cards/20190204195039_add_rule_card.rb +++ b/card/db/migrate_core_cards/20190204195039_add_rule_card.rb @@ -5,6 +5,6 @@ def up ensure_card "*rule", codename: "rule", type_id: Card::SetID # the following re-registers set patterns, now including the rule pattern - Card::Mod::Loader.reload_sets + Cardio::Mod::Loader.reload_sets end end diff --git a/card/db/seeds.rb b/card/db/seeds.rb index 9653079f36..699416cf08 100644 --- a/card/db/seeds.rb +++ b/card/db/seeds.rb @@ -1,4 +1,4 @@ require "card/seed_consts" require "active_record/fixtures" ActiveRecord::FixtureSet.create_fixtures CARD_SEED_PATH, CARD_SEED_TABLES -Card::Mod::Loader.load_mods +Cardio::Mod::Loader.load_mods diff --git a/card/lib/card.rb b/card/lib/card.rb index ff6de5b210..ada088b681 100644 --- a/card/lib/card.rb +++ b/card/lib/card.rb @@ -92,7 +92,7 @@ # card presentation, while events customize card transactions. Or, if you like, views # and events respectively alter cards in _space_ and _time_. # -# Both views and events are defined in {Card::Mod mods}, short for modules or +# Both views and events are defined in {Cardio::Mod mods}, short for modules or # modifications. # # {Card::Set::Format::AbstractFormat More on views} @@ -110,7 +110,7 @@ # can be temporarily assumed using `Card::Auth#as`. # # {Card::Auth More on accounts} -class Card < ApplicationRecord +class Card extend Mark extend Dirty::MethodFactory include Dirty diff --git a/card/lib/card/auth.rb b/card/lib/card/auth.rb index ca5230ad66..d61bd64478 100644 --- a/card/lib/card/auth.rb +++ b/card/lib/card/auth.rb @@ -23,7 +23,7 @@ def authenticate email, password case when !account then nil when !account.active? then nil - when Card.config.no_authentication then account + when Cardio.config.no_authentication then account when password_valid?(account, password.strip) then account end end diff --git a/card/lib/card/auth/permissions.rb b/card/lib/card/auth/permissions.rb index 99f11e8609..0c8811414d 100644 --- a/card/lib/card/auth/permissions.rb +++ b/card/lib/card/auth/permissions.rb @@ -45,7 +45,7 @@ def createable_types Auth.as_bot do Card.search( { type: Card::CardtypeID, return: :name, - not: { codename: ["in"] + Card.config.non_createable_types } }, + not: { codename: ["in"] + Cardio.config.non_createable_types } }, "find createable types" ) end diff --git a/card/lib/card/auth/token.rb b/card/lib/card/auth/token.rb index a8a71f0bee..721bcdd148 100644 --- a/card/lib/card/auth/token.rb +++ b/card/lib/card/auth/token.rb @@ -30,7 +30,7 @@ def decode token end def expiration - Card.config.token_expiry.from_now.to_i + Cardio.config.token_expiry.from_now.to_i end end end diff --git a/card/lib/card/content/chunk.rb b/card/lib/card/content/chunk.rb index 3d8cc3079a..9d869c84c7 100644 --- a/card/lib/card/content/chunk.rb +++ b/card/lib/card/content/chunk.rb @@ -92,5 +92,5 @@ def validate_chunk_list_key chunk_list_key register_list :references_keep_escaping, %i[KeepEscapedLiteral Nest Link] end end - Card::Mod::Loader.load_chunks + Cardio::Mod::Loader.load_chunks end diff --git a/card/lib/card/env.rb b/card/lib/card/env.rb index 11597f4e6a..296b322b2f 100644 --- a/card/lib/card/env.rb +++ b/card/lib/card/env.rb @@ -2,7 +2,7 @@ class Card # Card::Env is a module for containing the variable details of the environment # in which Card operates. # - # Env can differ for each request; Card.config should not. + # Env can differ for each request; Cardio.config should not. module Env extend LocationHistory extend RequestAssignments diff --git a/card/lib/card/env/location.rb b/card/lib/card/env/location.rb index 88018a219e..4640da90b0 100644 --- a/card/lib/card/env/location.rb +++ b/card/lib/card/env/location.rb @@ -12,7 +12,7 @@ def card_path rel_path if rel_path =~ %r{^(https?\:)?/} rel_path else - "#{Card.config.relative_url_root}/#{rel_path}" + "#{Cardio.config.relative_url_root}/#{rel_path}" end end @@ -21,7 +21,7 @@ def card_url rel end def protocol_and_host - Card.config.protocol_and_host || "#{Env[:protocol]}#{Env[:host]}" + Cardio.config.protocol_and_host || "#{Env[:protocol]}#{Env[:host]}" end def cardname_from_url url diff --git a/card/lib/card/env/request_assignments.rb b/card/lib/card/env/request_assignments.rb index 0b9d78bb5d..93140ca406 100644 --- a/card/lib/card/env/request_assignments.rb +++ b/card/lib/card/env/request_assignments.rb @@ -13,11 +13,11 @@ def assign_html c end def assign_host c - Card.config.override_host || c.request.env["HTTP_HOST"] + Cardio.config.override_host || c.request.env["HTTP_HOST"] end def assign_protocol c - Card.config.override_protocol || c.request.protocol + Cardio.config.override_protocol || c.request.protocol end end end diff --git a/card/lib/card/format.rb b/card/lib/card/format.rb index 6baa2e5e8d..36820a41db 100644 --- a/card/lib/card/format.rb +++ b/card/lib/card/format.rb @@ -6,9 +6,9 @@ class Card # are responsible for defining and rendering _views_. # # However, monkeys (those who code in the Card/Decko framework) rarely write code - # directly in these classes. Instead they organize their code using {Card::Mod mods}. + # directly in these classes. Instead they organize their code using {Cardio::Mod mods}. # - # {Card::Mod} explains how to set up a mod. + # {Cardio::Mod} explains how to set up a mod. # {Card::Set::Format} explains how to use this and other format classes within a mod. # {Card::Set::Format::AbstractFormat} introduces the view API, which is organized with # these format classes. diff --git a/card/lib/card/format/error.rb b/card/lib/card/format/error.rb index 5309b61880..1802fbbb64 100644 --- a/card/lib/card/format/error.rb +++ b/card/lib/card/format/error.rb @@ -29,7 +29,7 @@ def view_for_denial view, task end def monitor_depth - raise Card::Error::UserError, tr(:too_deep) if depth >= Card.config.max_depth + raise Card::Error::UserError, tr(:too_deep) if depth >= Cardio.config.max_depth yield end @@ -47,7 +47,7 @@ def error_cardname _exception end def loud_error? - focal? || Card.config.raise_all_rendering_errors + focal? || Cardio.config.raise_all_rendering_errors end def loud_error e, view diff --git a/card/lib/card/format/nesting.rb b/card/lib/card/format/nesting.rb index b56f9d377e..f0d0bdf4d2 100644 --- a/card/lib/card/format/nesting.rb +++ b/card/lib/card/format/nesting.rb @@ -63,11 +63,11 @@ def count_chars end def max_depth - Card.config.max_depth + Cardio.config.max_depth end def max_char_count - Card.config.max_char_count + Cardio.config.max_char_count end end end diff --git a/card/lib/card/mailer.rb b/card/lib/card/mailer.rb index 4fdd599a46..5541351fd0 100644 --- a/card/lib/card/mailer.rb +++ b/card/lib/card/mailer.rb @@ -4,7 +4,7 @@ class Card class Mailer < ActionMailer::Base - @@defaults = Card.config.email_defaults || {} + @@defaults = Cardio.config.email_defaults || {} @@defaults.symbolize_keys! @@defaults[:return_path] ||= @@defaults[:from] if @@defaults[:from] @@defaults[:charset] ||= "utf-8" diff --git a/card/lib/card/query/card_query.rb b/card/lib/card/query/card_query.rb index 5b5779ab81..ec27981a17 100644 --- a/card/lib/card/query/card_query.rb +++ b/card/lib/card/query/card_query.rb @@ -37,7 +37,7 @@ def initialize statement, comment=nil end def default_comment - return if @superquery || !Card.config.sql_comments + return if @superquery || !Cardio.config.sql_comments statement.to_s end diff --git a/card/lib/card/query/sql_statement.rb b/card/lib/card/query/sql_statement.rb index 7c49796013..b2053ee9bb 100644 --- a/card/lib/card/query/sql_statement.rb +++ b/card/lib/card/query/sql_statement.rb @@ -50,7 +50,7 @@ def leading_space end def comment - return nil unless Card.config.sql_comments && @query.comment + return nil unless Cardio.config.sql_comments && @query.comment "/* #{@query.comment} */\n" end diff --git a/card/lib/card/set.rb b/card/lib/card/set.rb index b2b038dff2..bd1baaaf34 100644 --- a/card/lib/card/set.rb +++ b/card/lib/card/set.rb @@ -11,7 +11,7 @@ class Card # web interface and are thus documented at https://decko.org/rules. # - **Code rules** can be defined in a 'set module'. # - # The {Card::Mod} docs explain how to create mods and set_modules. This page explains + # The {Cardio::Mod} docs explain how to create mods and set_modules. This page explains # how those modules become useful. # # Suppose you have created a "mod" for managing your contacts called "contactmanager", diff --git a/card/lib/card/set/event.rb b/card/lib/card/set/event.rb index eeb9639570..babdff5744 100644 --- a/card/lib/card/set/event.rb +++ b/card/lib/card/set/event.rb @@ -12,8 +12,8 @@ class Event # action has three phases, each phase has three stages, and each stage has many # events. # - # Events are defined in set modules in {Card::Mod **mods**}. Learn more about - # {Card::Mod set modules}. + # Events are defined in set modules in {Cardio::Mod **mods**}. Learn more about + # {Cardio::Mod set modules}. # # A simple event definition looks something like this: # diff --git a/card/lib/card/set/format.rb b/card/lib/card/set/format.rb index 6f5205584d..13044da5c7 100644 --- a/card/lib/card/set/format.rb +++ b/card/lib/card/set/format.rb @@ -2,8 +2,8 @@ class Card module Set - # This document explains how to use format blocks within {Card::Mod mods}. To make - # use of it, you will need to understand both {Card::Mod mods} and {Card::Set sets}. + # This document explains how to use format blocks within {Cardio::Mod mods}. To make + # use of it, you will need to understand both {Cardio::Mod mods} and {Card::Set sets}. # # Within a card mod, you can define format blocks like the following: # diff --git a/card/lib/card/set/format/abstract_format.rb b/card/lib/card/set/format/abstract_format.rb index 1736e6bc26..d2797926e8 100644 --- a/card/lib/card/set/format/abstract_format.rb +++ b/card/lib/card/set/format/abstract_format.rb @@ -4,7 +4,7 @@ class Card module Set module Format # AbstractFormat manages the basic format API, including API to define a {#view}. - # Whenever you create a format block in a set module in a {Card::Mod mod}, you + # Whenever you create a format block in a set module in a {Cardio::Mod mod}, you # create a format module that is extended with AbstractFormat. module AbstractFormat include Set::Basket diff --git a/card/lib/card/set/i18n_scope.rb b/card/lib/card/set/i18n_scope.rb index de96e2c6c8..35871c33ed 100644 --- a/card/lib/card/set/i18n_scope.rb +++ b/card/lib/card/set/i18n_scope.rb @@ -72,7 +72,7 @@ def path_parts backtrace # # def tmp_files? - Card.config.load_strategy == :tmp_files + Cardio.config.load_strategy == :tmp_files end def find_set_path backtrace diff --git a/card/lib/card/view/cache/cache_action.rb b/card/lib/card/view/cache/cache_action.rb index d6900f9a27..204e0429a1 100644 --- a/card/lib/card/view/cache/cache_action.rb +++ b/card/lib/card/view/cache/cache_action.rb @@ -40,7 +40,7 @@ def cache_status # @return [True/False] def cache_on? - Card.config.view_cache && format.class.view_caching? + Cardio.config.view_cache && format.class.view_caching? end # always skip all the magic diff --git a/card/lib/cardio.rb b/card/lib/cardio.rb index ee4248789b..5f03553148 100644 --- a/card/lib/cardio.rb +++ b/card/lib/cardio.rb @@ -9,7 +9,7 @@ require "cardio/delaying" ActiveSupport.on_load :after_card do - Card::Mod.load + Cardio::Mod.load end module Cardio diff --git a/card/lib/cardio/application.rb b/card/lib/cardio/application.rb new file mode 100644 index 0000000000..c0ef600054 --- /dev/null +++ b/card/lib/cardio/application.rb @@ -0,0 +1,83 @@ +# -*- encoding : utf-8 -*- + +require 'rails' + +Bundler.require :default, *Rails.groups + +if defined?(Bundler) + # If you precompile assets before deploying to production, use this line + Bundler.require *Rails.groups(assets: %w[development test cypress]) + # If you want your assets lazily compiled in production, use this line + # Bundler.require(:default, :assets, Rails.env) +end + +module Cardio + class Application < Rails::Application + class << self + def inherited base + super + Rails.app_class = base + add_lib_to_load_path!(find_root(base.called_from)) + ActiveSupport.run_load_hooks(:before_configuration, base.instance) + ActiveSupport.run_load_hooks(:load_active_record, base.instance) + ActiveSupport.run_load_hooks(:before_card) + end + end + + initializer :load_card_environment_config, + #after: :bootstrap, group: :all do + before: :load_environment_config, group: :all do + #before: :connect_on_load, group: :all do + add_path "lib/card/config/environments", glob: "#{Rails.env}.rb", root: Cardio.gem_root + paths["lib/card/config/environments"].existent.each do |environment| +warn "load env #{environment}" + require environment + end + end + + initializer :connect_on_load do + ActiveSupport.on_load(:active_record) do + c=ActiveRecord::Base.establish_connection(::Rails.env.to_sym) + ActiveSupport.run_load_hooks(:before_card) + require 'card/all' + + end + # ActiveSupport.on_load(:after_initialize) do + # # require "card" if Cardio.load_card? + # Card if Cardio.load_card? + # rescue ActiveRecord::StatementInvalid => e + # ::Rails.logger.warn "database not available[#{::Rails.env}] #{e}" + # end + ActiveSupport.on_load(:before_card) do + end + ActiveSupport.on_load(:after_application_record) do +warn "load ap rec trig, load card" + Cardio.load_card! + end + end + + def configure &block + super do + instance_eval &block if block_given? + + Cardio.set_config + + config.autoloader = :zeitwerk + config.load_default = "6.0" + config.i18n.enforce_available_locales = true + + Cardio.set_paths paths + end + end + + def root_path option + root = options.delete(:root) || Cardio.gem_root + end + + def add_path path, options={} + root = root_path_option options + options[:with] = File.join(root, (options[:with] || path)) + paths.add path, options + end + end +end diff --git a/card/lib/cardio/commands/commands/cucumber_command.rb b/card/lib/cardio/commands/commands/cucumber_command.rb index 8488f3f6f0..0534531b99 100644 --- a/card/lib/cardio/commands/commands/cucumber_command.rb +++ b/card/lib/cardio/commands/commands/cucumber_command.rb @@ -40,7 +40,7 @@ def require_args end def feature_paths - Card::Mod.dirs.map do |p| + Cardio::Mod.dirs.map do |p| Dir.glob "#{p}/features" end.flatten end diff --git a/decko/lib/decko/config/initializers/sedate_parser.rb b/card/lib/cardio/config/initializers/sedate_parser.rb similarity index 100% rename from decko/lib/decko/config/initializers/sedate_parser.rb rename to card/lib/cardio/config/initializers/sedate_parser.rb diff --git a/card/lib/cardio/mod.rb b/card/lib/cardio/mod.rb index c5a1b8d561..8dcc9e9a0e 100644 --- a/card/lib/cardio/mod.rb +++ b/card/lib/cardio/mod.rb @@ -67,7 +67,7 @@ def load return if ENV["CARD_MODS"] == "none" if Card.take - Card::Mod::Loader.load_mods + Cardio::Mod::Loader.load_mods else Rails.logger.warn "empty database" end @@ -75,7 +75,7 @@ def load # @return an array of Rails::Path objects def dirs - @dirs ||= Mod::Dirs.new(Card.paths["mod"].existent) + @dirs ||= Mod::Dirs.new(Cardio.paths["mod"].existent) end def dependencies name, nickname=true diff --git a/card/lib/cardio/mod/dirs.rb b/card/lib/cardio/mod/dirs.rb index cc6971c75f..66a3f56944 100644 --- a/card/lib/cardio/mod/dirs.rb +++ b/card/lib/cardio/mod/dirs.rb @@ -173,7 +173,7 @@ def load_from_gemfile def tmp_dir modname, type index = @mods.index modname - File.join Card.paths["tmp/#{type}"].first, + File.join Cardio.paths["tmp/#{type}"].first, "mod#{'%03d' % (index + 1)}-#{modname}" end end diff --git a/card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb b/card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb index ac2dd054bf..35c195a2f2 100644 --- a/card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb +++ b/card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb @@ -21,7 +21,7 @@ def load_tmp_files end def tmp_dir - Card.paths["tmp/set_pattern"].first + Cardio.paths["tmp/set_pattern"].first end end end diff --git a/card/lib/cardio/mod/load_strategy/tmp_files.rb b/card/lib/cardio/mod/load_strategy/tmp_files.rb index 7385d76d4f..aa52083419 100644 --- a/card/lib/cardio/mod/load_strategy/tmp_files.rb +++ b/card/lib/cardio/mod/load_strategy/tmp_files.rb @@ -18,7 +18,7 @@ def clean_comments? def prepare_tmp_dir path return unless rewrite_tmp_files? - p = Card.paths[path] + p = Cardio.paths[path] FileUtils.rm_rf p.first, secure: true if p.existent.first Dir.mkdir p.first end @@ -28,7 +28,7 @@ def rewrite_tmp_files? @rewrite else @rewrite = !(Rails.env.production? && - Card.paths["tmp/set"].existent.first) + Cardio.paths["tmp/set"].existent.first) end end diff --git a/card/lib/cardio/mod/loader.rb b/card/lib/cardio/mod/loader.rb index 2452b2407a..2b80122aeb 100644 --- a/card/lib/cardio/mod/loader.rb +++ b/card/lib/cardio/mod/loader.rb @@ -2,7 +2,7 @@ class Card module Mod - # Card::Mod::Loader is used to load all part of a mod, + # Cardio::Mod::Loader is used to load all part of a mod, # i.e. initializers, patterns, formats, chunks, layouts and sets # cards are not accessible at this point @@ -36,8 +36,8 @@ class << self def load_mods load_formats - Card::Mod::Loader::SetPatternLoader.new.load - Card::Mod::Loader::SetLoader.new.load + Cardio::Mod::Loader::SetPatternLoader.new.load + Cardio::Mod::Loader::SetLoader.new.load Card::Set.process_base_modules load_initializers end @@ -45,8 +45,8 @@ def load_mods def reload_sets Card::Set::Pattern.reset Card::Set.reset_modules - Card::Mod::Loader::SetPatternLoader.new.load - Card::Mod::Loader::SetLoader.new( + Cardio::Mod::Loader::SetPatternLoader.new.load + Cardio::Mod::Loader::SetLoader.new( patterns: Card::Set::Pattern.nonbase_loadable_codes ).load end @@ -64,7 +64,7 @@ def module_class_template # private def load_initializers - Card.config.paths["mod/config/initializers"].existent.sort.each do |initializer| + Cardio.config["mod/config/initializers"].existent.sort.each do |initializer| load initializer end end diff --git a/card/lib/cardio/modfiles.rb b/card/lib/cardio/modfiles.rb index b5d8f0d474..1a551e4185 100644 --- a/card/lib/cardio/modfiles.rb +++ b/card/lib/cardio/modfiles.rb @@ -36,7 +36,7 @@ def each_gem_mod_path def mod_migration_paths dir [].tap do |list| - Card::Mod.dirs.each("db/#{dir}") { |path| list.concat Dir.glob path } + Cardio::Mod.dirs.each("db/#{dir}") { |path| list.concat Dir.glob path } end end end diff --git a/card/lib/tasks/migrate.rake b/card/lib/tasks/migrate.rake index 571f4eb108..f177f852e9 100644 --- a/card/lib/tasks/migrate.rake +++ b/card/lib/tasks/migrate.rake @@ -8,7 +8,7 @@ def prepare_migration Card::Cache.reset_all ENV["SCHEMA"] ||= "#{Cardio.gem_root}/db/schema.rb" Card::Cache.reset_all - Card.config.action_mailer.perform_deliveries = false + Cardio.config.action_mailer.perform_deliveries = false Card.reset_column_information # this is needed in production mode to insure core db Card::Reference.reset_column_information diff --git a/card/mod/admin/set/self/admin.rb b/card/mod/admin/set/self/admin.rb index 9b881bb813..1d34e0ad5c 100644 --- a/card/mod/admin/set/self/admin.rb +++ b/card/mod/admin/set/self/admin.rb @@ -79,7 +79,7 @@ def cache_stats link_text: "clear machine cache", task: "clear_machine_cache" } ] - # return stats unless Card.config.view_cache# + # return stats unless Cardio.config.view_cache# # stats << { title: "view cache", # count: Card::View, # link_text: "clear view cache", diff --git a/card/mod/admin/set/self/admin_info.rb b/card/mod/admin/set/self/admin_info.rb index e2d2bf82d1..0d80c08fe1 100644 --- a/card/mod/admin/set/self/admin_info.rb +++ b/card/mod/admin/set/self/admin_info.rb @@ -8,7 +8,7 @@ add_to_basket :warnings, :no_email_delivery def no_email_delivery? - Card.config.action_mailer.perform_deliveries == false + Cardio.config.action_mailer.perform_deliveries == false end def clean_html? diff --git a/card/mod/basic_formats/set/all/head.rb b/card/mod/basic_formats/set/all/head.rb index 59c97e6aa8..180669fd21 100644 --- a/card/mod/basic_formats/set/all/head.rb +++ b/card/mod/basic_formats/set/all/head.rb @@ -71,7 +71,7 @@ def views_in_head def decko_script_variables { "window.decko": { rootUrl: card_url("") }, - "decko.doubleClick": Card.config.double_click, + "decko.doubleClick": Cardio.config.double_click, "decko.cssPath": head_stylesheet_path, "decko.currentUserId": (Auth.current_id if Auth.signed_in?) @@ -143,6 +143,6 @@ def trigger_slot_ready end def rss_link? - Card.config.rss_enabled && respond_to?(:rss_link_tag) + Cardio.config.rss_enabled && respond_to?(:rss_link_tag) end end diff --git a/card/mod/core/set/abstract/code_file.rb b/card/mod/core/set/abstract/code_file.rb index 5e4637851d..7326570779 100644 --- a/card/mod/core/set/abstract/code_file.rb +++ b/card/mod/core/set/abstract/code_file.rb @@ -28,7 +28,7 @@ def source_dir def find_file filename modname = file_content_mod_name modname = $1 if modname =~ /^card-mod-(\w*)/ - mod_path = Card::Mod.dirs.path modname + mod_path = Cardio::Mod.dirs.path modname file_path = File.join(mod_path, source_dir, filename) unless File.exist?(file_path) Rails.logger.info "couldn't locate file #{filename} at #{file_path}" diff --git a/card/mod/core/set/all/permissions.rb b/card/mod/core/set/all/permissions.rb index 37bc27a0a6..3887daf9e9 100644 --- a/card/mod/core/set/all/permissions.rb +++ b/card/mod/core/set/all/permissions.rb @@ -96,7 +96,7 @@ def deny_because why end def permitted? action - return false if Card.config.read_only # :read does not call #permit + return false if Cardio.config.read_only # :read does not call #permit return true if Auth.always_ok? Auth.as_card.among? who_can(action) @@ -104,7 +104,7 @@ def permitted? action def permit action, verb=nil # not called by ok_to_read - if Card.config.read_only + if Cardio.config.read_only deny_because "Currently in read-only mode" return false end diff --git a/card/mod/core/set/all/trash.rb b/card/mod/core/set/all/trash.rb index c5b8f64e4c..5609d095ab 100644 --- a/card/mod/core/set/all/trash.rb +++ b/card/mod/core/set/all/trash.rb @@ -39,7 +39,7 @@ def delete_trashed_files end def all_file_ids - dir = Card.paths["files"].existent.first + dir = Cardio.paths["files"].existent.first Dir.entries(dir)[2..-1].map(&:to_i) end diff --git a/card/mod/machines/spec/set/abstract/machine_spec.rb b/card/mod/machines/spec/set/abstract/machine_spec.rb index b75f7dd96d..0f2197ac52 100644 --- a/card/mod/machines/spec/set/abstract/machine_spec.rb +++ b/card/mod/machines/spec/set/abstract/machine_spec.rb @@ -4,7 +4,7 @@ describe "#make_machine_output_coded" do it "creates coded file" do Card[:all, :script].make_machine_output_coded - mod_path = Card::Mod.dirs.path "machines" + mod_path = Cardio::Mod.dirs.path "machines" path = File.join mod_path, "file", "all_script_machine_output", "file.js" expect(File.exist?(path)).to be_truthy end diff --git a/card/mod/search/set/abstract/search/views.rb b/card/mod/search/set/abstract/search/views.rb index 10700e3e71..3f479b3932 100644 --- a/card/mod/search/set/abstract/search/views.rb +++ b/card/mod/search/set/abstract/search/views.rb @@ -154,6 +154,6 @@ def checkbox_item item_card end def closed_limit - [search_params[:limit].to_i, Card.config.closed_search_limit].min + [search_params[:limit].to_i, Cardio.config.closed_search_limit].min end end diff --git a/card/mod/search/set/self/search.rb b/card/mod/search/set/self/search.rb index 8ea1a447cf..33e300bc6c 100644 --- a/card/mod/search/set/self/search.rb +++ b/card/mod/search/set/self/search.rb @@ -75,7 +75,7 @@ def new_item_of_type exact end def goto_items term, exact - goto_names = complete_or_match_search start_only: Card.config.navbox_match_start_only + goto_names = complete_or_match_search start_only: Cardio.config.navbox_match_start_only goto_names.unshift exact.name if add_exact_to_goto_names? exact, goto_names goto_names.map do |name| [name, name.to_name.url_key, h(highlight(name, term, sanitize: false))] diff --git a/card/mod/standard/set/all/path.rb b/card/mod/standard/set/all/path.rb index c2b00d122c..607672d7cd 100644 --- a/card/mod/standard/set/all/path.rb +++ b/card/mod/standard/set/all/path.rb @@ -150,7 +150,7 @@ def add_unknown_name_to_opts name, opts format :css do def contextualize_path relative_path - if Card.config.file_storage == :local + if Cardio.config.file_storage == :local # absolute paths lead to invalid assets path in css for cukes card_path relative_path else diff --git a/card/mod/standard/set/all/rich_html/error.rb b/card/mod/standard/set/all/rich_html/error.rb index 75150d1088..c62f04fe23 100644 --- a/card/mod/standard/set/all/rich_html/error.rb +++ b/card/mod/standard/set/all/rich_html/error.rb @@ -186,7 +186,7 @@ def loud_denial_message end def not_denied_task_read? - @denied_task != :read && Card.config.read_only + @denied_task != :read && Cardio.config.read_only end def to_do_unauthorized_task diff --git a/card/mod/standard/spec/set/all/path_spec.rb b/card/mod/standard/spec/set/all/path_spec.rb index 2d04ce56d2..c65de48c14 100644 --- a/card/mod/standard/spec/set/all/path_spec.rb +++ b/card/mod/standard/spec/set/all/path_spec.rb @@ -4,11 +4,11 @@ def path *args end def with_complex_env - Card.config.relative_url_root = "/root" + Cardio.config.relative_url_root = "/root" Card::Env[:protocol] = "http://" Card::Env[:host] = "mydomain.com" yield - Card.config.relative_url_root = nil + Cardio.config.relative_url_root = nil Card::Env[:protocol] = nil Card::Env[:host] = nil end diff --git a/card/spec/card/content_spec.rb b/card/spec/card/content_spec.rb index d9930dc1b3..0c0949c164 100644 --- a/card/spec/card/content_spec.rb +++ b/card/spec/card/content_spec.rb @@ -400,7 +400,7 @@ def all_classes_pass_check_proc # it "doesn't fix regular nbsp order with setting" do # # manually configure this setting, then make this one live # # (test above will then fail) - # pending "Can't set Card.config.space_last_in_multispace= false "\ + # pending "Can't set Cardio.config.space_last_in_multispace= false "\ # 'for one test' # assert_equal 'space  test  two   space', # Card::Content.clean!( diff --git a/card/spec/card/loader_spec.rb b/card/spec/card/loader_spec.rb index 7be9e7b278..240350374a 100644 --- a/card/spec/card/loader_spec.rb +++ b/card/spec/card/loader_spec.rb @@ -1,6 +1,6 @@ # -*- encoding : utf-8 -*- -describe Card::Mod::Loader do +describe Cardio::Mod::Loader do # let(:card_double) { double "Card" } # let(:pat_all_double) { proxy Card::Set::All } # let(:format_double) { proxy Card::Format } @@ -8,13 +8,13 @@ # it "autos-load Card class methods from lib/card and mods" do # #xpect(Card).to receive(:load_mods) # # - # allow(Card::Mod::Loader).to receive(:load_mods) + # allow(Cardio::Mod::Loader).to receive(:load_mods) # #card = Card[:all] # #expect(card_double).to receive(:load_formats) # #expect(Card).to receive(:load_sets) # #expect(Card).to receive(:tracks).with(:any_args) # so Card still loads without core in failure testing # Card[:all] - # expect(Card::Mod::Loader).to have_received(:load_mods) + # expect(Cardio::Mod::Loader).to have_received(:load_mods) # #expect(Card.instance_method(:version)).to be # # allow(Card).to receive(:version) # # expect(Card.instance_method(:type_card)).to be diff --git a/card/spec/card/mod/loader/mod_dirs.rb b/card/spec/card/mod/loader/mod_dirs.rb index 0f826ea942..64e8ce48a6 100644 --- a/card/spec/card/mod/loader/mod_dirs.rb +++ b/card/spec/card/mod/loader/mod_dirs.rb @@ -1,8 +1,8 @@ -describe Card::Mod::Dirs do +describe Cardio::Mod::Dirs do it 'loads mods from Modfile' do path = File.expand_path "..", __FILE__ - tg = Card::Mod::Dirs.new path + tg = Cardio::Mod::Dirs.new path expect(tg.mods).to eq %w(mod1 mod2) end end diff --git a/card/spec/card/mod/loader/set_loader_spec.rb b/card/spec/card/mod/loader/set_loader_spec.rb index eb3ead1c8b..4beeef140e 100644 --- a/card/spec/card/mod/loader/set_loader_spec.rb +++ b/card/spec/card/mod/loader/set_loader_spec.rb @@ -1,13 +1,13 @@ # -*- encoding : utf-8 -*- -RSpec.describe Card::Mod::Loader::SetLoader do +RSpec.describe Cardio::Mod::Loader::SetLoader do let(:mod_dirs) do path = File.expand_path "../../../../support/test_mods", __FILE__ - Card::Mod::Dirs.new path + Cardio::Mod::Dirs.new path end it 'initializes the load strategy' do - expect(Card::Mod::LoadStrategy::Eval).to receive(:new).with(mod_dirs, instance_of(described_class)) + expect(Cardio::Mod::LoadStrategy::Eval).to receive(:new).with(mod_dirs, instance_of(described_class)) described_class.new(load_strategy: :eval, mod_dirs: mod_dirs) end diff --git a/card/spec/card/mod/loader/set_pattern_loader_spec.rb b/card/spec/card/mod/loader/set_pattern_loader_spec.rb index 723bc2d2ac..924910f99d 100644 --- a/card/spec/card/mod/loader/set_pattern_loader_spec.rb +++ b/card/spec/card/mod/loader/set_pattern_loader_spec.rb @@ -1,14 +1,14 @@ # -*- encoding : utf-8 -*- -RSpec.describe Card::Mod::Loader::SetPatternLoader do +RSpec.describe Cardio::Mod::Loader::SetPatternLoader do let(:mod_dirs) do path = File.expand_path "../../../../support/test_mods", __FILE__ puts path - Card::Mod::Dirs.new path + Cardio::Mod::Dirs.new path end it 'initializes the load strategy' do - expect(Card::Mod::LoadStrategy::Eval).to receive(:new).with(mod_dirs, instance_of(described_class)) + expect(Cardio::Mod::LoadStrategy::Eval).to receive(:new).with(mod_dirs, instance_of(described_class)) described_class.new load_strategy: :eval, mod_dirs: mod_dirs end diff --git a/card/spec/card/mod_spec.rb b/card/spec/card/mod_spec.rb index 439c3ec80c..a0341c22b8 100644 --- a/card/spec/card/mod_spec.rb +++ b/card/spec/card/mod_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Card::Mod do +RSpec.describe Cardio::Mod do describe "gem_spec" do it "finds card mods" do expect(described_class.gem_spec("card-mod-defaults")) diff --git a/card/spec/card/set/event_spec.rb b/card/spec/card/set/event_spec.rb index b36a80932e..94c01f0391 100644 --- a/card/spec/card/set/event_spec.rb +++ b/card/spec/card/set/event_spec.rb @@ -20,7 +20,7 @@ def event_called end it "runs events after reloading sets" do - Card::Mod::Loader.reload_sets + Cardio::Mod::Loader.reload_sets expect(Card.create! name: "event tester").to be_a(Card) # if events don't load, the above will fail to stamp a creator_id and won't validate end diff --git a/card/spec/support/card_spec_helper.rb b/card/spec/support/card_spec_helper.rb index ac35bdb7a9..5b462eaa4e 100644 --- a/card/spec/support/card_spec_helper.rb +++ b/card/spec/support/card_spec_helper.rb @@ -88,10 +88,10 @@ def users end def with_rss_enabled - Card.config.rss_enabled = true + Cardio.config.rss_enabled = true yield ensure - Card.config.rss_enabled = false + Cardio.config.rss_enabled = false end module ClassMethods diff --git a/card/spec/support/card_spec_loader.rb b/card/spec/support/card_spec_loader.rb index 616114cf42..aa0baa55d6 100644 --- a/card/spec/support/card_spec_loader.rb +++ b/card/spec/support/card_spec_loader.rb @@ -106,7 +106,7 @@ def helper def load_shared_examples require File.expand_path "../card_shared_examples", __FILE__ %w[shared_examples shared_context].each do |dirname| - Card::Mod.dirs.each "spec/#{dirname}" do |shared_ex_dir| + Cardio::Mod.dirs.each "spec/#{dirname}" do |shared_ex_dir| Dir["#{shared_ex_dir}/**/*.rb"].sort.each { |f| require f } end end diff --git a/decko/features/support/delayed_job.rb b/decko/features/support/delayed_job.rb index c1347bb78d..5e44da47df 100644 --- a/decko/features/support/delayed_job.rb +++ b/decko/features/support/delayed_job.rb @@ -1,4 +1,4 @@ -Card.config.active_job.queue_adapter = :delayed_job +Cardio.config.active_job.queue_adapter = :delayed_job Before("@delayed-jobs") do Cardio.delaying! diff --git a/decko/lib/decko/application.rb b/decko/lib/decko/application.rb index 0609f24524..002b97f147 100644 --- a/decko/lib/decko/application.rb +++ b/decko/lib/decko/application.rb @@ -1,20 +1,12 @@ # -*- encoding : utf-8 -*- require "decko/engine" -require_relative "config/initializers/sedate_parser" - -Bundler.require :default, *Rails.groups +require "cardio/application" +djar = "delayed_job_active_record" +require djar if Gem::Specification.find_all_by_name(djar).any? module Decko - class Application < Rails::Application - initializer :load_decko_environment_config, - before: :load_environment_config, group: :all do - add_path paths, "lib/decko/config/environments", glob: "#{Rails.env}.rb" - paths["lib/decko/config/environments"].existent.each do |environment| - require environment - end - end - + class Application < Cardio::Application class << self def inherited base super @@ -24,22 +16,23 @@ def inherited base end end - def add_path paths, path, options={} + # override in each domain with local root + def root_path option root = options.delete(:root) || Decko.gem_root - options[:with] = File.join(root, (options[:with] || path)) - paths.add path, options end def configure &block super do - instance_eval(&block) if block_given? + instance_eval &block if block_given? + + config.active_job.queue_adapter = :delayed_job # any config settings below: # (a) do not apply to Card used outside of a Decko context # (b) cannot be overridden in a deck's application.rb, but # (c) CAN be overridden in an environment file - + # therefore, in general, they should be restricted to settings that # (1) are specific to the web environment, and # (2) should not be overridden @@ -49,7 +42,6 @@ def configure &block # overridable decko-specific settings don't have a place yet # but should probably follow the cardio pattern. - # config.load_defaults "6.0" config.autoloader = :zeitwerk config.load_default = "6.0" config.i18n.enforce_available_locales = true @@ -63,8 +55,8 @@ def configure &block # Rails.autoloaders.log! Rails.autoloaders.main.ignore(File.join(Cardio.gem_root, "lib/card/seed_consts.rb")) + # paths configuration - # paths configurations Cardio.set_paths paths.add "files" diff --git a/decko/lib/tasks/decko.rake b/decko/lib/tasks/decko.rake index 9de8a20bc6..7df20acd1b 100644 --- a/decko/lib/tasks/decko.rake +++ b/decko/lib/tasks/decko.rake @@ -101,7 +101,7 @@ decko_namespace = namespace :decko do desc "set symlink for assets" task update_assets_symlink: :environment do prepped_asset_path do |assets_path| - Card::Mod.dirs.each_assets_path do |mod, target| + Cardio::Mod.dirs.each_assets_path do |mod, target| link = File.join assets_path, mod FileUtils.rm_rf link FileUtils.ln_s target, link, force: true From da0cca4823588da8cc649f4a6beeaca3838caa85 Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Tue, 6 Oct 2020 06:00:46 -0500 Subject: [PATCH 03/11] Move card commands to right targets --- card/lib/cardio/cli.rb | 17 +++++++++++++++++ .../commands/{commands => }/application.rb | 0 .../cardio/commands/{commands => }/command.rb | 0 .../commands/{commands => }/cucumber_command.rb | 0 .../{commands => }/cucumber_command/parser.rb | 0 .../commands/{commands => }/rake_command.rb | 0 .../{commands => }/rake_command/parser.rb | 0 .../commands/{commands => }/rspec_command.rb | 0 .../{commands => }/rspec_command/parser.rb | 0 9 files changed, 17 insertions(+) create mode 100644 card/lib/cardio/cli.rb rename card/lib/cardio/commands/{commands => }/application.rb (100%) rename card/lib/cardio/commands/{commands => }/command.rb (100%) rename card/lib/cardio/commands/{commands => }/cucumber_command.rb (100%) rename card/lib/cardio/commands/{commands => }/cucumber_command/parser.rb (100%) rename card/lib/cardio/commands/{commands => }/rake_command.rb (100%) rename card/lib/cardio/commands/{commands => }/rake_command/parser.rb (100%) rename card/lib/cardio/commands/{commands => }/rspec_command.rb (100%) rename card/lib/cardio/commands/{commands => }/rspec_command/parser.rb (100%) diff --git a/card/lib/cardio/cli.rb b/card/lib/cardio/cli.rb new file mode 100644 index 0000000000..850df676d8 --- /dev/null +++ b/card/lib/cardio/cli.rb @@ -0,0 +1,17 @@ +require "rbconfig" +require "cardio/commands/application" +require "cardio/script_loader" + +# If we are inside a Card application this method performs an exec and thus +# the rest of this script is not run. +Cardio::ScriptLoader.exec_script! :card + +require "rails/ruby_version_check" +Signal.trap("INT") { puts; exit(1) } + +# if ARGV.first == 'plugin' +# ARGV.shift +# require 'cardio/commands/plugin_new' +# else + +# end diff --git a/card/lib/cardio/commands/commands/application.rb b/card/lib/cardio/commands/application.rb similarity index 100% rename from card/lib/cardio/commands/commands/application.rb rename to card/lib/cardio/commands/application.rb diff --git a/card/lib/cardio/commands/commands/command.rb b/card/lib/cardio/commands/command.rb similarity index 100% rename from card/lib/cardio/commands/commands/command.rb rename to card/lib/cardio/commands/command.rb diff --git a/card/lib/cardio/commands/commands/cucumber_command.rb b/card/lib/cardio/commands/cucumber_command.rb similarity index 100% rename from card/lib/cardio/commands/commands/cucumber_command.rb rename to card/lib/cardio/commands/cucumber_command.rb diff --git a/card/lib/cardio/commands/commands/cucumber_command/parser.rb b/card/lib/cardio/commands/cucumber_command/parser.rb similarity index 100% rename from card/lib/cardio/commands/commands/cucumber_command/parser.rb rename to card/lib/cardio/commands/cucumber_command/parser.rb diff --git a/card/lib/cardio/commands/commands/rake_command.rb b/card/lib/cardio/commands/rake_command.rb similarity index 100% rename from card/lib/cardio/commands/commands/rake_command.rb rename to card/lib/cardio/commands/rake_command.rb diff --git a/card/lib/cardio/commands/commands/rake_command/parser.rb b/card/lib/cardio/commands/rake_command/parser.rb similarity index 100% rename from card/lib/cardio/commands/commands/rake_command/parser.rb rename to card/lib/cardio/commands/rake_command/parser.rb diff --git a/card/lib/cardio/commands/commands/rspec_command.rb b/card/lib/cardio/commands/rspec_command.rb similarity index 100% rename from card/lib/cardio/commands/commands/rspec_command.rb rename to card/lib/cardio/commands/rspec_command.rb diff --git a/card/lib/cardio/commands/commands/rspec_command/parser.rb b/card/lib/cardio/commands/rspec_command/parser.rb similarity index 100% rename from card/lib/cardio/commands/commands/rspec_command/parser.rb rename to card/lib/cardio/commands/rspec_command/parser.rb From 79ddda4e53531e1f3937aa94c99328340c791f70 Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Tue, 6 Oct 2020 07:29:06 -0500 Subject: [PATCH 04/11] Some mistake (restart) fixing and further advancing. Command processing launches rspec --- card/lib/cardio/application.rb | 6 +- card/lib/cardio/cli.rb | 47 ++++++- card/lib/cardio/commands.rb | 120 +++++++++++++++++ card/lib/cardio/commands/application.rb | 15 ++- card/lib/cardio/commands/command.rb | 12 +- card/lib/cardio/commands/command/parser.rb | 37 ++++++ card/lib/cardio/commands/cucumber_command.rb | 51 -------- .../commands/cucumber_command/parser.rb | 41 ------ card/lib/cardio/commands/rake_command.rb | 4 +- .../cardio/commands/rake_command/parser.rb | 6 +- card/lib/cardio/commands/rspec_command.rb | 71 +++++++++- .../cardio/commands/rspec_command/parser.rb | 123 +++++++++--------- decko/lib/decko.rb | 2 + decko/lib/decko/cli.rb | 4 +- decko/lib/decko/script_decko_loader.rb | 31 ----- 15 files changed, 355 insertions(+), 215 deletions(-) create mode 100644 card/lib/cardio/commands.rb create mode 100644 card/lib/cardio/commands/command/parser.rb delete mode 100644 card/lib/cardio/commands/cucumber_command.rb delete mode 100644 card/lib/cardio/commands/cucumber_command/parser.rb delete mode 100644 decko/lib/decko/script_decko_loader.rb diff --git a/card/lib/cardio/application.rb b/card/lib/cardio/application.rb index c0ef600054..7424eca30d 100644 --- a/card/lib/cardio/application.rb +++ b/card/lib/cardio/application.rb @@ -39,8 +39,6 @@ def inherited base ActiveSupport.on_load(:active_record) do c=ActiveRecord::Base.establish_connection(::Rails.env.to_sym) ActiveSupport.run_load_hooks(:before_card) - require 'card/all' - end # ActiveSupport.on_load(:after_initialize) do # # require "card" if Cardio.load_card? @@ -70,8 +68,8 @@ def configure &block end end - def root_path option - root = options.delete(:root) || Cardio.gem_root + def root_path_option options + options.delete(:root) || Cardio.gem_root end def add_path path, options={} diff --git a/card/lib/cardio/cli.rb b/card/lib/cardio/cli.rb index 850df676d8..45805122c6 100644 --- a/card/lib/cardio/cli.rb +++ b/card/lib/cardio/cli.rb @@ -1,17 +1,56 @@ require "rbconfig" -require "cardio/commands/application" -require "cardio/script_loader" +require "pathname" +module Cardio + module ScriptLoader + RUBY = File.join(*RbConfig::CONFIG.values_at( + "bindir", "ruby_install_name") ) + RbConfig::CONFIG["EXEEXT"] + + class < cardio paths # If we are inside a Card application this method performs an exec and thus # the rest of this script is not run. -Cardio::ScriptLoader.exec_script! :card +Cardio::ScriptLoader.exec_script! command require "rails/ruby_version_check" Signal.trap("INT") { puts; exit(1) } # if ARGV.first == 'plugin' # ARGV.shift -# require 'cardio/commands/plugin_new' +# require "#{path}/commands/plugin_new" # else # end +# FIXME: if path/... not there, use "cardio" (skip aliasing above?) +require "#{path}/commands/application" diff --git a/card/lib/cardio/commands.rb b/card/lib/cardio/commands.rb new file mode 100644 index 0000000000..ffa0249974 --- /dev/null +++ b/card/lib/cardio/commands.rb @@ -0,0 +1,120 @@ +# add method in? to Object class +require "active_support/core_ext/object/inclusion" +#require 'cardio/application_record' + +require "rake" +def load_rake_tasks + require "./config/environment" + Cardio::Application.load_tasks +end + +RAILS_COMMANDS = %w( card generate destroy plugin benchmarker profiler console + server dbconsole application runner ).freeze +CARD_TASK_COMMANDS = %w(card add add_remote refresh_machine_output reset_cache + reset_tmp update merge merge_all assume_card_migrations + clean clear dump emergency load seed reseed supplement + update seed reseed load update).freeze + +ALIAS = { + "rs" => "rspec", + "cc" => "cucumber", + "jm" => "jasmine", + "g" => "generate", + "d" => "destroy", + "c" => "console", + "s" => "server", + "db" => "dbconsole", + "r" => "runner" +}.freeze + + +def supported_rails_command? arg + #Rake.application.top_level_tasks.include? arg + arg.in?(RAILS_COMMANDS) || ALIAS[arg].in?(RAILS_COMMANDS) +end + +#require "cardio/commands" +require "cardio" +module Cardio + module Commands + class << self + def run_new + if ARGV.first.in?(["-h", "--help"]) + require "cardio/commands/application" + else + puts "Can't initialize a new deck within the directory of another, " \ + "please change to a non-deck directory first.\n" + puts "Type 'card' for help." + exit(1) + end + end + + def run_rspec + require "cardio/commands/rspec_command" + RspecCommand.new(ARGV).run + end + + def run_card_task command + require "cardio/commands/rake_command" + RakeCommand.new(['card', command]*':', ARGV).run + end + end + end +end + +ARGV << "--help" if ARGV.empty? + +ARGV.unshift 'card' if ARGV.first == '-T' +command = ARGV.first +command = ALIAS[command] || command +if supported_rails_command?(command) + ENV["PRY_RESCUE_RAILS"] = "1" if ARGV.delete("--rescue") + + # without this, the card generators don't list with: card g --help + require "generators/card" if command == "generate" + require "rails/commands" +else + ARGV.shift + lookup = command + lookup = $1 if command =~ /^([^:]+):/ + case lookup + when "--version", "-v" + puts "Card #{Card::Version.release}" + when 'rspec' + Cardio::Commands.run_rspec + when *CARD_TASK_COMMANDS + Cardio::Commands.run_card_task command + else + puts "Error: Command not recognized" unless command.in?(["-h", "--help"]) + puts <<-EOT + Usage: card COMMAND [ARGS] + + The most common card commands are: + seed Create and seed the database specified in config/database.yml + + server Start the Rails server (short-cut alias: "s") + console Start the Rails console (short-cut alias: "c") + dbconsole Start a console for the database specified in config/database.yml + (short-cut alias: "db") + + For core developers + rspec Run rspec tests (short-cut alias: "rs") + update Run card migrations + load Load bootstrap data into database + + In addition to those, there are the standard rails commands: + generate Generate new code (short-cut alias: "g") + application Generate the Rails application code + destroy Undo code generated with "generate" (short-cut alias: "d") + benchmarker See how fast a piece of code runs + profiler Get profile information from a piece of code + plugin Install a plugin + runner Run a piece of code in the application environment (short-cut alias: "r") + + All commands can be run with -h (or --help) for more information. + EOT + exit(1) + end +end +exit(0) + diff --git a/card/lib/cardio/commands/application.rb b/card/lib/cardio/commands/application.rb index e10342031c..a390f85c08 100644 --- a/card/lib/cardio/commands/application.rb +++ b/card/lib/cardio/commands/application.rb @@ -1,10 +1,15 @@ -require "rails/generators" -require File.expand_path("../../generators/deck/deck_generator", __FILE__) +# -*- encoding : utf-8 -*- + +# no card generator new templates +require "generators/card" if ARGV.first != "new" - ARGV[0] = "--help" + #ARGV[0] = "--help" else - ARGV.shift + cmd = ARGV.shift end -Decko::Generators::Deck::DeckGenerator.start +require "cardio/application" + +require "cardio/commands" +Cardio::Commands.run_new diff --git a/card/lib/cardio/commands/command.rb b/card/lib/cardio/commands/command.rb index 658a4de938..26e4669b93 100644 --- a/card/lib/cardio/commands/command.rb +++ b/card/lib/cardio/commands/command.rb @@ -1,27 +1,27 @@ # require "English" # needed for CHILD_STATUS, but not sure this is the best place for this. -module Decko +module Cardio module Commands class Command def run - puts command exit_with_child_status command end def exit_with_child_status command + puts command command += " 2>&1" - exit $CHILD_STATUS.exitstatus unless system command + exit($CHILD_STATUS&.exitstatus || 1) unless system command end - # split special decko args and original command args separated by '--' + # split special card args and original command args separated by '--' def split_args args before_split = true - decko_args, command_args = + card_args, command_args = args.partition do |a| before_split = (a == "--" ? false : before_split) end command_args.shift - [decko_args, command_args] + [card_args, command_args] end end end diff --git a/card/lib/cardio/commands/command/parser.rb b/card/lib/cardio/commands/command/parser.rb new file mode 100644 index 0000000000..ffef5f82b5 --- /dev/null +++ b/card/lib/cardio/commands/command/parser.rb @@ -0,0 +1,37 @@ +# -*- encoding : utf-8 -*- +require "optparse" + +module Cardio + module Commands + class Command + class Parser + USAGE_MESSAGE = <<-EOT + card new + EOT + + def initialize + @args = [] + @options = {} + end + # move to command/parser.rb + attr_reader :options, :args + + def parse args + # The options specified on the command line will be collected in + # *options*. + + @options = self.class.new + @args = OptionParser.new do |parser| + @options.define_options parser # load self.options (super too) + parser.parse! args # do the parse and set self.args + end + @options + end + + def define_options parser + end + + end + end + end +end diff --git a/card/lib/cardio/commands/cucumber_command.rb b/card/lib/cardio/commands/cucumber_command.rb deleted file mode 100644 index 0534531b99..0000000000 --- a/card/lib/cardio/commands/cucumber_command.rb +++ /dev/null @@ -1,51 +0,0 @@ -require File.expand_path("../command", __FILE__) - -module Decko - module Commands - class CucumberCommand < Command - def initialize args - require "decko" - require "./config/environment" - @decko_args, @cucumber_args = split_args args - @opts = {} - Parser.new(@opts).parse!(@decko_args) - end - - def command - @cmd ||= - "#{env_args} #{@opts[:executer] || "bundle exec"} cucumber #{require_args} #{feature_args}" - end - - private - - def env_args - env_args = @opts[:env].join " " - # turn coverage off if not all cukes run - env_args << " COVERAGE=false" if @cucumber_args.present? - env_args << " RAILS_GROUPS=test" - env_args - end - - def feature_args - if @cucumber_args.empty? - feature_paths.join(" ") - else - @cucumber_args.shelljoin - end - end - - def require_args - "-r #{Decko.gem_root}/features " + - feature_paths.map { |path| "-r #{path}" }.join(" ") - end - - def feature_paths - Cardio::Mod.dirs.map do |p| - Dir.glob "#{p}/features" - end.flatten - end - end - end -end - -require File.expand_path("../cucumber_command/parser", __FILE__) diff --git a/card/lib/cardio/commands/cucumber_command/parser.rb b/card/lib/cardio/commands/cucumber_command/parser.rb deleted file mode 100644 index 6bc0114470..0000000000 --- a/card/lib/cardio/commands/cucumber_command/parser.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -*- encoding : utf-8 -*- -require "optparse" - -module Decko - module Commands - class CucumberCommand - class Parser < OptionParser - def initialize opts - super() do |parser| - parser.banner = "Usage: decko cucumber [DECKO ARGS] -- [CUCUMBER ARGS]\n\n" - parser.separator <<-EOT.strip_heredoc - - DECKO ARGS - EOT - opts[:env] = ["RAILS_ROOT=."] - parser.on("-d", "--debug", "Drop into debugger on failure") do |a| - opts[:env] << "DEBUG=1" if a - end - parser.on("-f", "--fast", "Stop on first failure") do |a| - opts[:env] << "FAST=1" if a - end - parser.on("-l", "--launchy", "Open page on failure") do |a| - opts[:env] << "LAUNCHY=1" if a - end - parser.on("-s", "--step", "Pause after each step") do |a| - opts[:env] << "STEP=1" if a - end - parser.on("--[no-]spring", "Run with spring") do |spring| - opts[:executer] = - if spring - "spring" - else - "bundle exec" - end - end - end - end - end - end - end -end diff --git a/card/lib/cardio/commands/rake_command.rb b/card/lib/cardio/commands/rake_command.rb index 2b2f3e7da8..68d28603c0 100644 --- a/card/lib/cardio/commands/rake_command.rb +++ b/card/lib/cardio/commands/rake_command.rb @@ -1,7 +1,7 @@ require File.expand_path("../command", __FILE__) # require "pry" -module Decko +module Cardio module Commands class RakeCommand < Command def initialize rake_task, args={} @@ -38,4 +38,4 @@ def commands end end -require File.expand_path("../rake_command/parser", __FILE__) \ No newline at end of file +require File.expand_path("../rake_command/parser", __FILE__) diff --git a/card/lib/cardio/commands/rake_command/parser.rb b/card/lib/cardio/commands/rake_command/parser.rb index 8997b4a293..5a1be058f4 100644 --- a/card/lib/cardio/commands/rake_command/parser.rb +++ b/card/lib/cardio/commands/rake_command/parser.rb @@ -1,14 +1,14 @@ # -*- encoding : utf-8 -*- require "optparse" -module Decko +module Cardio module Commands class RakeCommand class Parser < OptionParser def initialize command, opts super() do |parser| - parser.banner = "Usage: decko #{command} [options]\n\n" \ - "Run decko:#{command} task on the production "\ + parser.banner = "Usage: card #{command} [options]\n\n" \ + "Run card:#{command} task on the production "\ " database specified in config/database.yml\n\n" parser.on("--production", "-p", "#{command} production database (default)") do diff --git a/card/lib/cardio/commands/rspec_command.rb b/card/lib/cardio/commands/rspec_command.rb index 7064414379..5ef760c491 100644 --- a/card/lib/cardio/commands/rspec_command.rb +++ b/card/lib/cardio/commands/rspec_command.rb @@ -1,20 +1,25 @@ require File.expand_path("../command", __FILE__) -module Decko +module Cardio module Commands class RspecCommand < Command def initialize args require "rspec/core" - require "decko/application" - @decko_args, @rspec_args = split_args args - @opts = {} - Parser.new(@opts).parse!(@decko_args) + @opts = RspecCommand::Parser.new.parse(ARGV).options + @rspec_args, @cmd_args = + if ARGV.include?('--') + split_args(ARGV) + else + [[], ARGV] + end end def command +c= "#{env_args} #{@opts[:executer]} #{@opts[:rescue]}" \ - "rspec #{@rspec_args.shelljoin} #{@opts[:files]}" + "rspec #{@rspec_args.shelljoin} #{spec_files_from_opts(@opts)*' '} "\ + "--exclude-pattern \"./card/vendor/**/*\"" end private @@ -23,13 +28,65 @@ def env_args ["RAILS_ROOT=.", coverage].compact.join " " end + def has_specs? + @opts[:mod_items]&.any? || + @opts[:deck_items]&.any? || + @opts[:card_items]&.any? + end + def coverage # no coverage if rspec was started with file argument - if (@opts[:files] || @rspec_args.present?) && !@opts[:simplecov] + if (has_specs? || @rspec_args.any?) && !@opts[:simplecov] @opts[:simplecov] = "COVERAGE=false" end @opts[:simplecov] end + + def spec_files_from_opts opts + find_mod_specs(opts[:mod_items]) + + find_deck_specs(opts[:deck_items]) + + find_core_specs(opts[:core_items]) + end + def find_mods mods, base_dir + #def find_mod_file filename, base_dir + mods.map do |modname| + if File.exist?("mod/#{modname}") || File.exist?("#{base_dir}/mod/#{modname}") + "#{base_dir}/mod/#{filename}" + elsif (files = find_tests(filename, "mod"))&.present? + files + else + find_spec_file(file, "#{base_dir}/mod") + end + end + end + + def find_tests names, base_dir + #def find_spec_file filename, base_dir + names.map do |filename| + file, line = filename.split(":") + if file.include?("_spec.rb") && File.exist?(file) + filename + else + file = File.basename(file, ".rb").sub(/_spec$/, "") + Dir.glob("#{base_dir}/**/#{file}_spec.rb").flatten.map do |spec_file| + line ? "#{spec_file}:#{line}" : file + end.join(" ") + end + end + end + + def find_mod_specs mods + [] + end + + def find_deck_specs files + #find_tests files, basedir + [] + end + + def find_core_specs files + [] + end end end end diff --git a/card/lib/cardio/commands/rspec_command/parser.rb b/card/lib/cardio/commands/rspec_command/parser.rb index 3233a126e1..ab3edbbf1a 100644 --- a/card/lib/cardio/commands/rspec_command/parser.rb +++ b/card/lib/cardio/commands/rspec_command/parser.rb @@ -1,13 +1,14 @@ # -*- encoding : utf-8 -*- require "optparse" +require 'cardio/commands/command/parser' -module Decko +module Cardio module Commands - class RspecCommand - class Parser < OptionParser + class RspecCommand < Command + class Parser < Command::Parser RSPEC_PATH_MESSAGE = <<-EOT - DECKO ARGS + {cmdname.upcase} ARGS You don't have to give a full path for FILENAME; the basename is enough. If FILENAME does not include '_spec', then rspec searches for the @@ -16,78 +17,82 @@ class Parser < OptionParser EOT - def initialize opts - super() do |parser| - parser.banner = "Usage: decko rspec [DECKO ARGS] -- [RSPEC ARGS]\n\n" \ + RSPEC_USAGE_MESSAGE = <<-EOT + card rspec + -d --deck-spec FILENAME(:LINE) # Run spec for a Decko spec + -c --core-spec FILENAME(:LINE) # Run spec for a Card core spec + -m --mod MODNAME # Run all specs for a mod + -s --[no-]simplecov # Run with simplecov + --rescue # Run with pry-rescue + --[no]-spring # Run with spring + EOT + + def define_options parser + super # define common options from parent class + cmdname = $0 + cmdname = $1 if cmdname =~ /\/([^\/]+)$/ + parser.banner = "Usage: #{cmdname} rspec [#{cmdname.upcase} ARGS] -- [RSPEC ARGS]\n\n" \ "RSPEC ARGS" - parser.separator RSPEC_PATH_MESSAGE + parser.separator RSPEC_USAGE_MESSAGE + parser.separator RSPEC_PATH_MESSAGE - parser.on("-d", "--spec FILENAME(:LINE)", - "Run spec for a Decko deck file") do |file| - opts[:files] = find_spec_file(file, "#{Decko.root}/mod") - end - parser.on("-c", "--core-spec FILENAME(:LINE)", - "Run spec for a Decko core file") do |file| - opts[:files] = find_spec_file(file, Cardio.gem_root) - end - parser.on("-m", "--mod MODNAME", - "Run all specs for a mod or matching a mod") do |file| - opts[:files] = find_mod_file(file, Cardio.gem_root) - end - parser.on("-s", "--[no-]simplecov", "Run with simplecov") do |s| - opts[:simplecov] = s ? "" : "COVERAGE=false" - end - parser.on("--rescue", "Run with pry-rescue") do - process_rescue_opts opts - end - parser.on("--[no-]spring", "Run with spring") do |spring| - process_spring_opts spring, opts - end - parser.separator "\n" + # can you run decko specs in card? doesn't seem right + parser.on("-d", "--deck-spec [FILENAME(:LINE)]", + "Run spec for a Card deck file") do |file| + add_tests file, :deck_items + end + parser.on("-c", "--core-spec [FILENAME(:LINE)]", + "Run spec for a Card core file") do |file| + add_tests file, :core_items + end + parser.on("-m", "--mod [MODNAME]", + "Run all specs for a mod or matching a mod") do |mod| + add_tests mod, :mod_items + end + parser.on("-s", "--[no-]simplecov", "Run with simplecov") do |s| + options[:simplecov] = s ? "" : "COVERAGE=false" + end + parser.on("--rescue", "Run with pry-rescue") do + process_rescue_opts opts + end + parser.on("--[no-]spring", "Run with spring") do |spring| + process_spring_opts spring, opts end + parser.on_tail("[LIST]") do |list| + add_tests(list, :core_items) + end + parser.separator "\n" end - private + private + + def add_tests item, kind=:core_items + item ||= :all + o = options[kind] ||= [] + if options[kind].include?(:all) + warn 'multiple #{kind} with "all"' + else + o <<= item + end + end def process_rescue_opts opts - if opts[:executer] == "spring" + if options[:executer] == "spring" puts "Disabled pry-rescue. Not compatible with spring." else - opts[:rescue] = "rescue " + options[:rescue] = "rescue " end end def process_spring_opts spring, opts if spring - opts[:executer] = "spring" - if opts[:rescue] - opts[:rescue] = "" + options[:executer] = "spring" + if options[:rescue] + options[:rescue] = "" puts "Disabled pry-rescue. Not compatible with spring." end else - opts[:executer] = "bundle exec" - end - end - - def find_mod_file filename, base_dir - if File.exist?("mod/#{filename}") || File.exist?("#{base_dir}/mod/#{filename}") - "#{base_dir}/mod/#{filename}" - elsif (files = find_spec_file(filename, "mod"))&.present? - files - else - find_spec_file(file, "#{base_dir}/mod") - end - end - - def find_spec_file filename, base_dir - file, line = filename.split(":") - if file.include?("_spec.rb") && File.exist?(file) - filename - else - file = File.basename(file, ".rb").sub(/_spec$/, "") - Dir.glob("#{base_dir}/**/#{file}_spec.rb").flatten.map do |spec_file| - line ? "#{spec_file}:#{line}" : file - end.join(" ") + options[:executer] = "bundle exec" end end end diff --git a/decko/lib/decko.rb b/decko/lib/decko.rb index bf4e7d67f0..531dcf698c 100644 --- a/decko/lib/decko.rb +++ b/decko/lib/decko.rb @@ -1,4 +1,6 @@ +require 'cardio' + module Decko DECKO_GEM_ROOT = File.expand_path("../..", __FILE__) diff --git a/decko/lib/decko/cli.rb b/decko/lib/decko/cli.rb index 7da1b02516..19a3de13cc 100644 --- a/decko/lib/decko/cli.rb +++ b/decko/lib/decko/cli.rb @@ -1,9 +1,9 @@ require "rbconfig" -require "decko/script_decko_loader" +require "cardio/script_loader" # If we are inside a Decko application this method performs an exec and thus # the rest of this script is not run. -Decko::ScriptDeckoLoader.exec_script_decko! +Cardio::ScriptLoader.exec_script! :decko require "rails/ruby_version_check" Signal.trap("INT") { puts; exit(1) } diff --git a/decko/lib/decko/script_decko_loader.rb b/decko/lib/decko/script_decko_loader.rb deleted file mode 100644 index 89291cb1e4..0000000000 --- a/decko/lib/decko/script_decko_loader.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "pathname" - -module Decko - module ScriptDeckoLoader - RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + - RbConfig::CONFIG["EXEEXT"] - SCRIPT_DECKO = File.join("script", "decko") - - def self.exec_script_decko! - cwd = Dir.pwd - return unless in_decko_application? || in_decko_application_subdirectory? - exec RUBY, SCRIPT_DECKO, *ARGV if in_decko_application? - Dir.chdir("..") do - # Recurse in a chdir block: if the search fails we want to be sure - # the application is generated in the original working directory. - exec_script_decko! unless cwd == Dir.pwd - end - rescue SystemCallError - # could not chdir, no problem just return - end - - def self.in_decko_application? - File.exist?(SCRIPT_DECKO) - end - - def self.in_decko_application_subdirectory? path=Pathname.new(Dir.pwd) - File.exist?(File.join(path, SCRIPT_DECKO)) || - !path.root? && in_decko_application_subdirectory?(path.parent) - end - end -end From 2a51326561ff904efa36dfb1dab530846d2096be Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Tue, 6 Oct 2020 07:57:25 -0500 Subject: [PATCH 05/11] Move AppRecord back to top level --- card-mod-history/lib/card/act.rb | 2 +- card-mod-history/lib/card/action.rb | 2 +- card/lib/card.rb | 2 +- .../spec/{card => }/tasks/file_card_creator/script_card_spec.rb | 0 decko/lib/decko/tasks/.gitkeep | 0 5 files changed, 3 insertions(+), 3 deletions(-) rename card/spec/{card => }/tasks/file_card_creator/script_card_spec.rb (100%) delete mode 100644 decko/lib/decko/tasks/.gitkeep diff --git a/card-mod-history/lib/card/act.rb b/card-mod-history/lib/card/act.rb index cf36474e1c..28b5d03341 100644 --- a/card-mod-history/lib/card/act.rb +++ b/card-mod-history/lib/card/act.rb @@ -16,7 +16,7 @@ class Card # - _acted_at_, a timestamp of the action # - the _ip_address_ of the actor where applicable. # - class Act < Cardio::ApplicationRecord + class Act < ApplicationRecord before_save :assign_actor has_many :ar_actions, -> { order :id }, foreign_key: :card_act_id, inverse_of: :act, diff --git a/card-mod-history/lib/card/action.rb b/card-mod-history/lib/card/action.rb index ace0a6ea7f..8e2fbf3447 100644 --- a/card-mod-history/lib/card/action.rb +++ b/card-mod-history/lib/card/action.rb @@ -20,7 +20,7 @@ class Card # * a boolean indicated whether the action is a _draft_ # * a _comment_ (where applicable) # - class Action < Cardio::ApplicationRecord + class Action < ApplicationRecord include Differ extend Admin diff --git a/card/lib/card.rb b/card/lib/card.rb index ada088b681..e9c76ffddd 100644 --- a/card/lib/card.rb +++ b/card/lib/card.rb @@ -110,7 +110,7 @@ # can be temporarily assumed using `Card::Auth#as`. # # {Card::Auth More on accounts} -class Card +class Card < ApplicationRecord extend Mark extend Dirty::MethodFactory include Dirty diff --git a/card/spec/card/tasks/file_card_creator/script_card_spec.rb b/card/spec/tasks/file_card_creator/script_card_spec.rb similarity index 100% rename from card/spec/card/tasks/file_card_creator/script_card_spec.rb rename to card/spec/tasks/file_card_creator/script_card_spec.rb diff --git a/decko/lib/decko/tasks/.gitkeep b/decko/lib/decko/tasks/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 From 6d69c22164240a5aa27738285669675777e5ad1a Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Tue, 6 Oct 2020 09:36:18 -0500 Subject: [PATCH 06/11] Small changes for commands --- card/lib/card.rb | 1 + card/lib/cardio.rb | 109 ++++++++++++++++++++++----------- card/lib/cardio/application.rb | 33 ++++++---- card/lib/cardio/commands.rb | 1 - 4 files changed, 94 insertions(+), 50 deletions(-) diff --git a/card/lib/card.rb b/card/lib/card.rb index e9c76ffddd..46520d3fa6 100644 --- a/card/lib/card.rb +++ b/card/lib/card.rb @@ -1,5 +1,6 @@ # -*- encoding : utf-8 -*- +raise "Defined?" if Cardio.card_defined? ActiveSupport.run_load_hooks(:before_card, self) # Cards are wiki-inspired building blocks. diff --git a/card/lib/cardio.rb b/card/lib/cardio.rb index 5f03553148..b9ce6e85bd 100644 --- a/card/lib/cardio.rb +++ b/card/lib/cardio.rb @@ -1,6 +1,8 @@ # -*- encoding : utf-8 -*- -require "active_support/core_ext/numeric/time" +#require "active_support/core_ext/numeric/time" +#require 'rails' +#require 'active_support' djar = "delayed_job_active_record" require djar if Gem::Specification.find_all_by_name(djar).any? require "cardio/schema" @@ -9,6 +11,7 @@ require "cardio/delaying" ActiveSupport.on_load :after_card do + #require 'cardio/mod' # should autoload Cardio::Mod.load end @@ -46,7 +49,10 @@ def gem_root end def card_defined? - const_defined? "Card" + if const_defined? "Card" + raise "Wrong Card" unless Card.is_a? ApplicationRecord + true + end end def load_card? @@ -60,7 +66,7 @@ def cache end def default_configs - { + defaults = { read_only: read_only?, # if you disable inline styles tinymce's formatting options stop working @@ -100,6 +106,7 @@ def default_configs request_logger: false, performance_logger: false, sql_comments: true, + eager_load: false, file_storage: :local, file_buckets: {}, @@ -121,13 +128,11 @@ def default_configs load_strategy: :eval, cache_set_module_list: false } - end - - def set_config - add_lib_dirs_to_autoload_paths - - default_configs.each_pair do |setting, value| - set_default_value(config, setting, *value) + cfg = config + defaults.each_pair do |setting, value| + # so don't change settings here if they already exist + cfg.send("#{setting}=", *value) unless cfg.respond_to?(setting) && + !cf.send(setting.nil?) end end @@ -137,17 +142,14 @@ def add_lib_dirs_to_autoload_paths # TODO: this should use each_mod_path, but it's not available when this is run # This means libs will not get autoloaded (and sets not watched) if the mod # dir location is overridden in config - [gem_root, root].each { |dir| autoload_and_watch config, "#{dir}/mod/*" } - gem_mod_specs.each_value { |spec| autoload_and_watch config, spec.full_gem_path } + [gem_root, root].each { |dir| autoload_and_watch "#{dir}/mod/*" } + gem_mod_specs.each_value { |spec| autoload_and_watch spec.full_gem_path } # the watchable_dirs are processes in # set_clear_dependencies_hook hook in the railties gem in finisher.rb - - # TODO: move this to the right place in decko - config.autoload_paths += Dir["#{Decko.gem_root}/lib"] end - def autoload_and_watch config, mod_path + def autoload_and_watch mod_path config.autoload_paths += Dir["#{mod_path}/lib"] config.watchable_dirs["#{mod_path}/set"] = [:rb] end @@ -156,16 +158,9 @@ def read_only? !ENV["DECKO_READ_ONLY"].nil? end - # In production mode set_config gets called twice. - # The second call overrides all deck config settings - # so don't change settings here if they already exist - def set_default_value config, setting, *value - config.send("#{setting}=", *value) unless config.respond_to? setting - end - - def set_paths + def paths_init %w[set set_pattern].each do |path| - tmppath = "tmp/#{path}" + tmppath = File.join("tmp", path) add_path tmppath, root: root unless paths[tmppath]&.existent end @@ -177,6 +172,59 @@ def set_paths add_mod_initializer_paths end + def future_stamp + # # used in test data + @future_stamp ||= Time.zone.local 2020, 1, 1, 0, 0, 0 + end + + def load_card_environment + add_lib_dirs_to_autoload_paths + default_configs + paths_init + add_configs + + ActiveSupport.run_load_hooks(:before_configuration) + ActiveSupport.run_load_hooks(:load_active_record) + ActiveSupport.run_load_hooks(:before_card) + + add_path "lib/card/config/environments", glob: "#{Rails.env}.rb", root: Cardio.gem_root + end + + def load_rails_environment + paths["lib/card/config/environments"].existent.each do |environment| + require environment + end + end + + def connect_on_load + ActiveSupport.on_load(:before_configure_environment) do + ActiveRecord::Base.establish_connection(::Rails.env.to_sym) + end + ActiveSupport.on_load(:after_initialize) do + end + ActiveSupport.on_load(:after_application_record) do + #ActiveSupport.run_load_hooks :initialize, self + end + end + + def add_configs + + # should get from class that include Cardio::App (Decko) + #config.autoloader = :zeitwerk + #config.load_default = "6.0" + #config.i18n.enforce_available_locales = true + + Rails.autoloaders.log! + # Rails.autoloaders.main.ignore(File.join(Cardio.gem_root, "lib/card/seed_consts.rb")) + end + private + + def add_path path, options={} + root = options.delete(:root) || Cardio.gem_root + options[:with] = File.join(root, (options[:with] || path)) + paths.add path, options + end + def add_db_paths add_path "db" add_path "db/migrate" @@ -203,16 +251,5 @@ def add_initializers base_dir, mod=false, init_dir="initializers" paths[path_mark] << initializers_dir end end - - def add_path path, options={} - root = options.delete(:root) || gem_root - options[:with] = File.join(root, (options[:with] || path)) - paths.add path, options - end - - def future_stamp - # # used in test data - @future_stamp ||= Time.zone.local 2020, 1, 1, 0, 0, 0 - end end end diff --git a/card/lib/cardio/application.rb b/card/lib/cardio/application.rb index 7424eca30d..3611e25085 100644 --- a/card/lib/cardio/application.rb +++ b/card/lib/cardio/application.rb @@ -2,14 +2,7 @@ require 'rails' -Bundler.require :default, *Rails.groups - -if defined?(Bundler) - # If you precompile assets before deploying to production, use this line - Bundler.require *Rails.groups(assets: %w[development test cypress]) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) -end +Bundler.require :default, *Rails.groups if defined?(Bundler) module Cardio class Application < Rails::Application @@ -58,14 +51,28 @@ def configure &block super do instance_eval &block if block_given? - Cardio.set_config - - config.autoloader = :zeitwerk config.load_default = "6.0" - config.i18n.enforce_available_locales = true + Cardio.load_card_environment + #Cardio.set_config + #Cardio.set_paths paths + + #config.autoloader = :zeitwerk # included in "6.0" + config.i18n.enforce_available_locales = true # maybe this too + end + end + + initializer :load_card_config, + before: :load_environment_config, group: :all do + #Cardio.load_card_environment + end - Cardio.set_paths paths + initializer :load_card_config_initializers, + after: :load_card_config, group: :all do + Cardio.load_rails_environment + paths["config/initializers"].existent.sort.each do |initializer| + load(initializer) end + Cardio.connect_on_load end def root_path_option options diff --git a/card/lib/cardio/commands.rb b/card/lib/cardio/commands.rb index ffa0249974..ddc9475a74 100644 --- a/card/lib/cardio/commands.rb +++ b/card/lib/cardio/commands.rb @@ -116,5 +116,4 @@ def run_card_task command exit(1) end end -exit(0) From ef56df59a394eaabc3397b95b2fb965040688d7c Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Wed, 14 Oct 2020 10:20:52 -0500 Subject: [PATCH 07/11] decko new command working after restart, step 1 (needs tests writen) --- decko/lib/decko/cli.rb | 63 +++++++++++++++---- decko/lib/decko/commands/application.rb | 10 +++ .../lib/decko}/commands/command.rb | 12 ++-- .../decko/commands/cucumber_command/parser.rb | 41 ++++++++++++ 4 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 decko/lib/decko/commands/application.rb rename {card/lib/cardio => decko/lib/decko}/commands/command.rb (69%) create mode 100644 decko/lib/decko/commands/cucumber_command/parser.rb diff --git a/decko/lib/decko/cli.rb b/decko/lib/decko/cli.rb index 19a3de13cc..aa67369638 100644 --- a/decko/lib/decko/cli.rb +++ b/decko/lib/decko/cli.rb @@ -1,17 +1,56 @@ require "rbconfig" -require "cardio/script_loader" +require "pathname" -# If we are inside a Decko application this method performs an exec and thus -# the rest of this script is not run. -Cardio::ScriptLoader.exec_script! :decko +module ScriptLoader + RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + + RbConfig::CONFIG["EXEEXT"] + # replace with current cli.rb + APP_DECKO = File.join("config", "application.rb") -require "rails/ruby_version_check" -Signal.trap("INT") { puts; exit(1) } + def self.find_app_config + cwd = Dir.pwd + return unless in_decko_application? || in_decko_application_subdirectory? + return File.join(cwd, APP_DECKO) + Dir.chdir("..") do + # Recurse in a chdir block: if the search fails we want to be sure + # the application is generated in the original working directory. + exec_script_decko! unless cwd == Dir.pwd + end + rescue SystemCallError + # could not chdir, no problem just return + end -# if ARGV.first == 'plugin' -# ARGV.shift -# require 'decko/commands/plugin_new' -# else + def self.in_decko_application? + File.exist?(APP_DECKO) + end + + def self.in_decko_application_subdirectory? path=Pathname.new(Dir.pwd) + File.exist?(File.join(path, APP_DECKO)) || + !path.root? && in_decko_application_subdirectory?(path.parent) + end +end + +# If we are inside a Decko/Card application (have a parent with +# config/application.rb, therefore any rails and use card commands +# otherwise we are decko new and decko/commands.rb should handle it. +# The first case here is in app, replaces script_loader method +if APP_CONF = ScriptLoader.find_app_config +warn "CLI #{__FILE__}:#{__LINE__} #{APP_CONF} (require boot #{File.expand_path("../config/boot", APP_CONF)}" + require APP_CONF + require File.expand_path("../config/boot", APP_CONF) + require 'cardio/commands' +else + + require "rails/ruby_version_check" + Signal.trap("INT") { puts; exit(1) } + +# if ARGV.first == 'plugin' +# ARGV.shift +# require 'decko/commands/plugin_new' +# else + + # should be decko new or usage + require "decko/commands/application" + # end +end -require "decko/commands/application" -# end diff --git a/decko/lib/decko/commands/application.rb b/decko/lib/decko/commands/application.rb new file mode 100644 index 0000000000..e10342031c --- /dev/null +++ b/decko/lib/decko/commands/application.rb @@ -0,0 +1,10 @@ +require "rails/generators" +require File.expand_path("../../generators/deck/deck_generator", __FILE__) + +if ARGV.first != "new" + ARGV[0] = "--help" +else + ARGV.shift +end + +Decko::Generators::Deck::DeckGenerator.start diff --git a/card/lib/cardio/commands/command.rb b/decko/lib/decko/commands/command.rb similarity index 69% rename from card/lib/cardio/commands/command.rb rename to decko/lib/decko/commands/command.rb index 26e4669b93..658a4de938 100644 --- a/card/lib/cardio/commands/command.rb +++ b/decko/lib/decko/commands/command.rb @@ -1,27 +1,27 @@ # require "English" # needed for CHILD_STATUS, but not sure this is the best place for this. -module Cardio +module Decko module Commands class Command def run + puts command exit_with_child_status command end def exit_with_child_status command - puts command command += " 2>&1" - exit($CHILD_STATUS&.exitstatus || 1) unless system command + exit $CHILD_STATUS.exitstatus unless system command end - # split special card args and original command args separated by '--' + # split special decko args and original command args separated by '--' def split_args args before_split = true - card_args, command_args = + decko_args, command_args = args.partition do |a| before_split = (a == "--" ? false : before_split) end command_args.shift - [card_args, command_args] + [decko_args, command_args] end end end diff --git a/decko/lib/decko/commands/cucumber_command/parser.rb b/decko/lib/decko/commands/cucumber_command/parser.rb new file mode 100644 index 0000000000..6bc0114470 --- /dev/null +++ b/decko/lib/decko/commands/cucumber_command/parser.rb @@ -0,0 +1,41 @@ +# -*- encoding : utf-8 -*- +require "optparse" + +module Decko + module Commands + class CucumberCommand + class Parser < OptionParser + def initialize opts + super() do |parser| + parser.banner = "Usage: decko cucumber [DECKO ARGS] -- [CUCUMBER ARGS]\n\n" + parser.separator <<-EOT.strip_heredoc + + DECKO ARGS + EOT + opts[:env] = ["RAILS_ROOT=."] + parser.on("-d", "--debug", "Drop into debugger on failure") do |a| + opts[:env] << "DEBUG=1" if a + end + parser.on("-f", "--fast", "Stop on first failure") do |a| + opts[:env] << "FAST=1" if a + end + parser.on("-l", "--launchy", "Open page on failure") do |a| + opts[:env] << "LAUNCHY=1" if a + end + parser.on("-s", "--step", "Pause after each step") do |a| + opts[:env] << "STEP=1" if a + end + parser.on("--[no-]spring", "Run with spring") do |spring| + opts[:executer] = + if spring + "spring" + else + "bundle exec" + end + end + end + end + end + end + end +end From b21879c2f07cebc5205f9e1b02f0dac8ffce7577 Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Wed, 14 Oct 2020 10:29:01 -0500 Subject: [PATCH 08/11] boot is in same dir as APP_CONF (config/(boot|application).rb --- decko/lib/decko/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decko/lib/decko/cli.rb b/decko/lib/decko/cli.rb index aa67369638..a922883f16 100644 --- a/decko/lib/decko/cli.rb +++ b/decko/lib/decko/cli.rb @@ -35,7 +35,7 @@ def self.in_decko_application_subdirectory? path=Pathname.new(Dir.pwd) # otherwise we are decko new and decko/commands.rb should handle it. # The first case here is in app, replaces script_loader method if APP_CONF = ScriptLoader.find_app_config -warn "CLI #{__FILE__}:#{__LINE__} #{APP_CONF} (require boot #{File.expand_path("../config/boot", APP_CONF)}" +warn "CLI #{__FILE__}:#{__LINE__} #{APP_CONF} (require boot #{File.expand_path("../boot", APP_CONF)}" require APP_CONF require File.expand_path("../config/boot", APP_CONF) require 'cardio/commands' From 1a07e5f1fe9cb674ffe2de42a8668c33905d0a8b Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Wed, 14 Oct 2020 10:31:44 -0500 Subject: [PATCH 09/11] boot is in same dir as APP_CONF (config/(boot|application).rb --- decko/lib/decko/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decko/lib/decko/cli.rb b/decko/lib/decko/cli.rb index a922883f16..7b5adafea2 100644 --- a/decko/lib/decko/cli.rb +++ b/decko/lib/decko/cli.rb @@ -37,7 +37,7 @@ def self.in_decko_application_subdirectory? path=Pathname.new(Dir.pwd) if APP_CONF = ScriptLoader.find_app_config warn "CLI #{__FILE__}:#{__LINE__} #{APP_CONF} (require boot #{File.expand_path("../boot", APP_CONF)}" require APP_CONF - require File.expand_path("../config/boot", APP_CONF) + require File.expand_path("../boot", APP_CONF) require 'cardio/commands' else From f871d30a0a2d6b4f0ab697b3af6e41dfb499bfcd Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Wed, 14 Oct 2020 12:04:43 -0500 Subject: [PATCH 10/11] Commands and cli inheritance organized --- card/lib/cardio/cli.rb | 53 ----------------- card/lib/cardio/commands.rb | 74 +++++++----------------- card/lib/cardio/commands/command.rb | 29 ++++++++++ card/lib/cardio/commands/rake_command.rb | 5 +- decko/lib/decko/commands.rb | 27 ++++----- decko/lib/decko/commands/command.rb | 24 +------- decko/lib/decko/commands/rake_command.rb | 12 ++++ 7 files changed, 79 insertions(+), 145 deletions(-) create mode 100644 card/lib/cardio/commands/command.rb create mode 100644 decko/lib/decko/commands/rake_command.rb diff --git a/card/lib/cardio/cli.rb b/card/lib/cardio/cli.rb index 45805122c6..eb26648f1e 100644 --- a/card/lib/cardio/cli.rb +++ b/card/lib/cardio/cli.rb @@ -1,56 +1,3 @@ require "rbconfig" require "pathname" -module Cardio - module ScriptLoader - RUBY = File.join(*RbConfig::CONFIG.values_at( - "bindir", "ruby_install_name") ) + RbConfig::CONFIG["EXEEXT"] - - class < cardio paths -# If we are inside a Card application this method performs an exec and thus -# the rest of this script is not run. -Cardio::ScriptLoader.exec_script! command - -require "rails/ruby_version_check" -Signal.trap("INT") { puts; exit(1) } - -# if ARGV.first == 'plugin' -# ARGV.shift -# require "#{path}/commands/plugin_new" -# else - -# end -# FIXME: if path/... not there, use "cardio" (skip aliasing above?) -require "#{path}/commands/application" diff --git a/card/lib/cardio/commands.rb b/card/lib/cardio/commands.rb index ddc9475a74..a3d28a1cd4 100644 --- a/card/lib/cardio/commands.rb +++ b/card/lib/cardio/commands.rb @@ -8,57 +8,34 @@ def load_rake_tasks Cardio::Application.load_tasks end -RAILS_COMMANDS = %w( card generate destroy plugin benchmarker profiler console - server dbconsole application runner ).freeze -CARD_TASK_COMMANDS = %w(card add add_remote refresh_machine_output reset_cache - reset_tmp update merge merge_all assume_card_migrations - clean clear dump emergency load seed reseed supplement - update seed reseed load update).freeze - -ALIAS = { - "rs" => "rspec", - "cc" => "cucumber", - "jm" => "jasmine", - "g" => "generate", - "d" => "destroy", - "c" => "console", - "s" => "server", - "db" => "dbconsole", - "r" => "runner" -}.freeze - - -def supported_rails_command? arg - #Rake.application.top_level_tasks.include? arg - arg.in?(RAILS_COMMANDS) || ALIAS[arg].in?(RAILS_COMMANDS) -end - -#require "cardio/commands" -require "cardio" +#require "cardio" +# if anything left, include in Decko +# should go to card_command.rb +=begin module Cardio module Commands - class << self - def run_new - if ARGV.first.in?(["-h", "--help"]) - require "cardio/commands/application" - else - puts "Can't initialize a new deck within the directory of another, " \ - "please change to a non-deck directory first.\n" - puts "Type 'card' for help." - exit(1) - end - end + CARD_TASK_COMMANDS = %w(card add add_remote refresh_machine_output + reset_cache reset_tmp update merge merge_all + assume_card_migrations clean clear dump emergency + load seed reseed supplement update seed reseed + load update).freeze + + module ClassMethods def run_rspec require "cardio/commands/rspec_command" RspecCommand.new(ARGV).run end - def run_card_task command + def run_task command require "cardio/commands/rake_command" RakeCommand.new(['card', command]*':', ARGV).run end end + + class << self + include ClassMethods + end end end @@ -67,13 +44,7 @@ def run_card_task command ARGV.unshift 'card' if ARGV.first == '-T' command = ARGV.first command = ALIAS[command] || command -if supported_rails_command?(command) - ENV["PRY_RESCUE_RAILS"] = "1" if ARGV.delete("--rescue") - # without this, the card generators don't list with: card g --help - require "generators/card" if command == "generate" - require "rails/commands" -else ARGV.shift lookup = command lookup = $1 if command =~ /^([^:]+):/ @@ -82,8 +53,8 @@ def run_card_task command puts "Card #{Card::Version.release}" when 'rspec' Cardio::Commands.run_rspec - when *CARD_TASK_COMMANDS - Cardio::Commands.run_card_task command + when *Cardio::Commands::CARD_TASK_COMMANDS + Cardio::Commands::RakeCommand.run_task command else puts "Error: Command not recognized" unless command.in?(["-h", "--help"]) puts <<-EOT @@ -95,7 +66,7 @@ def run_card_task command server Start the Rails server (short-cut alias: "s") console Start the Rails console (short-cut alias: "c") dbconsole Start a console for the database specified in config/database.yml - (short-cut alias: "db") + (short-cut alias: "db") For core developers rspec Run rspec tests (short-cut alias: "rs") @@ -111,9 +82,8 @@ def run_card_task command plugin Install a plugin runner Run a piece of code in the application environment (short-cut alias: "r") - All commands can be run with -h (or --help) for more information. - EOT - exit(1) - end +All commands can be run with -h (or --help) for more information. + EOT + exit(1) end diff --git a/card/lib/cardio/commands/command.rb b/card/lib/cardio/commands/command.rb new file mode 100644 index 0000000000..c79ed6bfc3 --- /dev/null +++ b/card/lib/cardio/commands/command.rb @@ -0,0 +1,29 @@ + +# require "English" # needed for CHILD_STATUS, but not sure this is the best place for this. + +module Cardio + module Commands + class Command + def run + puts command + exit_with_child_status command + end + + def exit_with_child_status command + command += " 2>&1" + exit $CHILD_STATUS.exitstatus unless system command + end + + # split special decko args and original command args separated by '--' + def split_args args + before_split = true + decko_args, command_args = + args.partition do |a| + before_split = (a == "--" ? false : before_split) + end + command_args.shift + [decko_args, command_args] + end + end + end +end diff --git a/card/lib/cardio/commands/rake_command.rb b/card/lib/cardio/commands/rake_command.rb index 68d28603c0..60d0caed17 100644 --- a/card/lib/cardio/commands/rake_command.rb +++ b/card/lib/cardio/commands/rake_command.rb @@ -1,5 +1,4 @@ -require File.expand_path("../command", __FILE__) -# require "pry" +require "cardio/commands/command" module Cardio module Commands @@ -38,4 +37,4 @@ def commands end end -require File.expand_path("../rake_command/parser", __FILE__) +require "cardio/commands/rake_command/parser" diff --git a/decko/lib/decko/commands.rb b/decko/lib/decko/commands.rb index 0d65e8147e..7a1ea8b765 100644 --- a/decko/lib/decko/commands.rb +++ b/decko/lib/decko/commands.rb @@ -7,10 +7,11 @@ def load_rake_tasks Decko::Application.load_tasks end +require 'cardio/commands' RAILS_COMMANDS = %w( generate destroy plugin benchmarker profiler console server dbconsole application runner ).freeze DECKO_COMMANDS = %w(new cucumber rspec jasmine).freeze -DECKO_DB_COMMANDS = %w(seed reseed load update).freeze +DECKO_TASK_COMMANDS = %w(seed reseed load update).freeze ALIAS = { "rs" => "rspec", @@ -30,20 +31,15 @@ def supported_rails_command? arg ARGV << "--help" if ARGV.empty? +require 'cardio/commands' + module Decko module Commands class << self - def run_new - if ARGV.first.in?(["-h", "--help"]) - require "decko/commands/application" - else - puts "Can't initialize a new deck within the directory of another, " \ - "please change to a non-deck directory first.\n" - puts "Type 'decko' for help." - exit(1) - end - end - + include Decko::ClassMethds + include Cardio::ClassMethods + end + module ClassMethods def run_rspec require "decko/commands/rspec_command" RspecCommand.new(ARGV).run @@ -54,7 +50,7 @@ def run_cucumber CucumberCommand.new(ARGV).run end - def run_db_task command + def run_task command require "decko/commands/rake_command" RakeCommand.new("decko:#{command}", ARGV).run end @@ -82,8 +78,9 @@ def run_jasmine puts "Decko #{Card::Version.release}" when *DECKO_COMMANDS Decko::Commands.send("run_#{command}") - when *DECKO_DB_COMMANDS - Decko::Commands.run_db_task command + when *DECKO_TASK_COMMANDS + when *Cardio::Commands::CARD_TASK_COMMANDS + Decko::Commands.run_task command else puts "Error: Command not recognized" unless command.in?(["-h", "--help"]) puts <<-EOT diff --git a/decko/lib/decko/commands/command.rb b/decko/lib/decko/commands/command.rb index 658a4de938..587a2d8f33 100644 --- a/decko/lib/decko/commands/command.rb +++ b/decko/lib/decko/commands/command.rb @@ -1,28 +1,8 @@ -# require "English" # needed for CHILD_STATUS, but not sure this is the best place for this. +require 'cardio/commands/command' module Decko module Commands - class Command - def run - puts command - exit_with_child_status command - end - - def exit_with_child_status command - command += " 2>&1" - exit $CHILD_STATUS.exitstatus unless system command - end - - # split special decko args and original command args separated by '--' - def split_args args - before_split = true - decko_args, command_args = - args.partition do |a| - before_split = (a == "--" ? false : before_split) - end - command_args.shift - [decko_args, command_args] - end + class Command < Cardio::Commands::Command end end end diff --git a/decko/lib/decko/commands/rake_command.rb b/decko/lib/decko/commands/rake_command.rb new file mode 100644 index 0000000000..830389647a --- /dev/null +++ b/decko/lib/decko/commands/rake_command.rb @@ -0,0 +1,12 @@ + +require "cardio/commands/command" +warn "DECKOCMD #{__LINE__}:#{__FILE__}" + +module Decko + module Commands + + class RakeCommand < Cardio::Commands::Command + end + end +end + From 597d7e044fbda12263935c27bb4109eab05b07be Mon Sep 17 00:00:00 2001 From: Gerry Gleason Date: Wed, 14 Oct 2020 15:13:17 -0500 Subject: [PATCH 11/11] Working on rake first, not quite loading environments yet. Need to load application environments and such --- card/card.gemspec | 7 +- card/lib/cardio/application.rb | 2 - card/lib/cardio/cli.rb | 1 + card/lib/cardio/commands.rb | 101 +++++++++--------- card/lib/cardio/commands/application.rb | 3 +- decko/bin/decko | 9 -- decko/decko.gemspec | 4 +- decko/exe/decko | 9 ++ decko/lib/decko/cli.rb | 24 ++--- decko/lib/decko/commands.rb | 19 ++-- decko/lib/decko/commands/application.rb | 7 +- decko/lib/decko/commands/rake_command.rb | 1 - .../generators/deck/templates/script/decko | 6 -- 13 files changed, 96 insertions(+), 97 deletions(-) delete mode 100755 decko/bin/decko create mode 100755 decko/exe/decko delete mode 100755 decko/lib/decko/generators/deck/templates/script/decko diff --git a/card/card.gemspec b/card/card.gemspec index 4d6ac6edee..459814d532 100644 --- a/card/card.gemspec +++ b/card/card.gemspec @@ -11,8 +11,11 @@ DeckoGem.gem "card" do |s, d| 'Card "Sharks" use links, nests, types, patterned names, queries, views, ' \ "events, and rules to create rich structures." - s.files = Dir["VERSION", "README.rdoc", "LICENSE", "GPL", ".yardopts", - "{config,db,lib,mod,tmpsets}/**/*"] + s.files = Dir["VERSION", "README.md", "LICENSE", "GPL", + "{exe,config,db,lib,mod}/**/*"] + + s.bindir = "exe" + s.executables = ["card"] d.depends_on( ["cardname", d.decko_version], diff --git a/card/lib/cardio/application.rb b/card/lib/cardio/application.rb index 3611e25085..dbcd91f633 100644 --- a/card/lib/cardio/application.rb +++ b/card/lib/cardio/application.rb @@ -23,7 +23,6 @@ def inherited base #before: :connect_on_load, group: :all do add_path "lib/card/config/environments", glob: "#{Rails.env}.rb", root: Cardio.gem_root paths["lib/card/config/environments"].existent.each do |environment| -warn "load env #{environment}" require environment end end @@ -42,7 +41,6 @@ def inherited base ActiveSupport.on_load(:before_card) do end ActiveSupport.on_load(:after_application_record) do -warn "load ap rec trig, load card" Cardio.load_card! end end diff --git a/card/lib/cardio/cli.rb b/card/lib/cardio/cli.rb index eb26648f1e..04dbeddf39 100644 --- a/card/lib/cardio/cli.rb +++ b/card/lib/cardio/cli.rb @@ -1,3 +1,4 @@ require "rbconfig" require "pathname" +require "cardio/commands/application" diff --git a/card/lib/cardio/commands.rb b/card/lib/cardio/commands.rb index a3d28a1cd4..6ae43356f6 100644 --- a/card/lib/cardio/commands.rb +++ b/card/lib/cardio/commands.rb @@ -1,17 +1,7 @@ # add method in? to Object class require "active_support/core_ext/object/inclusion" -#require 'cardio/application_record' +require "cardio" -require "rake" -def load_rake_tasks - require "./config/environment" - Cardio::Application.load_tasks -end - -#require "cardio" -# if anything left, include in Decko -# should go to card_command.rb -=begin module Cardio module Commands @@ -28,9 +18,17 @@ def run_rspec end def run_task command + load_rake_tasks + require "cardio/commands/application" require "cardio/commands/rake_command" RakeCommand.new(['card', command]*':', ARGV).run end + + def load_rake_tasks + require "rake" + require "./config/environment" + Cardio::Application.load_tasks + end end class << self @@ -43,47 +41,50 @@ class << self ARGV.unshift 'card' if ARGV.first == '-T' command = ARGV.first -command = ALIAS[command] || command - - ARGV.shift - lookup = command - lookup = $1 if command =~ /^([^:]+):/ - case lookup - when "--version", "-v" - puts "Card #{Card::Version.release}" - when 'rspec' - Cardio::Commands.run_rspec - when *Cardio::Commands::CARD_TASK_COMMANDS - Cardio::Commands::RakeCommand.run_task command - else - puts "Error: Command not recognized" unless command.in?(["-h", "--help"]) - puts <<-EOT +#FIXME: how to use DECK aliases? maybe they need to be here? +#command = ALIAS[command] || command + +ARGV.shift +lookup = command +lookup = $1 if command =~ /^([^:]+):/ + +case lookup +when "--version", "-v" + puts "Card #{Card::Version.release}" +when 'rspec' + Cardio::Commands.run_rspec +when *Cardio::Commands::CARD_TASK_COMMANDS + Cardio::Commands.run_task command +else + puts "Error: Command not recognized" unless command.in?(["-h", "--help"]) + # FIXME: give mostly card help, card -T to list, rspec, etc. reference decko + puts <<-EOT Usage: card COMMAND [ARGS] - The most common card commands are: - seed Create and seed the database specified in config/database.yml - - server Start the Rails server (short-cut alias: "s") - console Start the Rails console (short-cut alias: "c") - dbconsole Start a console for the database specified in config/database.yml - (short-cut alias: "db") - - For core developers - rspec Run rspec tests (short-cut alias: "rs") - update Run card migrations - load Load bootstrap data into database - - In addition to those, there are the standard rails commands: - generate Generate new code (short-cut alias: "g") - application Generate the Rails application code - destroy Undo code generated with "generate" (short-cut alias: "d") - benchmarker See how fast a piece of code runs - profiler Get profile information from a piece of code - plugin Install a plugin - runner Run a piece of code in the application environment (short-cut alias: "r") - -All commands can be run with -h (or --help) for more information. + The most common card commands are: (customized from rails?) + seed Create and seed the database specified in config/database.yml + + server Start the Rails server (short-cut alias: "s") + console Start the Rails console (short-cut alias: "c") + dbconsole Start a console for the database specified in config/database.yml + (short-cut alias: "db") + + For core developers + rspec Run rspec tests (short-cut alias: "rs") + update Run card migrations + load Load bootstrap data into database + + In addition to those, there are the standard rails commands: + generate Generate new code (short-cut alias: "g") + application Generate the Rails application code + destroy Undo code generated with "generate" (short-cut alias: "d") + benchmarker See how fast a piece of code runs + profiler Get profile information from a piece of code + plugin Install a plugin + runner Run a piece of code in the application environment (short-cut alias: "r") + + All commands can be run with -h (or --help) for more information. EOT + exit(1) end - diff --git a/card/lib/cardio/commands/application.rb b/card/lib/cardio/commands/application.rb index a390f85c08..d43ae89a8b 100644 --- a/card/lib/cardio/commands/application.rb +++ b/card/lib/cardio/commands/application.rb @@ -9,7 +9,6 @@ cmd = ARGV.shift end -require "cardio/application" - require "cardio/commands" + Cardio::Commands.run_new diff --git a/decko/bin/decko b/decko/bin/decko deleted file mode 100755 index 8ef9561171..0000000000 --- a/decko/bin/decko +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env ruby - -git_path = File.expand_path("../../../.git", __FILE__) - -if File.exist?(git_path) - railties_path = File.expand_path("../../lib", __FILE__) - $LOAD_PATH.unshift(railties_path) -end -require "decko/cli" diff --git a/decko/decko.gemspec b/decko/decko.gemspec index 6c0a87c186..54a85d0ea5 100644 --- a/decko/decko.gemspec +++ b/decko/decko.gemspec @@ -7,9 +7,9 @@ DeckoGem.gem "decko" do |s, d| s.description = "a wiki approach to structured data, dynamic interaction, and web design" - s.files = Dir["{db,lib,public,set}/**/*"] + s.files = Dir["{exe,app,lib,rails}/**/*"] - s.bindir = "bin" + s.bindir = "exe" s.executables = ["decko"] s.add_runtime_dependency "card", d.card_version end diff --git a/decko/exe/decko b/decko/exe/decko new file mode 100755 index 0000000000..e408bb7f6d --- /dev/null +++ b/decko/exe/decko @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby + +#git_path = File.expand_path("../../../.git", __FILE__) +#if File.exist?(git_path) +# railties_path = File.expand_path("../../lib", __FILE__) +# $LOAD_PATH.unshift(railties_path) +#end + +require "decko/cli" diff --git a/decko/lib/decko/cli.rb b/decko/lib/decko/cli.rb index 7b5adafea2..ed2c86523d 100644 --- a/decko/lib/decko/cli.rb +++ b/decko/lib/decko/cli.rb @@ -34,23 +34,19 @@ def self.in_decko_application_subdirectory? path=Pathname.new(Dir.pwd) # config/application.rb, therefore any rails and use card commands # otherwise we are decko new and decko/commands.rb should handle it. # The first case here is in app, replaces script_loader method -if APP_CONF = ScriptLoader.find_app_config -warn "CLI #{__FILE__}:#{__LINE__} #{APP_CONF} (require boot #{File.expand_path("../boot", APP_CONF)}" +if defined?(APP_CONF) || APP_CONF = ScriptLoader.find_app_config require APP_CONF require File.expand_path("../boot", APP_CONF) - require 'cardio/commands' -else - - require "rails/ruby_version_check" - Signal.trap("INT") { puts; exit(1) } + require 'decko/commands' +end -# if ARGV.first == 'plugin' -# ARGV.shift -# require 'decko/commands/plugin_new' -# else + require "rails/ruby_version_check" + Signal.trap("INT") { puts; exit(1) } - # should be decko new or usage +#if ARGV.first == 'plugin' +# ARGV.shift +# require 'decko/commands/plugin_new' +#else require "decko/commands/application" - # end -end +#end diff --git a/decko/lib/decko/commands.rb b/decko/lib/decko/commands.rb index 7a1ea8b765..464f8ab79a 100644 --- a/decko/lib/decko/commands.rb +++ b/decko/lib/decko/commands.rb @@ -1,12 +1,6 @@ # add method in? to Object class require "active_support/core_ext/object/inclusion" -def load_rake_tasks - require "./config/environment" - require "rake" - Decko::Application.load_tasks -end - require 'cardio/commands' RAILS_COMMANDS = %w( generate destroy plugin benchmarker profiler console server dbconsole application runner ).freeze @@ -51,6 +45,8 @@ def run_cucumber end def run_task command + load_rake_tasks + require "decko/commands/application" require "decko/commands/rake_command" RakeCommand.new("decko:#{command}", ARGV).run end @@ -59,6 +55,12 @@ def run_jasmine require "decko/commands/rake_command" RakeCommand.new("spec:javascript", envs: "test").run end + + def load_rake_tasks + require "rake" + require "./config/environment" + Decko::Application.load_tasks + end end end end @@ -71,8 +73,13 @@ def run_jasmine # without this, the card generators don't list with: decko g --help require "generators/card" if command == "generate" require "rails/commands" +elsif command == "-T" + load_rake_tasks else ARGV.shift + lookup = command + lookup = $1 if command =~ /^([^:]+):/ + case command when "--version", "-v" puts "Decko #{Card::Version.release}" diff --git a/decko/lib/decko/commands/application.rb b/decko/lib/decko/commands/application.rb index e10342031c..8a7bc852fe 100644 --- a/decko/lib/decko/commands/application.rb +++ b/decko/lib/decko/commands/application.rb @@ -2,9 +2,10 @@ require File.expand_path("../../generators/deck/deck_generator", __FILE__) if ARGV.first != "new" - ARGV[0] = "--help" + #require "decko/application" + require "cardio/commands" else ARGV.shift -end -Decko::Generators::Deck::DeckGenerator.start + Decko::Generators::Deck::DeckGenerator.start +end diff --git a/decko/lib/decko/commands/rake_command.rb b/decko/lib/decko/commands/rake_command.rb index 830389647a..493db71d00 100644 --- a/decko/lib/decko/commands/rake_command.rb +++ b/decko/lib/decko/commands/rake_command.rb @@ -1,6 +1,5 @@ require "cardio/commands/command" -warn "DECKOCMD #{__LINE__}:#{__FILE__}" module Decko module Commands diff --git a/decko/lib/decko/generators/deck/templates/script/decko b/decko/lib/decko/generators/deck/templates/script/decko deleted file mode 100755 index 1dbb54b374..0000000000 --- a/decko/lib/decko/generators/deck/templates/script/decko +++ /dev/null @@ -1,6 +0,0 @@ - -# This command will be run when you use `decko` from within your deck. - -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) -require 'decko/commands'