ristener 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: 8185ff46936edaaef407ee4931be79ff298dda37
4
+ data.tar.gz: 21e332e04d986961d128ea8ce0f671210d8d9835
5
+ SHA512:
6
+ metadata.gz: 877fd7aebe4b48fe453c1f4d060ce90a57a035c73c343784d14022a566d7a198bc19c4a634fef29ae1a0920fb3706b402966bee4ce7072162346b5a08fee83b5
7
+ data.tar.gz: f6b623db46e6048bd9bcf7c5af4d8cccca8cc24e7812b07604bf9c43682f0f9cddfb7b2ab8e48599f6b13fb9bcc15967e9e82821fc552ea8a9778c8fa734d222
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ristener.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Ristener
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'ristener'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ristener
18
+
19
+ ## Usage
20
+
21
+ ### Server Side
22
+ Create RistenFile and add this code:
23
+
24
+ ```ruby
25
+ listen('hello') do
26
+ puts 'hello world'
27
+ end
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ ```bash
33
+ $ ristener server
34
+ ```
35
+
36
+ ### Client Side
37
+ After starting server, you can instruct server by this command:
38
+
39
+ ```bash
40
+ $ ristener client hello
41
+ ```
42
+
43
+ And then server console will output:
44
+
45
+ ```bash
46
+ hello world
47
+ ```
48
+
49
+ TODO: More detail infomation
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec ristener` to use the gem in this directory, ignoring other installed copies of this gem.
54
+
55
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ristener.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ristener"
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
data/exe/ristener ADDED
@@ -0,0 +1,3 @@
1
+ require 'ristener'
2
+
3
+ Ristener::CLI.start(ARGV)
@@ -0,0 +1,24 @@
1
+ require 'thor'
2
+
3
+ module Ristener
4
+ # Command line interface of the Ristener
5
+ #
6
+ # @author autopp <autopp.inc@gmail.com>
7
+ #
8
+ class CLI < Thor
9
+ option :ristenfile, aliases: :f, type: :string, default: './RistenFile'
10
+ desc 'server', 'Run as server mode'
11
+ def server
12
+ Server.run(options[:ristenfile])
13
+ end
14
+
15
+ option :host, aliases: :H, type: :string, default: 'localhost'
16
+ option :port, aliases: :p, type: :numeric, default: DEFAULT_PORT
17
+ desc 'client COMMAND', 'Run as client mode'
18
+ def client(command)
19
+ res = Client.new.run(command, options[:host], options[:port])
20
+
21
+ exit(res ? 0 : 1)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module Ristener
5
+ # Client program
6
+ #
7
+ # @author autopp <autopp.inc@gmail.com>
8
+ #
9
+ class Client
10
+ def run(command, hostname, port)
11
+ uri = URI.parse("http://#{hostname}:#{port}/#{command}")
12
+ res = Net::HTTP.get_response(uri)
13
+
14
+ case res
15
+ when Net::HTTPSuccess
16
+ true
17
+ when Net::HTTPNotFound
18
+ $stderr.puts "unknown command `#{command}'"
19
+ false
20
+ else
21
+ $stderr.puts res.inspect
22
+ false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ module Ristener
2
+ class RistenerError < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,29 @@
1
+ module Ristener
2
+ class Server
3
+ # DSL for RistenFile
4
+ #
5
+ # @author autopp <autopp.inc@gmail.com>
6
+ #
7
+ class DSL
8
+ def initialize
9
+ @at_top_level = true
10
+ end
11
+
12
+ private
13
+
14
+ def set(name, value)
15
+ Server.conf[name] = value
16
+ end
17
+
18
+ def listen(command, &block)
19
+ fail RistenerError, "cannot invoke `listen' except at top level." unless @at_top_level
20
+ fail RistenerError, 'invalid command name' unless command =~ /[a-zA-Z_-]+/
21
+
22
+ Router.add_route("#{command}") do
23
+ @at_top_level = false
24
+ block.call
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'sinatra/base'
2
+
3
+ module Ristener
4
+ class Server
5
+ # HTTP Router using Sinatra
6
+ #
7
+ # @author autopp <autopp.inc@gmail.com>
8
+ #
9
+ class Router < Sinatra::Base
10
+ not_found do
11
+ puts 'Not found'
12
+ 'Not found!!'
13
+ end
14
+
15
+ set :logging, false
16
+
17
+ class << self
18
+ public :run!
19
+
20
+ def add_route(name, &block)
21
+ get("/#{name}") do
22
+ $stderr = Server.stderr_orig
23
+ block.call
24
+ $stderr = Server.stderr_mock
25
+ $stderr.truncate(0)
26
+ 'Success'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ require 'sinatra/base'
2
+ require 'stringio'
3
+
4
+ module Ristener
5
+ # Server side program
6
+ #
7
+ # @author autopp <autopp.inc@gmail.com>
8
+ #
9
+ class Server
10
+ @conf = {}
11
+
12
+ class << self
13
+ # @return [Hash] configuration map
14
+ attr_reader :conf
15
+
16
+ # @return [StringIO]
17
+ attr_reader :stderr_mock
18
+
19
+ # @return [IO]
20
+ attr_reader :stderr_orig
21
+
22
+ def run(script_path)
23
+ script = File.read(script_path)
24
+ @stderr_mock = StringIO.new
25
+ @stderr_orig = $stderr
26
+
27
+ dsl = DSL.new
28
+ dsl.instance_eval(script, script_path)
29
+
30
+ Router.port = DEFAULT_PORT
31
+ $stderr = @stderr_mock
32
+ Router.run! do |server|
33
+ case server
34
+ when WEBrick::HTTPServer
35
+ server.logger.level = WEBrick::BasicLog::WARN
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ require 'ristener/server/router'
44
+ require 'ristener/server/dsl'
@@ -0,0 +1,4 @@
1
+ # nodoc
2
+ module Ristener
3
+ VERSION = '0.1.0'
4
+ end
data/lib/ristener.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'ristener/version'
2
+
3
+ #
4
+ #
5
+ # @author autopp <autopp.inc@gmail.com>
6
+ #
7
+ module Ristener
8
+ DEFAULT_PORT = 5678
9
+ end
10
+
11
+ require 'ristener/ristener_error'
12
+ require 'ristener/server'
13
+ require 'ristener/client'
14
+ require 'ristener/cli'
data/ristener.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ristener/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ristener'
8
+ spec.version = Ristener::VERSION
9
+ spec.authors = ['autopp']
10
+ spec.email = ['autopp.inc@gmail.com']
11
+
12
+ spec.summary = 'Server/Client model event listener flamework'
13
+ spec.description = 'Server/Client model event listener flamework'
14
+ spec.homepage = 'https://github.com/autopp/ristener'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'sinatra'
24
+ spec.add_runtime_dependency 'thor'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.10'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ristener
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - autopp
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Server/Client model event listener flamework
84
+ email:
85
+ - autopp.inc@gmail.com
86
+ executables:
87
+ - ristener
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - exe/ristener
100
+ - lib/ristener.rb
101
+ - lib/ristener/cli.rb
102
+ - lib/ristener/client.rb
103
+ - lib/ristener/ristener_error.rb
104
+ - lib/ristener/server.rb
105
+ - lib/ristener/server/dsl.rb
106
+ - lib/ristener/server/router.rb
107
+ - lib/ristener/version.rb
108
+ - ristener.gemspec
109
+ homepage: https://github.com/autopp/ristener
110
+ licenses: []
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.5.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Server/Client model event listener flamework
132
+ test_files: []