mbklein/dot-properties


Read and write Java-style .properties files with minimal intrusiveness

License: Other

Language: Ruby


DotProperties Build Status

Reads and writes Java .properties files like a champ.

  • Intuitive, Hash-like access. Anywhere it makes sense to act like a Hash, it acts like a Hash.
  • Won't clobber comments and blank lines (unless you want to).
  • Will preserve original delimiters for each value (unless you normalize them).
  • Supports all the delimiters (whitespace, =, :).
  • Supports both comment prefixes (#, !).
  • Supports expansion of inline ${property} references.

Installation

Add this line to your application's Gemfile:

gem 'dot-properties'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dot_properties

Usage

require 'dot_properties'

# Load a .properties file
props = DotProperties.load('sample.properties')

# Get a value
props['foo']

# Set a value
props['foo'] = 'bar'

# Convert key/value pairs to a hash
props.to_h

# Or just let it act like a hash 
props.each_pair { |key,value| puts "#{key} :: #{value}" }

# Remove all comments/blanks/both
props.strip_comments!
props.strip_blanks!
props.compact!

# Write a .properties file
File.open('output.properties','w') { |out| out.write(props.to_s) }

See the spec tests and fixture data for more examples.

Known Issues

  • Multiline values will be converted to single line on output

History

  • 0.1.3 - Explicitly require 'forwardable' (jruby / mri2.x compat) (from @billdueber)
  • 0.1.2 - Improved escaping and Unicode (\uXXXX) support
  • 0.1.1 - Fix mishandled keys with leading whitespace (#1)
  • 0.1.0 - Initial release

Copyright

Copyright (c) 2013 Michael B. Klein. See LICENSE.txt for further details.

Project Statistics

Sourcerank 6
Repository Size 11.7 KB
Stars 4
Forks 1
Watchers 1
Open issues 3
Dependencies 5
Contributors 3
Tags 4
Created
Last updated
Last pushed

Top Contributors See all

Michael B. Klein Stephan Kämper Bill Dueber

Packages Referencing this Repo

dot-properties
Java-style .properties file manipulation with a light touch
Latest release 0.1.3 - Updated - 4 stars

Recent Tags See all

v0.1.3 June 19, 2014
v0.1.2 December 02, 2013
v0.1.1 December 02, 2013
v0.1.0 November 27, 2013

Something wrong with this page? Make a suggestion

Last synced: 2019-11-10 04:12:45 UTC

Login to resync this repository