properties-configuration 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/properties_configuration.rb +54 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: !binary |-
4
+ YjE2Y2YwM2EzODAxMmY1ZjE3MzczM2I2NTE3YzUzNTFjZWU1YWRhNA==
5
+ data.tar.gz: !binary |-
6
+ MDdlZTRhMWRmNzEyOWQ3NTU4Y2MwNGE3MzM3MDE4MjFmM2UzZDcxYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTJkOWJmNTA3MTAwN2YzMjdhYzNiMGJiOTY2NWE3MDEzYzhiNTgzNzVlNzM0
10
+ ZTFkYjI5ZWIxYmUxMTc2NWQ0YmFlNWNkMDFmODQxNmM0NWI2NzBmN2VkMzcy
11
+ MDg5YTY4YjhjYjk0N2ZjNWYxYzAzYzg3MWFjMDdkODIwYWVhOGQ=
12
+ data.tar.gz: !binary |-
13
+ YTJjOWQzNWQ5NjUwY2QxYmU0MDVmMGE4MTMzYWU0OTM1OTQzMTNjZWIyYTM5
14
+ ZjI4MzNlZmU1NmU5NDRkNmYyNGQ0YmZjZmIzMmM1NjNjN2Y4YjEzZTYwZDhi
15
+ ZjU2YWFmYjhhZjZmYWYzODA4ZjY0NmEyNjQ2MzcwNTUyNzI4MDU=
@@ -0,0 +1,54 @@
1
+ # Simple class that loads properties from a file to override a hash with default properties. This is a useful thing to have in any application.
2
+ # To use:
3
+ # config=PropertiesConfiguration::loadConfiguration({
4
+ # :my_property => 'value'
5
+ # },['/etc/localstream/localstream.properties'])
6
+ #
7
+ # puts config.my_property
8
+ #
9
+ module PropertiesConfiguration
10
+ def self.load_properties(properties_filename)
11
+ properties = {}
12
+ if File.exists?(properties_filename)
13
+ File.open(properties_filename, 'r') do | properties_file |
14
+ properties_file.read.each_line do |line|
15
+ line.strip!
16
+ if (line[0] != ?# and line[0] != ?=)
17
+ i = line.index('=')
18
+ if (i)
19
+ properties[line[0..i - 1].strip] = line[i + 1..-1].strip
20
+ else
21
+ properties[line] = ''
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ properties
28
+ end
29
+
30
+ def self.loadConfiguration(config={}, locations=[])
31
+ hash=config
32
+ if locations
33
+ locations.each do | location |
34
+ properties=load_properties(location)
35
+ hash=hash.merge(properties)
36
+ end
37
+ end
38
+ if java.lang.System
39
+ # only works in jruby
40
+ java.lang.System.getProperties.each do |k,v|
41
+ hash[k]=v
42
+ end
43
+ end
44
+
45
+ # create a new class and then return an instance of that class so that we can pretend our properties are actual fields
46
+ Class.new do
47
+ hash.each do |k,v|
48
+ define_method k do
49
+ return v.to_s
50
+ end
51
+ end
52
+ end.new
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: properties-configuration
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Jilles van Gurp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple solution that allows you to define properties in code and override them using properties files.
14
+ email: incoming@jillesvangurp.xom
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/properties_configuration.rb
20
+ homepage: https://github.com/jillesvangurp/properties-configuration-rb
21
+ licenses:
22
+ - Expat
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.3
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Solution for loading properties
44
+ test_files: []