ruboty-tryruby 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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +2 -0
- data/images/tryruby.png +0 -0
- data/lib/ruboty/actions/tryruby.rb +23 -0
- data/lib/ruboty/handlers/tryruby.rb +13 -0
- data/lib/ruboty/tryruby.rb +15 -0
- data/lib/ruboty/tryruby/evaluator.rb +32 -0
- data/lib/ruboty/tryruby/result.rb +27 -0
- data/lib/ruboty/tryruby/version.rb +5 -0
- data/ruboty-tryruby.gemspec +24 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b8f6cd2902acddaf777e8e8f0fa4d57cd6701d54
|
4
|
+
data.tar.gz: 2f2d3e4b5f6a170e68658d92229c420ff4b895b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abd13c5e168becf9c0b4518119e329069d5afbc546ac042263c1d51a1c312a5e59c82abeb3eb0883bb91d0010f574407687ec841edf8aceda69113c1359d11e9
|
7
|
+
data.tar.gz: 4bafdb1dd9d23806c693e414e37ab6202dfbf1b6e556608c09adab3e485cab519b3a62e960ea2c3333bfa7434b9d7ff5e394d818a0c7a9979189823dffe5724a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 mizokami
|
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,30 @@
|
|
1
|
+
# Ruboty::Tryruby
|
2
|
+
|
3
|
+
Ruboty plugin to evaluate one line of Ruby script
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ruboty-tryruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ruboty-tryruby
|
22
|
+
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it ( https://github.com/mizoR/ruboty-tryruby/fork )
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/images/tryruby.png
ADDED
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Actions
|
3
|
+
class Tryruby < Base
|
4
|
+
def call
|
5
|
+
message.reply(body)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def script
|
11
|
+
message[2]
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
result.successful? ? result.output : result.result
|
16
|
+
end
|
17
|
+
|
18
|
+
def result
|
19
|
+
@result ||= Ruboty::Tryruby.evaluate(script)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Handlers
|
3
|
+
class Tryruby < Base
|
4
|
+
on %r<(ruby|rb|irb)\s+(.*)$>, name: 'evaluate', description: 'Evaluate one line of Ruby script'
|
5
|
+
|
6
|
+
def evaluate(message)
|
7
|
+
Ruboty::Actions::Tryruby.new(message).call
|
8
|
+
rescue Exception => e
|
9
|
+
Ruboty.logger.info "#{e.class}: #{e.message}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "ruboty"
|
2
|
+
require "ruboty/tryruby/version"
|
3
|
+
require "ruboty/tryruby/result"
|
4
|
+
require "ruboty/tryruby/evaluator"
|
5
|
+
require "ruboty/handlers/tryruby"
|
6
|
+
require "ruboty/actions/tryruby"
|
7
|
+
|
8
|
+
module Ruboty
|
9
|
+
module Tryruby
|
10
|
+
def self.evaluate(command)
|
11
|
+
evaluator = Evaluator.new(command)
|
12
|
+
evaluator.evaluate
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module Tryruby
|
5
|
+
class Evaluator
|
6
|
+
attr_reader :http, :request
|
7
|
+
|
8
|
+
def initialize(command)
|
9
|
+
@http = Net::HTTP.new('tryruby.org', 80)
|
10
|
+
@request = Net::HTTP::Put.new('/levels/1/challenges/0')
|
11
|
+
@request.set_form_data(cmd: command)
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate
|
15
|
+
response = http.request(request)
|
16
|
+
parse(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse(response)
|
22
|
+
code = response.code.to_i
|
23
|
+
|
24
|
+
if (code >= 200) && (code <= 299)
|
25
|
+
Result.parse(response.body)
|
26
|
+
else
|
27
|
+
raise response.value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module Tryruby
|
5
|
+
class Result
|
6
|
+
def self.parse(raw_data)
|
7
|
+
data = JSON.parse(raw_data)
|
8
|
+
new(data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def successful?
|
12
|
+
success
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method_name)
|
16
|
+
method_name = method_name.to_s
|
17
|
+
@data.key?(method_name) ? @data[method_name] : super
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def initialize(data)
|
23
|
+
@data = data
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/tryruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-tryruby"
|
8
|
+
spec.version = Ruboty::Tryruby::VERSION
|
9
|
+
spec.authors = ["mizokami"]
|
10
|
+
spec.email = ["suzunatsu@yahoo.com"]
|
11
|
+
spec.summary = %q{Evaluate one line of Ruby script.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "ruboty"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-tryruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mizokami
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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
|
+
description:
|
70
|
+
email:
|
71
|
+
- suzunatsu@yahoo.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- images/tryruby.png
|
82
|
+
- lib/ruboty/actions/tryruby.rb
|
83
|
+
- lib/ruboty/handlers/tryruby.rb
|
84
|
+
- lib/ruboty/tryruby.rb
|
85
|
+
- lib/ruboty/tryruby/evaluator.rb
|
86
|
+
- lib/ruboty/tryruby/result.rb
|
87
|
+
- lib/ruboty/tryruby/version.rb
|
88
|
+
- ruboty-tryruby.gemspec
|
89
|
+
homepage: ''
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.5
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Evaluate one line of Ruby script.
|
113
|
+
test_files: []
|