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/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 4f8d98e40d..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.md", "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/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..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. @@ -92,7 +93,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} 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 f03007d354..a4cd10076b 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 e0b26e6942..85ee9adba0 100644 --- a/card/lib/cardio.rb +++ b/card/lib/cardio.rb @@ -7,7 +7,8 @@ require "cardio/delaying" ActiveSupport.on_load :after_card do - Card::Mod.load + #require 'cardio/mod' # should autoload + Cardio::Mod.load end module Cardio @@ -17,11 +18,37 @@ 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" + if const_defined? "Card" + raise "Wrong Card" unless Card.is_a? ApplicationRecord + true + end end def load_card? @@ -30,17 +57,12 @@ def load_card? false end - def load_card! - require "card" - ActiveSupport.run_load_hooks :after_card - end - def cache @cache ||= ::Rails.cache end def default_configs - { + defaults = { read_only: read_only?, # if you disable inline styles tinymce's formatting options stop working @@ -80,6 +102,7 @@ def default_configs request_logger: false, performance_logger: false, sql_comments: true, + eager_load: false, file_storage: :local, file_buckets: {}, @@ -101,35 +124,28 @@ def default_configs load_strategy: :eval, cache_set_module_list: false } - end - - def set_config config - @@config = config - - add_lib_dirs_to_autoload_paths config - - 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 - 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 # 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 @@ -138,17 +154,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 paths - @@paths = 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 @@ -160,6 +168,59 @@ def set_paths 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" @@ -186,24 +247,5 @@ def add_initializers base_dir, mod=false, init_dir="initializers" paths[path_mark] << initializers_dir 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)) - 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 new file mode 100644 index 0000000000..dbcd91f633 --- /dev/null +++ b/card/lib/cardio/application.rb @@ -0,0 +1,86 @@ +# -*- encoding : utf-8 -*- + +require 'rails' + +Bundler.require :default, *Rails.groups if defined?(Bundler) + +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| + 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) + 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 + Cardio.load_card! + end + end + + def configure &block + super do + instance_eval &block if block_given? + + config.load_default = "6.0" + 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 + + 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 + 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/cli.rb b/card/lib/cardio/cli.rb new file mode 100644 index 0000000000..04dbeddf39 --- /dev/null +++ b/card/lib/cardio/cli.rb @@ -0,0 +1,4 @@ +require "rbconfig" +require "pathname" + +require "cardio/commands/application" diff --git a/card/lib/cardio/commands.rb b/card/lib/cardio/commands.rb new file mode 100644 index 0000000000..6ae43356f6 --- /dev/null +++ b/card/lib/cardio/commands.rb @@ -0,0 +1,90 @@ +# add method in? to Object class +require "active_support/core_ext/object/inclusion" +require "cardio" + +module Cardio + module Commands + + 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_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 + include ClassMethods + end + end +end + +ARGV << "--help" if ARGV.empty? + +ARGV.unshift 'card' if ARGV.first == '-T' +command = ARGV.first +#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: (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 new file mode 100644 index 0000000000..d43ae89a8b --- /dev/null +++ b/card/lib/cardio/commands/application.rb @@ -0,0 +1,14 @@ +# -*- encoding : utf-8 -*- + +# no card generator new templates +require "generators/card" + +if ARGV.first != "new" + #ARGV[0] = "--help" +else + cmd = ARGV.shift +end + +require "cardio/commands" + +Cardio::Commands.run_new 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/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/rake_command.rb b/card/lib/cardio/commands/rake_command.rb new file mode 100644 index 0000000000..60d0caed17 --- /dev/null +++ b/card/lib/cardio/commands/rake_command.rb @@ -0,0 +1,40 @@ +require "cardio/commands/command" + +module Cardio + module Commands + class RakeCommand < Command + def initialize rake_task, args={} + @task = rake_task + opts = {} + if args.is_a? Array + Parser.new(rake_task, opts).parse!(args) + else + opts = args + end + @envs = Array(opts[:envs]) + end + + def run + commands.each do |cmd| + puts cmd + # exit_with_child_status cmd + + result = `#{cmd}` + process = $? + puts result + exit process.exitstatus unless process.success? + end + end + + def commands + task_cmd = "bundle exec rake #{@task}" + return [task_cmd] if !@envs || @envs.empty? + @envs.map do |env| + "env RAILS_ENV=#{env} #{task_cmd}" + end + end + end + end +end + +require "cardio/commands/rake_command/parser" diff --git a/decko/lib/decko/commands/rake_command/parser.rb b/card/lib/cardio/commands/rake_command/parser.rb similarity index 86% rename from decko/lib/decko/commands/rake_command/parser.rb rename to card/lib/cardio/commands/rake_command/parser.rb index 8997b4a293..5a1be058f4 100644 --- a/decko/lib/decko/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 new file mode 100644 index 0000000000..5ef760c491 --- /dev/null +++ b/card/lib/cardio/commands/rspec_command.rb @@ -0,0 +1,94 @@ +require File.expand_path("../command", __FILE__) + +module Cardio + module Commands + class RspecCommand < Command + def initialize args + require "rspec/core" + + @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} #{spec_files_from_opts(@opts)*' '} "\ + "--exclude-pattern \"./card/vendor/**/*\"" + end + + private + + 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 (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 + +require File.expand_path("../rspec_command/parser", __FILE__) diff --git a/card/lib/cardio/commands/rspec_command/parser.rb b/card/lib/cardio/commands/rspec_command/parser.rb new file mode 100644 index 0000000000..ab3edbbf1a --- /dev/null +++ b/card/lib/cardio/commands/rspec_command/parser.rb @@ -0,0 +1,101 @@ +# -*- encoding : utf-8 -*- +require "optparse" +require 'cardio/commands/command/parser' + +module Cardio + module Commands + class RspecCommand < Command + class Parser < Command::Parser + RSPEC_PATH_MESSAGE = <<-EOT + + {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 + corresponding spec file. + The line number always refers to the example in the spec file. + + EOT + + 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_USAGE_MESSAGE + parser.separator RSPEC_PATH_MESSAGE + + # 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 + + 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 options[:executer] == "spring" + puts "Disabled pry-rescue. Not compatible with spring." + else + options[:rescue] = "rescue " + end + end + + def process_spring_opts spring, opts + if spring + options[:executer] = "spring" + if options[:rescue] + options[:rescue] = "" + puts "Disabled pry-rescue. Not compatible with spring." + end + else + options[:executer] = "bundle exec" + end + end + end + end + end +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/card/mod.rb b/card/lib/cardio/mod.rb similarity index 96% rename from card/lib/card/mod.rb rename to card/lib/cardio/mod.rb index c5a1b8d561..8dcc9e9a0e 100644 --- a/card/lib/card/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/card/mod/dirs.rb b/card/lib/cardio/mod/dirs.rb similarity index 98% rename from card/lib/card/mod/dirs.rb rename to card/lib/cardio/mod/dirs.rb index cc6971c75f..66a3f56944 100644 --- a/card/lib/card/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/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 93% rename from card/lib/card/mod/load_strategy/pattern_tmp_files.rb rename to card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb index ac2dd054bf..35c195a2f2 100644 --- a/card/lib/card/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/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 92% rename from card/lib/card/mod/load_strategy/tmp_files.rb rename to card/lib/cardio/mod/load_strategy/tmp_files.rb index 7385d76d4f..aa52083419 100644 --- a/card/lib/card/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/card/mod/loader.rb b/card/lib/cardio/mod/loader.rb similarity index 86% rename from card/lib/card/mod/loader.rb rename to card/lib/cardio/mod/loader.rb index 2452b2407a..2b80122aeb 100644 --- a/card/lib/card/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/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/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/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 98% rename from card/lib/card/tasks/card/migrate.rake rename to card/lib/tasks/migrate.rake index 571f4eb108..f177f852e9 100644 --- a/card/lib/card/tasks/card/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/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/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 4de449e8f7..84eebb3858 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 7ab107ed2f..2611147894 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/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/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/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.rb b/decko/lib/decko.rb index 2f8965631d..531dcf698c 100644 --- a/decko/lib/decko.rb +++ b/decko/lib/decko.rb @@ -1,23 +1,12 @@ +require 'cardio' + 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..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,17 +16,17 @@ 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 config - @config ||= begin - config = super + def configure &block + super do - Cardio.set_config config + 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 @@ -50,7 +42,6 @@ def config # 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 @@ -64,14 +55,9 @@ def config # Rails.autoloaders.log! Rails.autoloaders.main.ignore(File.join(Cardio.gem_root, "lib/card/seed_consts.rb")) - config - end - end + # paths configuration - def paths - @paths ||= begin - paths = super - Cardio.set_paths paths + Cardio.set_paths paths.add "files" @@ -82,8 +68,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/cli.rb b/decko/lib/decko/cli.rb index 7da1b02516..ed2c86523d 100644 --- a/decko/lib/decko/cli.rb +++ b/decko/lib/decko/cli.rb @@ -1,17 +1,52 @@ require "rbconfig" -require "decko/script_decko_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. -Decko::ScriptDeckoLoader.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' + 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 defined?(APP_CONF) || APP_CONF = ScriptLoader.find_app_config + require APP_CONF + require File.expand_path("../boot", APP_CONF) + require 'decko/commands' +end + + require "rails/ruby_version_check" + Signal.trap("INT") { puts; exit(1) } + +#if ARGV.first == 'plugin' # ARGV.shift # require 'decko/commands/plugin_new' -# else +#else + require "decko/commands/application" +#end -require "decko/commands/application" -# end diff --git a/decko/lib/decko/commands.rb b/decko/lib/decko/commands.rb index 0d65e8147e..464f8ab79a 100644 --- a/decko/lib/decko/commands.rb +++ b/decko/lib/decko/commands.rb @@ -1,16 +1,11 @@ # 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 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 +25,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 +44,9 @@ def run_cucumber CucumberCommand.new(ARGV).run end - def run_db_task command + def run_task command + load_rake_tasks + require "decko/commands/application" require "decko/commands/rake_command" RakeCommand.new("decko:#{command}", ARGV).run end @@ -63,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 @@ -75,15 +73,21 @@ 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}" 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/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/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 index 2b2f3e7da8..493db71d00 100644 --- a/decko/lib/decko/commands/rake_command.rb +++ b/decko/lib/decko/commands/rake_command.rb @@ -1,41 +1,11 @@ -require File.expand_path("../command", __FILE__) -# require "pry" + +require "cardio/commands/command" module Decko module Commands - class RakeCommand < Command - def initialize rake_task, args={} - @task = rake_task - opts = {} - if args.is_a? Array - Parser.new(rake_task, opts).parse!(args) - else - opts = args - end - @envs = Array(opts[:envs]) - end - - def run - commands.each do |cmd| - puts cmd - # exit_with_child_status cmd - - result = `#{cmd}` - process = $? - puts result - exit process.exitstatus unless process.success? - end - end - def commands - task_cmd = "bundle exec rake #{@task}" - return [task_cmd] if !@envs || @envs.empty? - @envs.map do |env| - "env RAILS_ENV=#{env} #{task_cmd}" - end - end + class RakeCommand < Cardio::Commands::Command end end end -require File.expand_path("../rake_command/parser", __FILE__) \ No newline at end of file diff --git a/decko/lib/decko/commands/rspec_command.rb b/decko/lib/decko/commands/rspec_command.rb deleted file mode 100644 index 7064414379..0000000000 --- a/decko/lib/decko/commands/rspec_command.rb +++ /dev/null @@ -1,37 +0,0 @@ -require File.expand_path("../command", __FILE__) - -module Decko - 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) - end - - def command - "#{env_args} #{@opts[:executer]} #{@opts[:rescue]}" \ - "rspec #{@rspec_args.shelljoin} #{@opts[:files]}" - end - - private - - def env_args - ["RAILS_ROOT=.", coverage].compact.join " " - end - - def coverage - # no coverage if rspec was started with file argument - if (@opts[:files] || @rspec_args.present?) && !@opts[:simplecov] - @opts[:simplecov] = "COVERAGE=false" - end - @opts[:simplecov] - end - end - end -end - -require File.expand_path("../rspec_command/parser", __FILE__) diff --git a/decko/lib/decko/commands/rspec_command/parser.rb b/decko/lib/decko/commands/rspec_command/parser.rb deleted file mode 100644 index 3233a126e1..0000000000 --- a/decko/lib/decko/commands/rspec_command/parser.rb +++ /dev/null @@ -1,96 +0,0 @@ -# -*- encoding : utf-8 -*- -require "optparse" - -module Decko - module Commands - class RspecCommand - class Parser < OptionParser - RSPEC_PATH_MESSAGE = <<-EOT - - DECKO 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 - corresponding spec file. - The line number always refers to the example in the spec file. - - EOT - - def initialize opts - super() do |parser| - parser.banner = "Usage: decko rspec [DECKO ARGS] -- [RSPEC ARGS]\n\n" \ - "RSPEC ARGS" - 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" - end - end - - private - - def process_rescue_opts opts - if opts[:executer] == "spring" - puts "Disabled pry-rescue. Not compatible with spring." - else - opts[:rescue] = "rescue " - end - end - - def process_spring_opts spring, opts - if spring - opts[:executer] = "spring" - if opts[:rescue] - opts[: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(" ") - end - end - end - 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/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' 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 diff --git a/decko/lib/decko/tasks/.gitkeep b/decko/lib/decko/tasks/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 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 98% rename from decko/lib/decko/tasks/decko.rake rename to decko/lib/tasks/decko.rake index 6087ea7483..7df20acd1b 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 = @@ -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 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