0.01
Low commit activity in last 3 years
No release in over a year
Java-style .properties file manipulation with a light touch
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 2.4.2
>= 0

Runtime

>= 2.2.33
 Project Readme

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.4 - Update bundler dependency due to CVE-2019-3881 (from @s2k)
  • 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.