prop2redis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ vagrantbox
2
+ vendor
3
+ *.pid
4
+ pkg
5
+ .idea
6
+ *.gem
7
+ config.properties
8
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prop2redis.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 mshea
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Prop2redis
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'prop2redis'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install prop2redis
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/prop2redis ADDED
@@ -0,0 +1,3 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'prop2redis', 'prop2redis')
2
+
3
+ Prop2Redis::RedisLoader.main
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ require 'uri'
3
+ require 'cgi'
4
+ require 'redis'
5
+
6
+ module Prop2Redis
7
+ class RedisLoader
8
+ # http://www.dzone.com/snippets/load-properties-properties
9
+ def self.load_properties(properties_filename)
10
+ properties = {}
11
+ File.open(properties_filename, 'r') do |properties_file|
12
+ properties_file.read.each_line do |line|
13
+ line.strip!
14
+ if (line[0] != ?# and line[0] != ?=)
15
+ i = line.index('=')
16
+ if (i)
17
+ properties[line[0..i - 1].strip] = line[i + 1..-1].strip
18
+ else
19
+ properties[line] = ''
20
+ end
21
+ end
22
+ end
23
+ end
24
+ properties
25
+ end
26
+
27
+ def self.main
28
+ abort "Usage: prop2redis <propertyfile>" if ARGV.length != 1
29
+
30
+ property_file = ARGV[0]
31
+ abort "Property file must exist." if !File.exist?(property_file)
32
+ abort "Property file must be a file." if !File.file?(property_file)
33
+
34
+ redis_url = ENV['REDIS_URL']
35
+ abort "REDIS_URL environment variable must be set" if redis_url.nil?
36
+
37
+ URI uri = URI(redis_url)
38
+ abort "REDIS_URL must have scheme 'redis'." if uri.scheme != 'redis'
39
+ abort "REDIS_URL must have a namespace query parameter." if ( uri.query.nil? )
40
+
41
+ query = uri.query
42
+ query_hash = CGI::parse(query)
43
+ abort "REDIS_URL must have a namespace query parameter." if (query_hash['namespace'].nil?)
44
+ namespace=query_hash['namespace']
45
+
46
+ abort "REDIS_URL must have a path." if uri.path.nil?
47
+
48
+ hash = load_properties(property_file)
49
+ db = uri.path
50
+ host = uri.host
51
+ port = uri.port.nil? ? 6379 : uri.port
52
+ db = uri.path
53
+ redis = Redis.new(:host=>host, :port=>port, :db=>db)
54
+ redis.multi do
55
+ hash.each do |key, value|
56
+ redis.hset namespace, key, value
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,3 @@
1
+ module Prop2redis
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prop2redis/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "prop2redis"
8
+ gem.version = Prop2redis::VERSION
9
+ gem.authors = ["mshea"]
10
+ gem.email = ["mshea@rypple.com"]
11
+ gem.description = "Converts .properties files into redenv"
12
+ gem.summary = "Converts .properties files into redenv"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('redis')
21
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prop2redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mshea
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Converts .properties files into redenv
31
+ email:
32
+ - mshea@rypple.com
33
+ executables:
34
+ - prop2redis
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/prop2redis
44
+ - lib/prop2redis/prop2redis.rb
45
+ - lib/prop2redis/version.rb
46
+ - prop2redis.gemspec
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Converts .properties files into redenv
71
+ test_files: []