rangeclient 0.0.1

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 (4) hide show
  1. data/LICENSE.md +13 -0
  2. data/README.md +17 -0
  3. data/lib/rangeclient.rb +41 -0
  4. metadata +83 -0
@@ -0,0 +1,13 @@
1
+ Copyright 2011 Square Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,17 @@
1
+ rangeclient synopsis
2
+ ============================
3
+
4
+
5
+ rangehost = ARGV.shift
6
+ rangearg = ARGV.shift
7
+
8
+ # Create range object for communication with ranged
9
+ r = Range::Client.new({:host => rangehost})
10
+
11
+ # use ranged to expand the range expression into an Array
12
+ # "foo10..12" => [ foo10, foo11, foo12 ] OR %foo => [ foo10, foo11, foo12 ]
13
+ hosts = r.expand(rangearg)
14
+
15
+ # use ranged to compress the array of hostnames into a range expression
16
+ # [ foo10, foo11, foo12 ] => "foo10..12"
17
+ range_exp = r.compress(hosts)
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'rest_client'
5
+ require 'cgi'
6
+
7
+ class Range::Client
8
+
9
+ def initialize(options = {})
10
+ default_host = 'range'
11
+ default_host = ENV['RANGE_HOST'] if ENV.has_key?('RANGE_HOST')
12
+ default_port = '80'
13
+ default_port = ENV['RANGE_PORT'] if ENV.has_key?('RANGE_PORT')
14
+ @options = {
15
+ :host => default_host,
16
+ :port => default_port,
17
+ }.merge(options)
18
+ end
19
+
20
+ def expand(arg)
21
+ escaped_arg = CGI.escape arg
22
+ puts "http://#@options[:host]}:#{@options[:port]}/range/list?#{escaped_arg}"
23
+ res = RestClient.get "http://#{@options[:host]}:#{@options[:port]}/range/list?#{escaped_arg}"
24
+ return res.split "\n"
25
+ end
26
+
27
+ def compress(names)
28
+ escaped_arg = CGI.escape names.join ","
29
+ return RestClient.get "http://#{@options[:host]}:#{@options[:port]}/range/expand?#{escaped_arg}"
30
+ end
31
+ end
32
+
33
+ if __FILE__ == $0
34
+ require 'pp'
35
+ rangehost = ARGV.shift
36
+ rangearg = ARGV.shift
37
+ r = Range::Client.new({:host => rangehost})
38
+ hosts = r.expand(rangearg)
39
+ pp hosts
40
+ pp r.compress(hosts)
41
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rangeclient
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Evan Miller
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Use with ranged from https://github.com/ytoolshed/range
35
+ email:
36
+ - evan@squareup.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE.md
43
+ files:
44
+ - lib/rangeclient.rb
45
+ - README.md
46
+ - LICENSE.md
47
+ homepage: https://github.com/square/prodeng/tree/master/ruby_rangeclient
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 23
70
+ segments:
71
+ - 1
72
+ - 3
73
+ - 6
74
+ version: 1.3.6
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.24
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Simple ranged client for ruby.
82
+ test_files: []
83
+