caerbannog 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd7777dd47aea5fb2c75fe83337676f39bdcfe4a
4
+ data.tar.gz: 2d43c2b1f4d9e262483e45bbf7e0fff161ddda34
5
+ SHA512:
6
+ metadata.gz: 87f4705b972e70f7ba5ebcbab7236f609050b3c8c370722e5ef3e1a8d4ec388d137643c1ba65c5e38c275f34287e9e9902dc5f175673c849859d7c75b508d49e
7
+ data.tar.gz: 9be692dc762855119244d7a912ed19c36de91aa5fc31f8ab9e0cad5cfffd984f04bb59db01add5f992d63869d9f93529f598e6c8f495457b60ba01110caca3ec
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in caerbannog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Karl Eklund
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Caerbannog
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/caerbannog`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'caerbannog'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install caerbannog
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/caerbannog/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "caerbannog"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'caerbannog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "caerbannog"
8
+ spec.version = Caerbannog::VERSION
9
+ spec.authors = [
10
+ "Dennis Rogenius",
11
+ "Karl Eklund",
12
+ "Kristoffer Roupé",
13
+ "Lennart Fridén",
14
+ "Martin Svalin",
15
+ "Mikael Amborn",
16
+ "Victoria Wagman"
17
+ ]
18
+ spec.email = [
19
+ "dennis@magplus.com",
20
+ "karl@magplus.com",
21
+ "kristoffer@maglus.com",
22
+ "lennart@magplus.com",
23
+ "martin@magplus.com",
24
+ "mikael.amborn@magplus.com",
25
+ "victoria@magplus.com"
26
+ ]
27
+
28
+ spec.summary = %q{Library for handling messages}
29
+ spec.description = %q{Implements a database buffer and workers for sending events to RabbitMQ}
30
+ spec.homepage = "https://github.com/magplus/caerbannog"
31
+ spec.license = "MIT"
32
+
33
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.8"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "mocha"
40
+ spec.add_development_dependency "rspec"
41
+
42
+ spec.add_dependency "bunny"
43
+ end
@@ -0,0 +1,28 @@
1
+ module Caerbannog
2
+ class MessagePoller
3
+ def initialize(message_class, wait_time: 5, iterations: Float::INFINITY)
4
+ @message_class = message_class
5
+ @wait_time = wait_time
6
+ @iterations = iterations
7
+ end
8
+
9
+ def each &block
10
+ (1..iterations).each do
11
+ new_messages = fetch_new_messages
12
+ if new_messages.empty?
13
+ sleep wait_time
14
+ else
15
+ new_messages.each(&block)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :wait_time, :iterations, :message_class
23
+
24
+ def fetch_new_messages
25
+ message_class.all
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ module Caerbannog
2
+ class Queue
3
+ def self.message_class=(message_class)
4
+ @message_class = message_class
5
+ end
6
+
7
+ def self.push(name, payload)
8
+ @message_class.create!(:name => name, :payload => JSON.generate(payload))
9
+ end
10
+
11
+ def self.rabbitmq
12
+ Bunny.run ENV['RABBIT_URL'] do |conn|
13
+ ch = conn.create_channel
14
+ exchange = ch.direct('events', :durable => true)
15
+ yield exchange, ch
16
+ end
17
+ end
18
+
19
+ def self.subscribe(queue_name, *routing_keys, &block)
20
+ rabbitmq do |exchange, channel|
21
+ queue = channel.queue(queue_name)
22
+ routing_keys.each { |routing_key| queue.bind(exchange, :routing_key => routing_key) }
23
+ queue.subscribe(:block => true, &block)
24
+ end
25
+ end
26
+
27
+ def self.publish(messages = MessagePoller.new(@message_class))
28
+ rabbitmq do |exchange|
29
+ messages.each do |message|
30
+ exchange.publish(message.payload, :routing_key => message.name, :persistent => true)
31
+ message.destroy
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Caerbannog
2
+ VERSION = "0.1.0"
3
+ end
data/lib/caerbannog.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/setup"
2
+ require "bunny"
3
+ require 'json'
4
+
5
+ require "caerbannog/version"
6
+ require "caerbannog/message_poller"
7
+ require "caerbannog/queue"
@@ -0,0 +1,21 @@
1
+ class CaerbannogGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def self.next_migration_number(path)
6
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
7
+ end
8
+
9
+ def copy_migration
10
+ migration_template "add_caerbannog_messages.rb", "db/migrate/add_caerbannog_messages.rb"
11
+ end
12
+
13
+ def create_message_model
14
+ copy_file "caerbannog_message.rb", "app/models/caerbannog_message.rb"
15
+ end
16
+
17
+ def create_caerbannog_initializer
18
+ copy_file "caerbannog_initializer.rb", "config/initializers/caerbannog_initializer.rb"
19
+ end
20
+ end
21
+
@@ -0,0 +1,10 @@
1
+ class AddCaerbannogMessages < ActiveRecord::Migration
2
+ def change
3
+ create_table :caerbannog_messages do |t|
4
+ t.string :name, :null => false
5
+ t.text :payload
6
+ t.timestamp :created_at
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1 @@
1
+ Caerbannog::Queue.message_class = CaerbannogMessage
@@ -0,0 +1,2 @@
1
+ class CaerbannogMessage < ActiveRecord::Base
2
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caerbannog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Rogenius
8
+ - Karl Eklund
9
+ - Kristoffer Roupé
10
+ - Lennart Fridén
11
+ - Martin Svalin
12
+ - Mikael Amborn
13
+ - Victoria Wagman
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+ date: 2015-03-18 00:00:00.000000000 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: bundler
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.8'
26
+ type: :development
27
+ prerelease: false
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.8'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: bunny
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Implements a database buffer and workers for sending events to RabbitMQ
90
+ email:
91
+ - dennis@magplus.com
92
+ - karl@magplus.com
93
+ - kristoffer@maglus.com
94
+ - lennart@magplus.com
95
+ - martin@magplus.com
96
+ - mikael.amborn@magplus.com
97
+ - victoria@magplus.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - ".gitignore"
103
+ - ".rspec"
104
+ - ".travis.yml"
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - caerbannog.gemspec
113
+ - lib/caerbannog.rb
114
+ - lib/caerbannog/message_poller.rb
115
+ - lib/caerbannog/queue.rb
116
+ - lib/caerbannog/version.rb
117
+ - lib/generators/caerbannog_generator.rb
118
+ - lib/generators/templates/add_caerbannog_messages.rb
119
+ - lib/generators/templates/caerbannog_initializer.rb
120
+ - lib/generators/templates/caerbannog_message.rb
121
+ homepage: https://github.com/magplus/caerbannog
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.5
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Library for handling messages
145
+ test_files: []