Module: Cardio
- Extended by:
- Delaying, Modfiles, Schema, Utils
- Defined in:
- lib/cardio.rb,
lib/cardio/mod.rb,
lib/cardio/utils.rb,
lib/cardio/schema.rb,
lib/cardio/delaying.rb,
lib/cardio/mod/dirs.rb,
lib/cardio/modfiles.rb,
lib/cardio/migration.rb,
lib/cardio/mod/loader.rb,
lib/cardio/migration/core.rb,
lib/cardio/migration/import.rb,
lib/cardio/mod/load_strategy.rb,
lib/cardio/mod/module_template.rb,
lib/cardio/mod/loader/set_loader.rb,
lib/cardio/mod/load_strategy/eval.rb,
lib/cardio/migration/import/merger.rb,
lib/cardio/migration/deck_structure.rb,
lib/cardio/mod/load_strategy/tmp_files.rb,
lib/cardio/migration/import/import_data.rb,
lib/cardio/mod/loader/set_pattern_loader.rb,
lib/cardio/mod/load_strategy/set_tmp_files.rb,
lib/cardio/mod/load_strategy/pattern_tmp_files.rb,
lib/cardio/mod/load_strategy/set_binding_magic.rb,
lib/cardio/migration/import/import_data/card_content.rb,
lib/cardio/migration/import/import_data/card_attributes.rb
Defined Under Namespace
Modules: Delaying, Mod, Modfiles, 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_paths ⇒ Object
120
121
122
123
124
125
126
127
|
# File '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_paths ⇒ Object
129
130
131
132
133
|
# File '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 '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 'lib/cardio.rb', line 65
def add_lib_dirs_to_autoload_paths config
config.autoload_paths += Dir["#{gem_root}/lib"]
[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 }
config.autoload_paths += Dir["#{Decko.gem_root}/lib"]
end
|
.add_mod_initializer_paths ⇒ Object
135
136
137
138
|
# File '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 '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_tmppaths ⇒ Object
105
106
107
108
109
110
|
# File '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 '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
|
.cache ⇒ Object
38
39
40
|
# File 'lib/cardio.rb', line 38
def cache
@cache ||= ::Rails.cache
end
|
.card_defined? ⇒ Boolean
23
24
25
|
# File 'lib/cardio.rb', line 23
def card_defined?
const_defined? "Card"
end
|
.default_configs ⇒ Object
TODO: many of these defaults should be in mods!
43
44
45
46
47
48
|
# File '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_yaml ⇒ Object
50
51
52
53
|
# File 'lib/cardio.rb', line 50
def defaults_from_yaml
filename = File.expand_path "cardio/defaults.yml", __dir__
YAML.load_file filename
end
|
.future_stamp ⇒ Object
161
162
163
164
|
# File 'lib/cardio.rb', line 161
def future_stamp
@future_stamp ||= Time.zone.local 2020, 1, 1, 0, 0, 0
end
|
.gem_root ⇒ Object
151
152
153
|
# File 'lib/cardio.rb', line 151
def gem_root
CARD_GEM_ROOT
end
|
.load_card! ⇒ Object
33
34
35
36
|
# File 'lib/cardio.rb', line 33
def load_card!
require "card"
ActiveSupport.run_load_hooks :after_card
end
|
.load_card? ⇒ Boolean
27
28
29
30
31
|
# File 'lib/cardio.rb', line 27
def load_card?
ActiveRecord::Base.connection && !card_defined?
rescue StandardError
false
end
|
.root ⇒ Object
147
148
149
|
# File 'lib/cardio.rb', line 147
def root
@@config.root
end
|
.set_config(config) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File '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 '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 'lib/cardio.rb', line 93
def set_paths paths
@@paths = paths
add_tmppaths
add_path "mod" paths["mod"] << "mod"
add_db_paths
add_initializer_paths
add_mod_initializer_paths
end
|
.tmppath_opts(dir) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/cardio.rb', line 112
def tmppath_opts dir
if ENV["REPO_TMPSETS"]
{ with: "tmpsets/#{dir}" }
elsif ENV["TMPSETS"]
{ root: root }
end
end
|