value-yard 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +5 -0
- data/Rakefile +15 -0
- data/lib/value/yard-1.0.rb +63 -0
- data/lib/value/yard/version.rb +24 -0
- data/test/unit/value/yard-1.0.rb +164 -0
- data/test/unit/value/yard/version.rb +4 -0
- metadata +107 -0
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'inventory/rake-1.0'
|
4
|
+
require 'lookout/rake-3.0'
|
5
|
+
|
6
|
+
load File.expand_path('../lib/value/yard/version.rb', __FILE__)
|
7
|
+
|
8
|
+
Inventory::Rake::Tasks.define Value::YARD::Version, :gem => proc{ |_, s|
|
9
|
+
s.author = 'Nikolai Weibull'
|
10
|
+
s.email = 'now@bitwi.se'
|
11
|
+
s.homepage = 'https://github.com/now/value-yard'
|
12
|
+
}
|
13
|
+
|
14
|
+
# TODO: Silence warnings generated from YARD (remove this once we plug them)
|
15
|
+
Lookout::Rake::Tasks::Test.new :options => []
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# Value namespace.
|
4
|
+
module Value
|
5
|
+
end
|
6
|
+
|
7
|
+
# Namespace for YARD extensions for Value.
|
8
|
+
module Value::YARD
|
9
|
+
load File.expand_path('../yard/version.rb', __FILE__)
|
10
|
+
Version.load
|
11
|
+
end
|
12
|
+
|
13
|
+
class YARD::Handlers::Ruby::ValuesHandler < YARD::Handlers::Ruby::Base
|
14
|
+
handles method_call('Value')
|
15
|
+
namespace_only
|
16
|
+
|
17
|
+
process do
|
18
|
+
parameters = statement.parameters(false)
|
19
|
+
if YARD::Parser::Ruby::AstNode === parameters[-1][0] and
|
20
|
+
parameters[-1][0].type == :assoc and
|
21
|
+
comparable = parameters[-1].find{ |e| e.jump(:ident).source == 'comparable' }
|
22
|
+
parameters.pop
|
23
|
+
comparables = (comparable[1].type == :array and comparable[1][0].map{ |e| e.jump(:ident).source })
|
24
|
+
ancestor 'Comparable'
|
25
|
+
ancestor 'Value::Comparable'
|
26
|
+
end
|
27
|
+
ancestor 'Value'
|
28
|
+
initialize = define('initialize', parameters.map{ |e| [e.jump(:ident).source, e.type == :array ? e[0][1].source : nil] })
|
29
|
+
initialize.docstring.tags(:param).select{ |e| e.text and not e.text.empty? }.each do |e|
|
30
|
+
define e.name.sub(/\A[&*]/, ''), [],
|
31
|
+
'@return [%s] %s' % [e.types ? e.types.join(', ') : '', e.text], :protected
|
32
|
+
e.text = ''
|
33
|
+
end
|
34
|
+
initialize.docstring.add_tag(YARD::Tags::Tag.new(:note, 'Comparisons between instances are made between %s.' % join(comparables))) if comparables
|
35
|
+
end
|
36
|
+
|
37
|
+
def ancestor(name)
|
38
|
+
modul = Proxy.new(:root, name).tap{ |m| m.type = :module }
|
39
|
+
namespace.mixins(scope).unshift(modul) unless namespace.mixins(scope).include? modul
|
40
|
+
end
|
41
|
+
|
42
|
+
def define(name, parameters, docstring = nil, visibility = :public)
|
43
|
+
YARD::CodeObjects::MethodObject.new(namespace, name).tap{ |m|
|
44
|
+
register(m)
|
45
|
+
m.signature = 'def %s%s' %
|
46
|
+
[name,
|
47
|
+
parameters.empty? ?
|
48
|
+
'' :
|
49
|
+
'(%s)' % parameters.map{ |n, d| d ? '%s = %s' % [n, d] : n }.join(', ')]
|
50
|
+
m.parameters = parameters
|
51
|
+
m.docstring = docstring if docstring
|
52
|
+
m.visibility = visibility
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def join(items)
|
57
|
+
return items.join('') if items.size < 2
|
58
|
+
return items.join(' and ') if items.size < 3
|
59
|
+
return '%s, and %s' % [items[0..-2].join(', '), items[-1]]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
YARD::Handlers::Ruby::MacroHandler::IGNORE_METHODS['Value'] = true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'inventory-1.0'
|
4
|
+
|
5
|
+
module Value end
|
6
|
+
|
7
|
+
module Value::YARD
|
8
|
+
Version = Inventory.new(1, 1, 0){
|
9
|
+
def dependencies
|
10
|
+
super + Inventory::Dependencies.new{
|
11
|
+
development 'inventory-rake', 1, 2, 0
|
12
|
+
development 'lookout', 3, 0, 0
|
13
|
+
development 'lookout-rake', 3, 0, 0
|
14
|
+
optional 'yard', 0, 7, 0
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def requires
|
19
|
+
%w'
|
20
|
+
yard
|
21
|
+
'
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect [YARD::CodeObjects::Proxy.new(:root, 'Value')] do
|
5
|
+
YARD::Registry.clear
|
6
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
7
|
+
class A
|
8
|
+
# @param [String] a
|
9
|
+
# @param [Integer] b The b
|
10
|
+
Value(:a, :b)
|
11
|
+
end
|
12
|
+
EOS
|
13
|
+
YARD::Registry.at('A').mixins(:instance)
|
14
|
+
end
|
15
|
+
|
16
|
+
expect 'Represents As.' do
|
17
|
+
YARD::Registry.clear
|
18
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
19
|
+
class A
|
20
|
+
# Represents As.
|
21
|
+
Value(:a, :b)
|
22
|
+
end
|
23
|
+
EOS
|
24
|
+
YARD::Registry.at('A#initialize').docstring
|
25
|
+
end
|
26
|
+
|
27
|
+
expect [['a', nil], ['b', '3']] do
|
28
|
+
YARD::Registry.clear
|
29
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
30
|
+
class A
|
31
|
+
Value(:a, [:b, 3])
|
32
|
+
end
|
33
|
+
EOS
|
34
|
+
YARD::Registry.at('A#initialize').parameters
|
35
|
+
end
|
36
|
+
|
37
|
+
expect [:b, :initialize] do
|
38
|
+
YARD::Registry.clear
|
39
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
40
|
+
class A
|
41
|
+
# @param [String] a
|
42
|
+
# @param [Integer] b The b
|
43
|
+
Value(:a, :b)
|
44
|
+
end
|
45
|
+
EOS
|
46
|
+
YARD::Registry.all(:method).map(&:name).sort
|
47
|
+
end
|
48
|
+
|
49
|
+
expect [:b, :initialize] do
|
50
|
+
YARD::Registry.clear
|
51
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
52
|
+
class A
|
53
|
+
# @param [String] a
|
54
|
+
# @param [Integer] *b The b
|
55
|
+
Value(:a, :'*b')
|
56
|
+
end
|
57
|
+
EOS
|
58
|
+
YARD::Registry.all(:method).map(&:name).sort
|
59
|
+
end
|
60
|
+
|
61
|
+
expect [:b, :initialize] do
|
62
|
+
YARD::Registry.clear
|
63
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
64
|
+
class A
|
65
|
+
# @param [String] a
|
66
|
+
# @param [Integer] &b The b
|
67
|
+
Value(:a, :'&b')
|
68
|
+
end
|
69
|
+
EOS
|
70
|
+
YARD::Registry.all(:method).map(&:name).sort
|
71
|
+
end
|
72
|
+
|
73
|
+
expect nil do
|
74
|
+
YARD::Registry.clear
|
75
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
76
|
+
class A
|
77
|
+
# @param [String] a
|
78
|
+
# @param [Integer] b The b
|
79
|
+
Value(:a, :b)
|
80
|
+
end
|
81
|
+
EOS
|
82
|
+
YARD::Registry.at('A#a')
|
83
|
+
end
|
84
|
+
|
85
|
+
expect '@return [Integer] The b' do
|
86
|
+
YARD::Registry.clear
|
87
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
88
|
+
class A
|
89
|
+
# @param [String] a
|
90
|
+
# @param [Integer] b The b
|
91
|
+
Value(:a, :b)
|
92
|
+
end
|
93
|
+
EOS
|
94
|
+
YARD::Registry.at('A#b').docstring.to_raw
|
95
|
+
end
|
96
|
+
|
97
|
+
expect %w'Value Value::Comparable Comparable' do
|
98
|
+
YARD::Registry.clear
|
99
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
100
|
+
class A
|
101
|
+
# @param [String] a
|
102
|
+
Value(:a, :comparable => true)
|
103
|
+
end
|
104
|
+
EOS
|
105
|
+
YARD::Registry.at('A').inheritance_tree(true)[1..3].map(&:path)
|
106
|
+
end
|
107
|
+
|
108
|
+
expect %w'Value Value::Comparable Comparable' do
|
109
|
+
YARD::Registry.clear
|
110
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
111
|
+
module A
|
112
|
+
# @param [String] a
|
113
|
+
Value(:a, :comparable => true)
|
114
|
+
end
|
115
|
+
class B
|
116
|
+
include A
|
117
|
+
# @param [String] a
|
118
|
+
# @param [String] b
|
119
|
+
Value(:a, :b, :comparable => true)
|
120
|
+
end
|
121
|
+
EOS
|
122
|
+
YARD::Registry.at('B').inheritance_tree(true)[1..3].map(&:path)
|
123
|
+
end
|
124
|
+
|
125
|
+
expect 'Comparisons between instances are made between a.' do
|
126
|
+
YARD::Registry.clear
|
127
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
128
|
+
class A
|
129
|
+
# This is A.
|
130
|
+
# @param [String] a
|
131
|
+
# @param [String] b
|
132
|
+
Value(:a, :b, :other => true, :comparable => [:a])
|
133
|
+
end
|
134
|
+
EOS
|
135
|
+
YARD::Registry.at('A#initialize').docstring.tag(:note).text
|
136
|
+
end
|
137
|
+
|
138
|
+
expect 'Comparisons between instances are made between a and b.' do
|
139
|
+
YARD::Registry.clear
|
140
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
141
|
+
class A
|
142
|
+
# @param [String] a
|
143
|
+
# @param [String] b
|
144
|
+
# @param [String] c
|
145
|
+
Value(:a, :b, :c, :comparable => [:a, :b])
|
146
|
+
end
|
147
|
+
EOS
|
148
|
+
YARD::Registry.at('A#initialize').docstring.tag(:note).text
|
149
|
+
end
|
150
|
+
|
151
|
+
expect 'Comparisons between instances are made between a, b, and c.' do
|
152
|
+
YARD::Registry.clear
|
153
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
154
|
+
class A
|
155
|
+
# @param [String] a
|
156
|
+
# @param [String] b
|
157
|
+
# @param [String] c
|
158
|
+
# @param [String] d
|
159
|
+
Value(:a, :b, :c, :d, :comparable => [:a, :b, :c])
|
160
|
+
end
|
161
|
+
EOS
|
162
|
+
YARD::Registry.at('A#initialize').docstring.tag(:note).text
|
163
|
+
end
|
164
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: value-yard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nikolai Weibull
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: inventory
|
16
|
+
requirement: &16782180 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *16782180
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: inventory-rake
|
27
|
+
requirement: &16781616 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.2'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *16781616
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: lookout
|
38
|
+
requirement: &16781148 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *16781148
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: lookout-rake
|
49
|
+
requirement: &16780608 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *16780608
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: yard
|
60
|
+
requirement: &16780116 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.7.0
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *16780116
|
69
|
+
description: ! " Value-YARD\n\n Value-YARD provides
|
70
|
+
YARD handlers for Value¹ objects.\n\n¹ Check out the Value library at http://disu.se/software/value\n"
|
71
|
+
email: now@bitwi.se
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/value/yard-1.0.rb
|
77
|
+
- lib/value/yard/version.rb
|
78
|
+
- test/unit/value/yard-1.0.rb
|
79
|
+
- test/unit/value/yard/version.rb
|
80
|
+
- README
|
81
|
+
- Rakefile
|
82
|
+
homepage: https://github.com/now/value-yard
|
83
|
+
licenses: []
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.10
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Value-YARD provides YARD handlers for Value¹ objects.
|
107
|
+
test_files: []
|