Comments (5)
Now I re-read the code in #116 , I am perplexed. I am not confident that it actually does anything. outside of a minor formatting change, this is assigning state = Mash.new
only to be usually overwritten with a hash from JSON.parse
.
The mash structure is cool, but I am not sure it helps here. I think a simpler solution to this problem is to flatten the key .to_s
in the write method. How does that sound?
from taste-tester.
no, you silly man. That's what mashes do... they treat string and symbol keys as the same thing. That's literally the point of them, so it always collapses them and we only ever write out strings, and always ever read in strings without constantly converting manually.
from taste-tester.
I get that mashes handle keys differently. That's not the issue. The issue I'm raising is that simply assigning a new mash to state before trying to read a json file / falling back on an empty hash. The resulting data type of state is always a hash not a mash as you intended. Example:
$ irb
irb(main):001:0> require 'chef/mash'
=> true
irb(main):002:0> require 'json'
=> true
irb(main):003:0> m = Mash.new
=> {}
irb(main):004:0> m.class
=> Mash
irb(main):005:0> m = JSON.parse(File.read('/data/users/malmond/.taste-tester/prod/ref.json'))
=> {"port"=>5093, "ssl"=>true, "ssh"=>false, "logging"=>true, "bundle"=>"compatible", "ref"=>"bb50da1a52bd0e9e1ab1d03649ed27690445e092", "last_upload_time"=>"2019-08-15 10:24:41"}
irb(main):006:0> m.class
=> Hash
irb(main):007:0> m = {}
=> {}
irb(main):008:0> m.class
=> Hash
I don't think the code in #116 actually does anything. If anything, the solution here is even simpler:
def write(key, val)
- merge({ key => val })
+ merge({ key.to_s => val })
end
This flattens all keys to strings, all the time.
from taste-tester.
Of course it's JSON... but it collapses all the keys. Every time. That's the point of mashes. What's written out is JSON, it's read into a mash, the keys merge properly. You CANNOT find a case with the current code where you'll get a :state
and a "state"
key, I'll bet money on it.
from taste-tester.
irb(main):002:0> m = Mash.new
=> {}
irb(main):003:0> m[:stuff] = 'bar'
=> "bar"
irb(main):004:0> m.merge!(JSON.parse('{"stuff": "wonk"}'))
=> {"stuff"=>"wonk"}
This is the whole reason that Chef wrote Mash. Let Mash do that for you so you're not doing it yourself.
from taste-tester.
Related Issues (20)
- When running master, cyclic include detected is thrown HOT 1
- `-v` should pass `-V` to knife... or something HOT 1
- Use newer minitar to support longer symlinks HOT 1
- combine tunnel.rb ssh_util.rb and ssh.rb
- Drop undocumented awk dependency
- --skip-repo-checks does not, in fact, skip repo checks. :( HOT 1
- taste-tester logging crash: undefined local variable or method 'logger' for #<TasteTester::State> HOT 1
- taste-tester prints ssh banner to stdout HOT 2
- Consider using "this repo" as the repo directory
- taste-tester logging crash: undefined local variable or method 'logger' for #<TasteTester::State> #156 HOT 3
- taste-tester needs an option for customizing errors when ssh fails HOT 9
- taste-tester ssh_generator code doesn't handle tunnel extra_options HOT 2
- Reword the spec tests better
- databags uploaded incorrectly in bundle mode
- tt assumes all machines are in the same timezone HOT 2
- tt should try to keep the same port on restart
- verification of chef_zero_path breaks using with RVM HOT 1
- taste-tester-ref.json overrides command line port configuration HOT 1
- Plugin Example HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taste-tester.