Class: Simp::Rake::Fixtures
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Simp::Rake::Fixtures
- Defined in:
- lib/simp/rake/fixtures.rb
Instance Method Summary collapse
- #define ⇒ Object
-
#initialize(dir) ⇒ Fixtures
constructor
A new instance of Fixtures.
Constructor Details
#initialize(dir) ⇒ Fixtures
Returns a new instance of Fixtures.
6 7 8 9 10 |
# File 'lib/simp/rake/fixtures.rb', line 6 def initialize( dir ) @base_dir = dir ###::CLEAN.include( '.fixtures.yml.local' ) define end |
Instance Method Details
#define ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/simp/rake/fixtures.rb', line 12 def define namespace :fixtures do def flatten_fixtures_hash(_f) _f .map{|k,v| v.values} .flatten .reduce({}){|h,pairs| pairs.each{|k,v| (h[k] ||= []) << v }; h } .keys .uniq .sort end def fixtures_yml_local(_f) _f_m = flatten_fixtures_hash(_f) _s = Hash[_f_m.map{|k| v= _f['fixtures']['repositories'].key?(k) ? "#\{source_dir\}/../#{k}": _f['fixtures']['symlinks'].fetch(k) [k, v ]} ] {'fixtures'=> {'symlinks'=> _s }} end desc 'generate .fixtures.yml.local formm the entries in .fixtures.yml' task :generate do pwd = File.(@base_dir) _f = YAML.load_file(File.join(pwd,'.fixtures.yml')) _l = clean_yaml(fixtures_yml_local( _f ).to_yaml) _o = File.join(pwd,'.fixtures.yml.local') File.open( _o,'w'){|f| puts _l; f.puts _l} puts puts "# written to '#{_o}'" end desc "check for missing .fixture modules" task :diff do require 'yaml' pwd = File.(@base_dir) _f = YAML.load_file(File.join(pwd,'.fixtures.yml')) unless File.file?(File.join(pwd,'.fixtures.yml.local')) fail "ERROR: Can't diff fixtures without a `.fixtures.yml.local` file" end _fl = YAML.load_file(File.join(pwd,'.fixtures.yml.local')) # reduce modules _f_m = flatten_fixtures_hash(_f) _fl_m = flatten_fixtures_hash(_fl) _f_u = (_f_m-_fl_m) _fl_u = (_fl_m-_f_m) if (_f_u.size + _fl_u.size) > 0 warn '' warn "WARNING: .fixtures.yml & .fixtures.yml.local have different files!" warn '' if _f_u.size > 0 warn 'Unique modules to .fixtures.yml:' _f_u.each{|x| warn " - #{x}"} warn '' end if _fl_u.size > 0 warn 'Unique modules to .fixtures.yml.local:' _fl_u.each{|x| warn " - #{x}"} warn '' end exit 1 end end end end |