diff --git a/.travis.yml b/.travis.yml index 5a8fbde..b155f82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,15 @@ -language: ruby +language: ruby script: ./utils/run-tests.sh -install: sudo gem install rspec +install: sudo gem install rspec rvm: - 1.8.6 - 1.8.7 - 1.9.2 - 1.9.3 + - 2.0 - jruby-18mode - jruby-19mode + - jruby-20mode - ruby-head - jruby-head - ree diff --git a/LICENSE b/LICENSE index f34f6f5..60054d1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License: -Copyright (c) 2006-2012 BJ Dierkes +Copyright (c) 2006-2013 Data Folk Labs, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8c24b59..792ec49 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Ruby ParseConfig Library ParseConfig provides simple parsing of standard configuration files in the form of 'param = value'. It also supports nested [group] sections. -[![Continuous Integration Status](https://secure.travis-ci.org/derks/ruby-parseconfig.png)](http://travis-ci.org/derks/ruby-parseconfig) +[![Continuous Integration Status](https://secure.travis-ci.org/datafolklabs/ruby-parseconfig.png)](http://travis-ci.org/datafolklabs/ruby-parseconfig) Installation ------------ diff --git a/lib/parseconfig.rb b/lib/parseconfig.rb index 36af531..93d03ef 100644 --- a/lib/parseconfig.rb +++ b/lib/parseconfig.rb @@ -1,24 +1,24 @@ -# -# Author:: BJ Dierkes +# +# Author:: BJ Dierkes # Copyright:: Copyright (c) 2006,2012 BJ Dierkes -# License:: MIT +# License:: MIT # URL:: https://github.com/derks/ruby-parseconfig -# +# # This class was written to simplify the parsing of configuration -# files in the format of "param = value". Please review the +# files in the format of "param = value". Please review the # demo files included with this package. # # For further information please refer to the './doc' directory # as well as the ChangeLog and README files included. # -# Note: A group is a set of parameters defined for a subpart of a +# Note: A group is a set of parameters defined for a subpart of a # config file class ParseConfig - - Version = '1.0.2' + + Version = '1.0.3' attr_accessor :config_file, :params, :groups @@ -32,37 +32,41 @@ def initialize(config_file=nil) @config_file = config_file @params = {} @groups = [] - + if(self.config_file) self.validate_config() self.import_config() end end - + # Validate the config file, and contents - def validate_config() + def validate_config() unless File.readable?(self.config_file) - raise Errno::EACCES, "#{self.config_file} is not readable" + raise Errno::EACCES, "#{self.config_file} is not readable" end - + # FIX ME: need to validate contents/structure? - end - + end + # Import data from the config to our config object. def import_config() # The config is top down.. anything after a [group] gets added as part - # of that group until a new [group] is found. + # of that group until a new [group] is found. group = nil open(self.config_file) { |f| f.each_with_index do |line, i| line.strip! - if i.eql? 0 and line.include?("\xef\xbb\xbf".force_encoding("UTF-8")) - line.delete!("\xef\xbb\xbf".force_encoding("UTF-8")) + # force_encoding not available in all versions of ruby + begin + if i.eql? 0 and line.include?("\xef\xbb\xbf".force_encoding("UTF-8")) + line.delete!("\xef\xbb\xbf".force_encoding("UTF-8")) + end + rescue NoMethodError end unless (/^\#/.match(line)) if(/\s*=\s*/.match(line)) - param, value = line.split(/\s*=\s*/, 2) + param, value = line.split(/\s*=\s*/, 2) var_name = "#{param}".chomp.strip value = value.chomp.strip new_value = '' @@ -74,26 +78,26 @@ def import_config() end else new_value = '' - end + end if group self.add_to_group(group, var_name, new_value) else self.add(var_name, new_value) end - + elsif(/^\[(.+)\]$/.match(line).to_a != []) group = /^\[(.+)\]$/.match(line).to_a[1] self.add(group, {}) - + end end end } end # This method will provide the value held by the object "@param" - # where "@param" is actually the name of the param in the config - # file. + # where "@param" is actually the name of the param in the config + # file. # # DEPRECATED - will be removed in future versions # @@ -112,7 +116,7 @@ def [](param) def get_params() return self.params.keys end - + # List available sub-groups of the config. def get_groups() return self.groups @@ -152,7 +156,7 @@ def add_to_group(group, param_name, value) # Writes out the config file to output_stream def write(output_stream=STDOUT) - self.params.each do |name,value| + self.params.each do |name,value| if value.class.to_s != 'Hash' if value.scan(/\w+/).length > 1 output_stream.puts "#{name} = \"#{value}\"" @@ -162,10 +166,10 @@ def write(output_stream=STDOUT) end end output_stream.puts "\n" - + self.groups.each do |group| output_stream.puts "[#{group}]" - self.params[group].each do |param, value| + self.params[group].each do |param, value| if value.scan(/\w+/).length > 1 output_stream.puts "#{param} = \"#{value}\"" else diff --git a/utils/parseconfig.gemspec b/utils/parseconfig.gemspec index 6ef69e7..391ce9e 100644 --- a/utils/parseconfig.gemspec +++ b/utils/parseconfig.gemspec @@ -1,17 +1,17 @@ Gem::Specification.new do |s| s.name = %q{parseconfig} - s.version = "1.0.2" - s.date = %q{2012-06-12} + s.version = "1.0.3" + s.date = %q{2013-12-19} s.authors = ["BJ Dierkes"] - s.email = %q{derks@bjdierkes.com} + s.email = %q{derks@datafolklabs.com} s.summary = %q{Config File Parser for Standard Unix/Linux Type Config Files} - s.homepage = %q{http://github.com/derks/ruby-parseconfig/} + s.homepage = %q{http://github.com/datafolklabs/ruby-parseconfig/} s.description = %q{ParseConfig provides simple parsing of standard configuration files in the form of 'param = value'. It also supports nested [group] sections.} - s.files = [ "README.md", - "Changelog", - "LICENSE", + s.files = [ "README.md", + "Changelog", + "LICENSE", "doc", "lib/parseconfig.rb", "tests"] - + end