fake_elasticache 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2be4ba62ac7e70b8776ed43d6498bc234f3249c
4
+ data.tar.gz: 2c4edad469bb41b176a5dc1fedab17d98641a6f6
5
+ SHA512:
6
+ metadata.gz: 234f940db238e024c9cb5605aff41ab732aede4af40ee7c28cc206643598144f98df1d0c9e87ad4c28230fc2e8cbf0619f86e752b3c4c4ff088f063899daa46e
7
+ data.tar.gz: 73cd489aaa00ef49c0abc8f9a53923a3291d5a705bd3afa35ee4ab6ca1711788358f038f8e32ceb8b385829683b4edffee231ba33d6550fb890a3454c4762764
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fake_elasticache.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Steven Jack
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
+ # FakeElasticache
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fake_elasticache'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fake_elasticache
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/fake_elasticache/fork )
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"
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pathname"
4
+
5
+ root = Pathname.new(__FILE__).dirname.parent
6
+ lib_path = (root + "lib").realdirpath
7
+ $LOAD_PATH.unshift(lib_path)
8
+
9
+ require "fake_elasticache"
10
+
11
+ FakeElasticache.run!
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fake_elasticache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fake_elasticache"
8
+ spec.version = FakeElasticache::VERSION
9
+ spec.authors = ["Steven Jack"]
10
+ spec.email = ["stevenmajack@gmail.com"]
11
+ spec.summary = %q{Creates an endpoint that mimics an elasticache cluster}
12
+ spec.description = %q{This gem is best suited to dev environments where you need to connect to a local memcached server but using the elasticache config endpoint.}
13
+ spec.homepage = "https://www.github.com/stevenjack/fake_elasticache"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,24 @@
1
+ module FakeElasticache
2
+ module Options
3
+ module Docker
4
+
5
+ def parse
6
+ options = {
7
+ :port => ENV.fetch('FAKEELASTICACHE_PORT', '11212'),
8
+ :bind => ENV.fetch('FAKEELASTICACHE_BIND','127.0.0.1'),
9
+ :servers => [],
10
+ :version => ENV.fetch('MEMCACHED_VERSION', '2.4.14')
11
+ }
12
+
13
+ ENV.keys.select { |key| key.to_s.match(/^MEMCACHED[0-9]*_PORT/) }.each do |linked_container|
14
+ id = linked_container[/\d+/,0]
15
+ memcached_server = ENV[linked_container].nil? ? ['127.0.0.1', '11211'] : ENV[linked_container].sub("tcp://", "").split(':')
16
+ options[:servers] << "#{ENV.fetch("DNS#{id}_NAME", 'localhost')}|#{memcached_server[0]}|#{memcached_server[1]}"
17
+ end
18
+ options
19
+ end
20
+
21
+ module_function :parse
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ require "optparse"
2
+
3
+ module FakeElasticache
4
+ module Options
5
+
6
+ def parse
7
+
8
+ options = {
9
+ :port => 11212,
10
+ :bind => '127.0.0.1',
11
+ :servers => ['localhost|127.0.0.1|11211'],
12
+ :version => ENV.fetch('MEMCACHED_VERSION', '2.4.14')
13
+ }
14
+
15
+ OptionParser.new do |opts|
16
+ opts.banner = "Usage: fake_elasticache [options]"
17
+
18
+ opts.on("-p", "--port PORT", "Default: #{options[:port]}") do |v|
19
+ options[:port] = v
20
+ end
21
+
22
+ opts.on("-b", "--bind ADDR", "Default: #{options[:bind]}") do |v|
23
+ options[:bind] = v
24
+ end
25
+
26
+ opts.on("-s", "--servers SERVERS", "Default: #{options[:servers]}") do |v|
27
+ options[:db] = v
28
+ end
29
+
30
+ end.parse!
31
+ options
32
+ end
33
+
34
+ module_function :parse
35
+
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ require 'eventmachine'
2
+
3
+ module FakeElasticache
4
+
5
+ class Server < EventMachine::Connection
6
+ attr_reader :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ super
11
+ end
12
+
13
+ def receive_data data
14
+ if data =~ /stats/i
15
+ send_data "STAT version #{options[:version]}\nEND\n"
16
+ elsif data =~ /config get cluster|get AmazonElastiCache:cluster/i
17
+ send_data config_output
18
+ elsif data =~ /quit/i
19
+ close_connection
20
+ else
21
+ send_data "Command: #{data} is unexpected\n"
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def config_output
28
+ config_string = options[:servers].join(" ")
29
+ "CONFIG cluster 0 #{config_string.length}\n1\n#{config_string}\n\nEND\n"
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module FakeElasticache
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require "fake_elasticache/version"
2
+ require "fake_elasticache/options"
3
+ require "fake_elasticache/options/docker"
4
+ require "fake_elasticache/server"
5
+ require "eventmachine"
6
+
7
+ module FakeElasticache
8
+
9
+ def self.run!
10
+ EventMachine.run {
11
+ EventMachine.start_server options[:bind], options[:port], FakeElasticache::Server, options
12
+ }
13
+ end
14
+
15
+ private
16
+
17
+ def self.options
18
+ @@options ||= ENV['CONTAINER'].nil? ? FakeElasticache::Options.parse : FakeElasticache::Options::Docker.parse
19
+ end
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake_elasticache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Jack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem is best suited to dev environments where you need to connect
42
+ to a local memcached server but using the elasticache config endpoint.
43
+ email:
44
+ - stevenmajack@gmail.com
45
+ executables:
46
+ - fake_elasticache
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/fake_elasticache
56
+ - fake_elasticache.gemspec
57
+ - lib/fake_elasticache.rb
58
+ - lib/fake_elasticache/options.rb
59
+ - lib/fake_elasticache/options/docker.rb
60
+ - lib/fake_elasticache/server.rb
61
+ - lib/fake_elasticache/version.rb
62
+ homepage: https://www.github.com/stevenjack/fake_elasticache
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Creates an endpoint that mimics an elasticache cluster
86
+ test_files: []