Module: Cardio

Extended by:
Delaying, Modfiles, Schema, Utils
Defined in:
card/lib/cardio.rb,
card/lib/cardio/mod.rb,
card/lib/cardio/utils.rb,
card/lib/cardio/schema.rb,
card/lib/cardio/delaying.rb,
card/lib/cardio/mod/dirs.rb,
card/lib/cardio/modfiles.rb,
card/lib/cardio/migration.rb,
card/lib/cardio/mod/loader.rb,
card-mod-monkey/lib/cardio/pry.rb,
card/lib/cardio/migration/core.rb,
card/lib/cardio/migration/import.rb,
card/lib/cardio/mod/load_strategy.rb,
card/lib/cardio/mod/module_template.rb,
card/lib/cardio/mod/loader/set_loader.rb,
card/lib/cardio/mod/load_strategy/eval.rb,
card-mod-monkey/lib/cardio/pry/commands.rb,
card/lib/cardio/migration/import/merger.rb,
card/lib/cardio/migration/deck_structure.rb,
card-mod-delayed_job/lib/cardio/delayed_job.rb,
card/lib/cardio/mod/load_strategy/tmp_files.rb,
card/lib/cardio/migration/import/import_data.rb,
card/lib/cardio/mod/loader/set_pattern_loader.rb,
card/lib/cardio/mod/load_strategy/set_tmp_files.rb,
card/lib/cardio/mod/load_strategy/pattern_tmp_files.rb,
card/lib/cardio/mod/load_strategy/set_binding_magic.rb,
card/lib/cardio/migration/import/import_data/card_content.rb,
card/lib/cardio/migration/import/import_data/card_attributes.rb

Defined Under Namespace

Modules: DelayedJob, Delaying, Mod, Modfiles, Pry, Schema, Utils Classes: Migration

Constant Summary collapse

CARD_GEM_ROOT =
File.expand_path("..", __dir__)

Class Method Summary collapse

Methods included from Schema

assume_migrated_upto_version, deck_migration?, migrate, migration_context, migration_paths, schema, schema_mode, schema_stamp_path, schema_suffix, with_migration_table, with_suffix

Methods included from Utils

database_name, delete_tmp_files!, seed_test_db, t

Methods included from Modfiles

each_gem_mod_path, each_mod_path, each_simple_mod_path, gem_mod_spec?, gem_mod_specs, mod_migration_paths

Methods included from Delaying

delaying!, delaying?

Class Method Details

.add_db_pathsObject



120
121
122
123
124
125
126
127
# File 'card/lib/cardio.rb', line 120

def add_db_paths
  add_path "db"
  add_path "db/migrate"
  add_path "db/migrate_core_cards"
  add_path "db/migrate_deck", root: root, with: "db/migrate"
  add_path "db/migrate_deck_cards", root: root, with: "db/migrate_cards"
  add_path "db/seeds.rb", with: "db/seeds.rb"
end

.add_initializer_pathsObject



129
130
131
132
133
# File 'card/lib/cardio.rb', line 129

def add_initializer_paths
  add_path "config/initializers", glob: "**/*.rb"
  add_initializers root
  each_mod_path { |mod_path| add_initializers mod_path, false, "core_initializers" }
end

.add_initializers(base_dir, mod = false, init_dir = "initializers") ⇒ Object



140
141
142
143
144
145
# File 'card/lib/cardio.rb', line 140

def add_initializers base_dir, mod=false, init_dir="initializers"
  Dir.glob("#{base_dir}/config/#{init_dir}").each do |initializers_dir|
    path_mark = mod ? "mod/config/initializers" : "config/initializers"
    paths[path_mark] << initializers_dir
  end
end

.add_lib_dirs_to_autoload_paths(config) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'card/lib/cardio.rb', line 65

def add_lib_dirs_to_autoload_paths config
  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 }

  # 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

.add_mod_initializer_pathsObject



135
136
137
138
# File 'card/lib/cardio.rb', line 135

def add_mod_initializer_paths
  add_path "mod/config/initializers", glob: "**/*.rb"
  each_mod_path { |mod_path| add_initializers mod_path, true }
end

.add_path(path, options = {}) ⇒ Object



155
156
157
158
159
# File 'card/lib/cardio.rb', line 155

def add_path path, options={}
  root = options.delete(:root) || gem_root
  options[:with] = File.join(root, (options[:with] || path))
  paths.add path, options
end

.add_tmppathsObject



105
106
107
108
109
110
# File 'card/lib/cardio.rb', line 105

def add_tmppaths
  %w[set set_pattern].each do |dir|
    opts = tmppath_opts dir
    add_path "tmp/#{dir}", opts if opts
  end
end

.autoload_and_watch(config, mod_path) ⇒ Object



81
82
83
84
# File 'card/lib/cardio.rb', line 81

def autoload_and_watch config, mod_path
  config.autoload_paths += Dir["#{mod_path}/lib"]
  config.watchable_dirs["#{mod_path}/set"] = [:rb]
end

.cacheObject



38
39
40
# File 'card/lib/cardio.rb', line 38

def cache
  @cache ||= ::Rails.cache
end

.card_defined?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'card/lib/cardio.rb', line 23

def card_defined?
  const_defined? "Card"
end

.default_configsObject

TODO: many of these defaults should be in mods!



43
44
45
46
47
48
# File 'card/lib/cardio.rb', line 43

def default_configs
  defaults_from_yaml.merge(
    read_only: !ENV["DECKO_READ_ONLY"].nil?,
    load_strategy: (ENV["REPO_TMPSETS"] || ENV["TMPSETS"] ? :tmp_files : :eval)
  )
end

.defaults_from_yamlObject



50
51
52
53
# File 'card/lib/cardio.rb', line 50

def defaults_from_yaml
  filename = File.expand_path "cardio/defaults.yml", __dir__
  YAML.load_file filename
end

.future_stampObject



161
162
163
164
# File 'card/lib/cardio.rb', line 161

def future_stamp
  # # used in test data
  @future_stamp ||= Time.zone.local 2020, 1, 1, 0, 0, 0
end

.gem_rootObject



151
152
153
# File 'card/lib/cardio.rb', line 151

def gem_root
  CARD_GEM_ROOT
end

.load_card!Object



33
34
35
36
# File 'card/lib/cardio.rb', line 33

def load_card!
  require "card"
  ActiveSupport.run_load_hooks :after_card
end

.load_card?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'card/lib/cardio.rb', line 27

def load_card?
  ActiveRecord::Base.connection && !card_defined?
rescue StandardError
  false
end

.rootObject



147
148
149
# File 'card/lib/cardio.rb', line 147

def root
  @@config.root
end

.set_config(config) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'card/lib/cardio.rb', line 55

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)
  end
end

.set_default_value(config, setting, *value) ⇒ Object

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



89
90
91
# File 'card/lib/cardio.rb', line 89

def set_default_value config, setting, *value
  config.send("#{setting}=", *value) unless config.respond_to? setting
end

.set_paths(paths) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'card/lib/cardio.rb', line 93

def set_paths paths
  @@paths = paths

  add_tmppaths
  add_path "mod"        # add card gem's mod path
  paths["mod"] << "mod" # add deck's mod path

  add_db_paths
  add_initializer_paths
  add_mod_initializer_paths
end

.tmppath_opts(dir) ⇒ Object



112
113
114
115
116
117
118
# File 'card/lib/cardio.rb', line 112

def tmppath_opts dir
  if ENV["REPO_TMPSETS"]
    { with: "tmpsets/#{dir}" }
  elsif ENV["TMPSETS"]
    { root: root }
  end
end