cinch-rubydoc 0.1.0
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/lib/cinch/rubydoc.rb +68 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0518390627af4e6319958776763042a561dbd5a
|
4
|
+
data.tar.gz: c3c871d804c05b72d177c0902a8424a94290e943
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a623220c7be378f16b14ef90f6fa6d2141d848b6edee61f14f24071ef09ad6e1d6047209fb11ae8b9539671196ca23c5cfbd128530167b9327078398cd18bb9d
|
7
|
+
data.tar.gz: dc128cc9734b25536cc73beb9448217532b74521b4138f722c51caecb9d1f83de225a6e5ca66333950719a9c0d8f5fc049443a661f5c99b8f596cc2e20f2f60a
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'pry'
|
3
|
+
require 'pry-byebug'
|
4
|
+
|
5
|
+
module Cinch
|
6
|
+
class Rubydoc
|
7
|
+
include Cinch::Plugin
|
8
|
+
BASE_URL = 'https://devdocs.io/ruby/'
|
9
|
+
UNSAFE_CHARS = /[^0-9a-zA-Z\$_\.\+!\*'\(\)-]/
|
10
|
+
|
11
|
+
match /ri ([\w:-]+)([#.][^:\s]+)?$/
|
12
|
+
|
13
|
+
def execute(m, klass, method = nil)
|
14
|
+
real_klass = find_class klass
|
15
|
+
if real_klass.nil?
|
16
|
+
m.reply "I'm sorry, I don't know anything about #{klass}."
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
type = nil
|
21
|
+
real_method = nil
|
22
|
+
unless method.nil?
|
23
|
+
type = method.slice!(0) == '#' ? :instance : :class
|
24
|
+
real_method = find_method(real_klass, method.to_sym, type)
|
25
|
+
|
26
|
+
if real_method.nil?
|
27
|
+
m.reply "I'm sorry, I found no #{type} method named #{method} in #{real_klass.name}"
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
real_klass = real_method.owner
|
32
|
+
real_klass = real_method.receiver if real_method.owner.name.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
klass_path = real_klass.name.split('::').map { |n| URI.encode(n, UNSAFE_CHARS).downcase }.join('/')
|
36
|
+
url = URI.join(Rubydoc::BASE_URL, klass_path)
|
37
|
+
|
38
|
+
unless real_method.nil?
|
39
|
+
url.merge!("#method-#{type.to_s[0]}-#{URI.encode(method, UNSAFE_CHARS).gsub(/%/, '-')}")
|
40
|
+
end
|
41
|
+
|
42
|
+
m.reply url.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_class(klass)
|
46
|
+
klass_path = klass.split('::')
|
47
|
+
current = Object
|
48
|
+
|
49
|
+
klass_path.each do |e|
|
50
|
+
current = current.const_get(e.to_sym)
|
51
|
+
end
|
52
|
+
|
53
|
+
current
|
54
|
+
rescue NameError
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def find_method(klass, method, type)
|
59
|
+
if type == :class
|
60
|
+
klass.method method
|
61
|
+
else
|
62
|
+
klass.instance_method method
|
63
|
+
end
|
64
|
+
rescue NameError
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-rubydoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thibault `Adædra` Hamel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cinch
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
description: This provides a Cinch plugin to give ruby doc links for doc requests
|
28
|
+
email:
|
29
|
+
- me@adaedra.eu
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/cinch/rubydoc.rb
|
35
|
+
homepage: https://github.com/adaedra/cinch-rubydoc
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.4.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: A ruby doc matcher for Cinch
|
59
|
+
test_files: []
|