cinch-rubydoc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cinch/rubydoc.rb +47 -46
  3. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0518390627af4e6319958776763042a561dbd5a
4
- data.tar.gz: c3c871d804c05b72d177c0902a8424a94290e943
3
+ metadata.gz: a8fda38de6cded1bc4cddcf740182c702f4a6851
4
+ data.tar.gz: 556b9e5b2afb8c359255f026b7ea133549bc92f3
5
5
  SHA512:
6
- metadata.gz: a623220c7be378f16b14ef90f6fa6d2141d848b6edee61f14f24071ef09ad6e1d6047209fb11ae8b9539671196ca23c5cfbd128530167b9327078398cd18bb9d
7
- data.tar.gz: dc128cc9734b25536cc73beb9448217532b74521b4138f722c51caecb9d1f83de225a6e5ca66333950719a9c0d8f5fc049443a661f5c99b8f596cc2e20f2f60a
6
+ metadata.gz: 76404f5934c485ca11f5f65f0d2b842a9396e41243afe12fb52c749c94d23589797b11e5179c0296387ba53c621a9f01d6b8454697da757b7ce021683db8abad
7
+ data.tar.gz: 98215c8c267e8ce67ad8681a8b213cd3da098ccd414b014cbed90c77b1a0e6c37262d39581fa21cca92f76592a5157c62a56dc2e5046cc93dbc20fd29d8da449
data/lib/cinch/rubydoc.rb CHANGED
@@ -1,68 +1,69 @@
1
- require 'uri'
2
- require 'pry'
3
- require 'pry-byebug'
1
+ require 'yard'
2
+ require 'cgi'
3
+
4
4
 
5
5
  module Cinch
6
6
  class Rubydoc
7
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
8
+ BASE_URL = 'http://www.rubydoc.info/stdlib'
19
9
 
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)
10
+ match /ri (.+)\z/
25
11
 
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
12
+ def initialize(*args)
13
+ super
14
+ @store = YARD::RegistryStore.new
15
+ @store.load '.yardoc'
16
+ end
30
17
 
31
- real_klass = real_method.owner
32
- real_klass = real_method.receiver if real_method.owner.name.nil?
18
+ def execute(m, request)
19
+ requests = request.split
20
+ if requests.count > 3
21
+ requests = requests.first(3)
33
22
  end
34
23
 
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(/%/, '-')}")
24
+ uris = requests.map do |request|
25
+ url_for(request)
40
26
  end
41
27
 
42
- m.reply url.to_s
28
+ uris.compact!
29
+ if uris.empty?
30
+ m.reply 'No results'
31
+ else
32
+ m.reply uris.join ', '
33
+ end
43
34
  end
44
35
 
45
- def find_class(klass)
46
- klass_path = klass.split('::')
47
- current = Object
36
+ private
37
+
38
+ def url_for(name)
39
+ obj = @store[name]
40
+ if obj.nil? && name.end_with?('.new')
41
+ obj = @store[name.sub(/\.new\z/, '#initialize')]
42
+ end
48
43
 
49
- klass_path.each do |e|
50
- current = current.const_get(e.to_sym)
44
+ unless obj
45
+ debug "Nothing found for #{name}"
46
+ return nil
51
47
  end
52
48
 
53
- current
54
- rescue NameError
55
- nil
49
+ section = section_for obj
50
+ "#{BASE_URL}/#{section}/#{path_for obj}"
56
51
  end
57
52
 
58
- def find_method(klass, method, type)
59
- if type == :class
60
- klass.method method
61
- else
62
- klass.instance_method method
53
+ def section_for(obj)
54
+ return :core if obj.files.any? { |f, _| !f.include?('/') }
55
+ File.basename(obj.file.split('/', 3)[1], '.rb')
56
+ end
57
+
58
+ def path_for(obj)
59
+ case obj.type
60
+ when :method
61
+ "#{path_for obj.parent}##{CGI.escape obj.name.to_s}-#{obj.scope}_method"
62
+ when :constant
63
+ "#{path_for obj.parent}##{obj.name}-constant"
64
+ when :class, :module
65
+ obj.path.gsub('::', '/')
63
66
  end
64
- rescue NameError
65
- nil
66
67
  end
67
68
  end
68
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-rubydoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault `Adædra` Hamel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-03 00:00:00.000000000 Z
11
+ date: 2015-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cinch
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
27
41
  description: This provides a Cinch plugin to give ruby doc links for doc requests
28
42
  email:
29
43
  - me@adaedra.eu
@@ -57,3 +71,4 @@ signing_key:
57
71
  specification_version: 4
58
72
  summary: A ruby doc matcher for Cinch
59
73
  test_files: []
74
+ has_rdoc: