Module: PhilColumns::SeedUtils
- Included in:
- Command::List::TaggedWith, Command::List::Tags, Filter, Seeder
- Defined in:
- lib/phil_columns/seed_utils.rb
Constant Summary collapse
- SEED_REGEX =
/^\w+\/\w+\/(\d{14})_(.+)\.rb$/
Instance Method Summary collapse
- #archivist ⇒ Object
- #discover_seed_class(filepath) ⇒ Object
- #discover_seed_timestamp(filepath) ⇒ Object
- #each_seed_meta_for_current_env(&block) ⇒ Object
- #load_seeds ⇒ Object
- #map_seeds ⇒ Object
- #seed_already_executed?(version) ⇒ Boolean
- #seed_filepaths ⇒ Object
- #seeds_for_current_env ⇒ Object
- #seeds_path ⇒ Object
Instance Method Details
#archivist ⇒ Object
63 64 65 |
# File 'lib/phil_columns/seed_utils.rb', line 63 def archivist @archivist ||= PhilColumns::Archivist.new end |
#discover_seed_class(filepath) ⇒ Object
53 54 55 56 57 |
# File 'lib/phil_columns/seed_utils.rb', line 53 def discover_seed_class( filepath ) matches = SEED_REGEX.match( filepath ) snakecased = matches[2] snakecased.camelize.constantize end |
#discover_seed_timestamp(filepath) ⇒ Object
48 49 50 51 |
# File 'lib/phil_columns/seed_utils.rb', line 48 def ( filepath ) matches = SEED_REGEX.match( filepath ) matches[1] end |
#each_seed_meta_for_current_env(&block) ⇒ Object
38 39 40 41 42 |
# File 'lib/phil_columns/seed_utils.rb', line 38 def ( &block ) seeds_for_current_env.each do || block.call( ) end end |
#load_seeds ⇒ Object
6 7 8 9 10 |
# File 'lib/phil_columns/seed_utils.rb', line 6 def load_seeds seed_filepaths.each do |seed_filepath| load seed_filepath end end |
#map_seeds ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/phil_columns/seed_utils.rb', line 12 def map_seeds seed_filepaths.map do |seed_filepath| klass = discover_seed_class( seed_filepath ) Hashie::Mash.new( envs: klass._envs, filepath: seed_filepath, klass: klass, name: File.basename( seed_filepath, '.rb' ), tags: klass., timestamp: ( seed_filepath )) end end |
#seed_already_executed?(version) ⇒ Boolean
59 60 61 |
# File 'lib/phil_columns/seed_utils.rb', line 59 def seed_already_executed?( version ) archivist.seed_already_executed?( version ) end |
#seed_filepaths ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/phil_columns/seed_utils.rb', line 25 def seed_filepaths seeds = Dir.glob( "#{seeds_path}/**/*.rb" ) if config.down seeds.sort { |a,b| b <=> a } else seeds.sort end end |
#seeds_for_current_env ⇒ Object
34 35 36 |
# File 'lib/phil_columns/seed_utils.rb', line 34 def seeds_for_current_env map_seeds.select { || .envs.include?( config.env ) } end |
#seeds_path ⇒ Object
44 45 46 |
# File 'lib/phil_columns/seed_utils.rb', line 44 def seeds_path config.seeds_path end |