Documentation for Psych to_yaml options?
Deep in the guts of ruby-1.9.3-p125/ext/psych/emitter.c
I found three options:
indentation
- The level must be less than 10 and greater than 1.line_width
- Set the preferred line width.canonical
- Set the output style to canonical, or not (true/false).
And they work!
why does psych yaml interpreter add line breaks around 80 characters?
You'll have to configure psych’s #to_yaml options. You'll most likely find it here:
ruby-1.9.3-p125/ext/psych/emitter.c
And then you can do something like this:
yaml.to_yaml(options = {:line_width => -1})
Inconsistent wrapping of quotes in to_yaml
- Column 1, section 2, text contains a trailing space.
- Column 2, section 8, text contains a
:
character followed by a space.
The specification says:
The plain (unquoted) style has no identifying indicators and provides no form of escaping. It is therefore the most readable, most limited and most context sensitive style. In addition to a restricted character set, a plain scalar must not be empty, or contain leading or trailing white space characters. It is only possible to break a long plain line where a space character is surrounded by non-spaces.
...
Plain scalars must never contain the “: ” and “ #” character combinations. Such combinations would cause ambiguity with mapping key: value pairs and comments. In addition, inside flow collections, or when used as implicit keys, plain scalars must not contain the “[”, “]”, “{”, “}” and “,” characters. These characters would cause ambiguity with flow collection structures.
Is it possible to specify formatting options for to_yaml in ruby?
This ugly hack seems to do the trick...
class Array
def to_yaml_style
:inline
end
end
Browsing through ruby's source, I can't find any options I could pass to achieve the same. Default options are described in the lib/yaml/constants.rb.
Is there a way to tell Psych in ruby to using inline mode?
Psych supports this, although it isn't at all straightforward.
I've started researching this in my own question on how to dump strings using literal style.
I ended up devising a complete solution for setting various styles for specific objects, including inlining hashes and arrays.
With my script, a solution to your problem would be:
o = { 'hash' => StyledYAML.inline('name' => 'Steve', 'foo' => 'bar') }
StyledYAML.dump o, $stdout
Related Topics
Configure Webrick to Use Automatically Generated Self-Signed Ssl/Https Certificate
Ruby on Rails: How to Use Oauth2::Accesstoken.Post
Kill Process and Sub-Processes in Ruby on Windows
Displaying a Polygon with Gmaps4Rails
Ruby on Rails Add a Column After a Specific Column Name
How to Use the Fetch Method for Nested Hash
Rails Script Segmentation Fault with Rvm
How to Create a Charge and a Customer in Stripe (Rails)
How to Do "Late" String Interpolation in Ruby
How to Add "Somewhere" a 'Before(:Each)' Hook So That All Spec File Can Run It
How to Integrate 'Premailer' with Rails
Rails How to Change Attribute Name When Rendering JSON
Zentest Autotest Not Running Tests
Ruby on Rails Activerecord Scopes VS Class Methods
How to Get the Destination Url of a Shortened Url Using Ruby