ruby on rails - Is there a way to alias/anchor an array in YAML? -


i'm using jammit package assets rails application , have few asset files i'd included in each of few groups. example, i'd sammy , plugins in both mobile , screen js packages.

i've tried this:

sammy: &sammy   - public/javascripts/vendor/sammy.js   - public/javascripts/vendor/sammy*.js  mobile:   <<: *sammy   - public/javascripts/something_else.js 

and this:

mobile:   - *sammy 

but both put sammy js files in nested array, jammit can't understand. there syntax including elements of array directly in array?

nb: realize in case there 2 elements in sammy array, wouldn't bad give each alias , reference both in each package. that's fine case, gets unmaintainable when there 5 or ten elements have specific load order.

your example valid yaml (a convenient place check ypaste), it's not defined merge does. per spec, merge key can have value:

  1. a mapping, in case it's merged parent mapping.
  2. a sequence of mappings, in case each merged, one-by-one, parent mapping.

there's no way of merging sequences. can, however, in code. using yaml second idea:

mobile:   - *sammy 

you'll nested sequences - flatten them! assuming have mapping of such nested sequences:

data = yaml::load(file.open('test.yaml')) data.each_pair { |key, value| value.flatten! } 

(of course, if have more complicated yaml file, , don't want every sequence flattened (or they're not sequences), you'll have filtering.)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -