magellan-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/Gemfile +7 -0
  4. data/Gemfile.lock +76 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +29 -0
  7. data/Rakefile +7 -0
  8. data/bin/magellan-rails +7 -0
  9. data/gems/magellan-publisher/.gitignore +37 -0
  10. data/gems/magellan-publisher/Gemfile +11 -0
  11. data/gems/magellan-publisher/Gemfile.lock +51 -0
  12. data/gems/magellan-publisher/LICENSE.txt +22 -0
  13. data/gems/magellan-publisher/README.md +29 -0
  14. data/gems/magellan-publisher/Rakefile +14 -0
  15. data/gems/magellan-publisher/lib/magellan/publisher/version.rb +5 -0
  16. data/gems/magellan-publisher/lib/magellan/publisher.rb +37 -0
  17. data/gems/magellan-publisher/magellan-publisher.gemspec +27 -0
  18. data/gems/magellan-publisher/spec/magellan/publisher_spec.rb +39 -0
  19. data/gems/magellan-publisher/spec/spec_helper.rb +8 -0
  20. data/lib/generators/install_generator.rb +20 -0
  21. data/lib/generators/templates/Magellan.yml +115 -0
  22. data/lib/magellan/extentions/rails/engine.rb +28 -0
  23. data/lib/magellan/extentions/rails.rb +2 -0
  24. data/lib/magellan/extentions.rb +2 -0
  25. data/lib/magellan/rails/executor.rb +35 -0
  26. data/lib/magellan/rails/railtie.rb +12 -0
  27. data/lib/magellan/rails/request.rb +111 -0
  28. data/lib/magellan/rails/response.rb +35 -0
  29. data/lib/magellan/rails/version.rb +5 -0
  30. data/lib/magellan/rails.rb +10 -0
  31. data/lib/magellan/subscriber/base.rb +26 -0
  32. data/lib/magellan/subscriber/executor.rb +21 -0
  33. data/lib/magellan/subscriber/mapper.rb +105 -0
  34. data/lib/magellan/subscriber/request.rb +25 -0
  35. data/lib/magellan/subscriber/rspec.rb +7 -0
  36. data/lib/magellan/subscriber/testing/integration.rb +22 -0
  37. data/lib/magellan/subscriber.rb +10 -0
  38. data/lib/magellan/worker/config.rb +33 -0
  39. data/lib/magellan/worker/core.rb +70 -0
  40. data/lib/magellan/worker/executor.rb +38 -0
  41. data/lib/magellan/worker.rb +14 -0
  42. data/lib/magellan.rb +28 -0
  43. data/magellan-rails.gemspec +28 -0
  44. data/spec/magellan/rails/request_spec.rb +103 -0
  45. data/spec/magellan/rails/response_spec.rb +58 -0
  46. data/spec/magellan/subscriber/mapper_spec.rb +264 -0
  47. data/spec/magellan/worker/core_spec.rb +70 -0
  48. data/spec/spec_helper.rb +4 -0
  49. metadata +167 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7796c0cc393d2e17a56de656c8022d29ec771b86
4
+ data.tar.gz: 1554fbf277c4c14f4e40cbc1f4ba596085ecb01d
5
+ SHA512:
6
+ metadata.gz: c2fdc42264aedba9574209ec711f36318ace206e48e8c9e0a78d918493f54079ebf0828c1390fffc19a6b5446d63d24ab86d5a7c19cb251ba195c4e86803bec1
7
+ data.tar.gz: bcf0fe036e69f5894306d802c50cdcc22c60791bfa961f3fddb4ef78ee638c23d0b7ae22a503162fed28c02a73aafc5dfc673277acb953b9c62f7fd15a21db4f
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /log
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+ vendor/bundle
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "bunny_mock", :git => 'git://github.com/groovenauts/bunny-mock.git',
4
+ :branch => "features/minimum_necessary_mock"
5
+
6
+ # Specify your gem's dependencies in magellan-rails.gemspec
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ GIT
2
+ remote: git://github.com/groovenauts/bunny-mock.git
3
+ revision: fbc775600d1e68b4bd3a521ca762ba79f3571704
4
+ branch: features/minimum_necessary_mock
5
+ specs:
6
+ bunny_mock (0.0.1)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ magellan-rails (0.0.1)
12
+ bunny
13
+ json
14
+ railties (~> 4.1.0)
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ actionpack (4.1.4)
20
+ actionview (= 4.1.4)
21
+ activesupport (= 4.1.4)
22
+ rack (~> 1.5.2)
23
+ rack-test (~> 0.6.2)
24
+ actionview (4.1.4)
25
+ activesupport (= 4.1.4)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ activesupport (4.1.4)
29
+ i18n (~> 0.6, >= 0.6.9)
30
+ json (~> 1.7, >= 1.7.7)
31
+ minitest (~> 5.1)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 1.1)
34
+ amq-protocol (1.9.2)
35
+ builder (3.2.2)
36
+ bunny (1.4.0)
37
+ amq-protocol (>= 1.9.2)
38
+ diff-lcs (1.2.5)
39
+ erubis (2.7.0)
40
+ i18n (0.6.11)
41
+ json (1.8.1)
42
+ minitest (5.4.0)
43
+ rack (1.5.2)
44
+ rack-test (0.6.2)
45
+ rack (>= 1.0)
46
+ railties (4.1.4)
47
+ actionpack (= 4.1.4)
48
+ activesupport (= 4.1.4)
49
+ rake (>= 0.8.7)
50
+ thor (>= 0.18.1, < 2.0)
51
+ rake (10.3.2)
52
+ rspec (3.0.0)
53
+ rspec-core (~> 3.0.0)
54
+ rspec-expectations (~> 3.0.0)
55
+ rspec-mocks (~> 3.0.0)
56
+ rspec-core (3.0.3)
57
+ rspec-support (~> 3.0.0)
58
+ rspec-expectations (3.0.3)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.0.0)
61
+ rspec-mocks (3.0.3)
62
+ rspec-support (~> 3.0.0)
63
+ rspec-support (3.0.3)
64
+ thor (0.19.1)
65
+ thread_safe (0.3.4)
66
+ tzinfo (1.2.2)
67
+ thread_safe (~> 0.1)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ bundler (~> 1.6)
74
+ bunny_mock!
75
+ magellan-rails!
76
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuuki Noguchi
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
+ # Magellan::Rails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'magellan-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install magellan-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/magellan-rails/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 a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
4
+ require 'magellan/worker'
5
+
6
+ Magellan::Worker.worker.initialize!
7
+ Magellan::Worker.worker.run
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /log
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+ vendor/bundle
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "bunny_mock", :git => 'git://github.com/groovenauts/bunny-mock.git',
4
+ :branch => "features/minimum_necessary_mock"
5
+
6
+ # Specify your gem's dependencies in magellan-publisher.gemspec
7
+ gemspec
8
+
9
+ group :test do
10
+ gem "simplecov"
11
+ end
@@ -0,0 +1,51 @@
1
+ GIT
2
+ remote: git://github.com/groovenauts/bunny-mock.git
3
+ revision: fbc775600d1e68b4bd3a521ca762ba79f3571704
4
+ branch: features/minimum_necessary_mock
5
+ specs:
6
+ bunny_mock (0.0.1)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ magellan-publisher (0.0.1)
12
+ bunny
13
+ json
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ amq-protocol (1.9.2)
19
+ bunny (1.4.1)
20
+ amq-protocol (>= 1.9.2)
21
+ diff-lcs (1.2.5)
22
+ docile (1.1.5)
23
+ json (1.8.1)
24
+ multi_json (1.10.1)
25
+ rspec (3.1.0)
26
+ rspec-core (~> 3.1.0)
27
+ rspec-expectations (~> 3.1.0)
28
+ rspec-mocks (~> 3.1.0)
29
+ rspec-core (3.1.6)
30
+ rspec-support (~> 3.1.0)
31
+ rspec-expectations (3.1.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.1.0)
34
+ rspec-mocks (3.1.3)
35
+ rspec-support (~> 3.1.0)
36
+ rspec-support (3.1.2)
37
+ simplecov (0.9.1)
38
+ docile (~> 1.1.0)
39
+ multi_json (~> 1.0)
40
+ simplecov-html (~> 0.8.0)
41
+ simplecov-html (0.8.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.6)
48
+ bunny_mock!
49
+ magellan-publisher!
50
+ rspec
51
+ simplecov
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuuki Noguchi
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.
@@ -0,0 +1,29 @@
1
+ # Magellan::Publisher
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'magellan-publisher'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install magellan-publisher
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/magellan-rails/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 a new Pull Request
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require "bundler/gem_tasks"
10
+ require "rspec/core/rake_task"
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ module Magellan
2
+ class Publisher
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ module Magellan
4
+ class Publisher
5
+ def initialize(host: "127.0.0.1", port: 5672, vhost: nil, user: nil, pass: nil, timeout: 0.3)
6
+ # RabbitMQへの接続設定を作成
7
+ connection_settings = {
8
+ host: host,
9
+ port: port,
10
+ vhost: vhost,
11
+ user: user,
12
+ pass: pass,
13
+ timeout: timeout,
14
+ }
15
+
16
+ @conn = Bunny.new(connection_settings)
17
+ @conn.start
18
+ @channel = @conn.create_channel
19
+
20
+ exchange_name = ENV["MAGELLAN_PUBLISH_EXCHANGE"] || "magellan_publish"
21
+
22
+ # no_declareを設定しない場合、Exchangeに対してdeclareを実行してしまい、
23
+ # Acess Contorolにひっかかりエラーとなります
24
+ # exchangeはmagellan-conductorによって作成済みの想定です
25
+ @exchange = @channel.exchange(exchange_name, no_declare: true)
26
+ end
27
+
28
+ def convert_topic(mqtt_topic)
29
+ mqtt_topic.gsub("/", ".")
30
+ end
31
+ private :convert_topic
32
+
33
+ def publish(topic, body)
34
+ @exchange.publish(body, routing_key: convert_topic(topic))
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'magellan/publisher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "magellan-publisher"
8
+ spec.version = Magellan::Publisher::VERSION
9
+ spec.authors = ["Tomoyuki Chikanaga"]
10
+ spec.email = ["t-chikanaga@groovenauts.jp"]
11
+ spec.summary = %q{}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
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_runtime_dependency "bunny"
22
+ spec.add_runtime_dependency "json"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "bunny_mock"
27
+ end