tdev_kiwi 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+
7
+ notifications:
8
+ irc:
9
+ channels:
10
+ - "irc.freenode.org#TotenDev"
11
+ template:
12
+ - "%{repository_url} (%{commit}) : %{message} %{foo}"
13
+ - "Build details: %{build_url}"
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kiwi.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "travis-lint"
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TotenDev
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,48 @@
1
+ # Kiwi
2
+
3
+ Ruby Gem to send a messages to [Kiwi](https://github.com/TotenDev/Kiwi)
4
+
5
+ [![Build Status](https://secure.travis-ci.org/TotenDev/Kiwi-LibRuby.png?branch=master)](http://travis-ci.org/TotenDev/Kiwi-LibRuby)
6
+
7
+ ## Requirements
8
+
9
+ - Ruby ~> 1.9.2
10
+ - [LibC](http://www.gnu.org/software/libc/)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'tdev_kiwi'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install tdev_kiwi
25
+
26
+ ## Usage
27
+
28
+ require 'tdev_kiwi'
29
+
30
+ message = TotenDev::Message.new
31
+ message.worker = '<PATH_TO_WORKER>'
32
+ message.args = '<ARGUMENTS>'
33
+
34
+ queue = TotenDev::Kiwi.new <KEY_ID>
35
+ queue.queue_id '<QUEUE_ID>'
36
+ queue.send message
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
45
+
46
+ ##License
47
+
48
+ [MIT](https://github.com/TotenDev/TDevShortener-LibRuby/blob/master/LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ task :default => 'test'
5
+
6
+ desc "Run all tests"
7
+ task :test => [:tlint, :spec] do
8
+ puts "finished running all tests successfully!"
9
+ end
10
+
11
+ desc "Run rspec"
12
+ task :spec do
13
+ puts "running rspec..."
14
+ system("bundle exec rspec spec")
15
+ raise "rspec failed!" unless $?.exitstatus == 0
16
+ end
17
+
18
+ desc "Run travis-lint"
19
+ task :tlint do
20
+ puts "running travis-lint..."
21
+ system("travis-lint")
22
+ raise "lint failed!" unless $?.exitstatus == 0
23
+ end
@@ -0,0 +1,15 @@
1
+ # message.rb — Kiwi
2
+ # today is 7/11/12, it is now 7:13 PM
3
+ # created by mtrovilho
4
+ # see LICENSE for details
5
+
6
+ module TotenDev
7
+ class Message
8
+ attr_accessor :worker, :args
9
+
10
+ def initialize(w = '', a = '')
11
+ @worker = w
12
+ @args = a
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Kiwi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tdev_kiwi.rb ADDED
@@ -0,0 +1,65 @@
1
+ # tdev_kiwi.rb — Kiwi
2
+ # today is 7/11/12, it is now 7:21 PM
3
+ # created by mtrovilho
4
+ # see LICENSE for details
5
+ #
6
+ # special thanks to Peter Cooper (@peterc) for
7
+ # the great gist (https://gist.github.com/2582673)
8
+ # that helped me a lot!
9
+
10
+ require 'fiddle'
11
+ require 'tdev_kiwi/message'
12
+ require 'tdev_kiwi/version'
13
+
14
+ module TotenDev
15
+ class Kiwi
16
+
17
+ LIBC = DL.dlopen('libc.dylib')
18
+
19
+ IPC_CREAT = 001000
20
+ IPC_EXCL = 002000
21
+ IPC_NOWAIT = 004000
22
+ IPC_R = 000400
23
+ IPC_W = 000200
24
+ IPC_M = 010000
25
+
26
+ attr_accessor :queue_id, :message
27
+
28
+ def initialize(qk, qid = 'TDKiwi')
29
+ @queue_id = qid
30
+ @kiwi = self.class.get(qk) unless qk.nil?
31
+ end
32
+
33
+ def self.get( queue_key, msgflag = IPC_CREAT | IPC_R | IPC_W | IPC_M )
34
+ queue_key = queue_key.to_i if queue_key.is_a? String
35
+ Fiddle::Function.new( LIBC['msgget'],
36
+ [Fiddle::TYPE_INT, Fiddle::TYPE_INT],
37
+ Fiddle::TYPE_INT )
38
+ .call( queue_key, msgflag )
39
+ end
40
+
41
+ def send( msg = @message )
42
+ wrapper = "#{@queue_id}||#{msg.worker}||'#{msg.args}'"
43
+ sender( "s:#{wrapper.length}:\"#{wrapper}\"" )
44
+ end
45
+
46
+ private
47
+ def sender(msg = {}, flags = 0)
48
+ msg = { msg: msg } if msg.is_a? String
49
+ msg = { type: 1, msg: '' }.merge(msg)
50
+
51
+ r = Fiddle::Function.new( LIBC['msgsnd'],
52
+ [ Fiddle::TYPE_INT,
53
+ Fiddle::TYPE_VOIDP,
54
+ Fiddle::TYPE_INT,
55
+ Fiddle::TYPE_INT ],
56
+ Fiddle::TYPE_INT )
57
+ .call(@kiwi,
58
+ [msg[:type]].pack('Q') + msg[:msg],
59
+ msg[:msg].length + 1,
60
+ flags)
61
+ r == -1 ? false : r
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'tdev_kiwi'
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe TotenDev::Kiwi do
4
+
5
+ before :each do
6
+ @kiwi = TotenDev::Kiwi.new nil, 'MyQueueID'
7
+ @kiwi.message = TotenDev::Message.new '/usr/local/test.rb', 'the_arg'
8
+ end
9
+
10
+ describe "#new" do
11
+ it "takes two parameters and returns a Kiwi object" do
12
+ @kiwi.should be_an_instance_of TotenDev::Kiwi
13
+ end
14
+ end
15
+
16
+ describe "#queue_id" do
17
+ it "returns the correct queue_id" do
18
+ @kiwi.queue_id.should eql 'MyQueueID'
19
+ end
20
+ end
21
+
22
+ describe "#message" do
23
+ it "returns an instance of Message" do
24
+ @kiwi.message.should be_an_instance_of TotenDev::Message
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe TotenDev::Message do
4
+
5
+ before :each do
6
+ @message = TotenDev::Message.new '/usr/local/test.rb', 'the_arg'
7
+ end
8
+
9
+ describe "#new" do
10
+ it "takes two parameters and returns a Message object" do
11
+ @message.should be_an_instance_of TotenDev::Message
12
+ end
13
+ end
14
+
15
+ describe "#worker" do
16
+ it "returns the correct worker" do
17
+ @message.worker.should eql '/usr/local/test.rb'
18
+ end
19
+ end
20
+
21
+ describe "#args" do
22
+ it "returns the correct argument" do
23
+ @message.args.should eql 'the_arg'
24
+ end
25
+ end
26
+
27
+ end
data/tdev_kiwi.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/tdev_kiwi/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Marcos Trovilho"]
6
+ gem.email = ["marcos@trovilho.com"]
7
+ gem.summary = %q{Ruby gem to send messages with Kiwi}
8
+ gem.homepage = "https://github.com/TotenDev/Kiwi-LibRuby"
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "tdev_kiwi"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = Kiwi::VERSION
15
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tdev_kiwi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marcos Trovilho
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - marcos@trovilho.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - .travis.yml
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - lib/tdev_kiwi.rb
29
+ - lib/tdev_kiwi/message.rb
30
+ - lib/tdev_kiwi/version.rb
31
+ - spec/spec_helper.rb
32
+ - spec/tdev_kiwi_spec.rb
33
+ - spec/tdev_message_spec.rb
34
+ - tdev_kiwi.gemspec
35
+ homepage: https://github.com/TotenDev/Kiwi-LibRuby
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ segments:
48
+ - 0
49
+ hash: 2067003275227394834
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ segments:
57
+ - 0
58
+ hash: 2067003275227394834
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.23
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Ruby gem to send messages with Kiwi
65
+ test_files:
66
+ - spec/spec_helper.rb
67
+ - spec/tdev_kiwi_spec.rb
68
+ - spec/tdev_message_spec.rb