yard-value 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,5 @@
1
+ YARD-Value
2
+
3
+ YARD-Value provides YARD handlers for Value¹ objects.
4
+
5
+ ¹ Check out the Value library at http://disu.se/software/value
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'inventory/rake-1.0'
4
+
5
+ load File.expand_path('../lib/yard-value/version.rb', __FILE__)
6
+
7
+ Inventory::Rake::Tasks.define YARDValue::Version, :gem => proc{ |_, s|
8
+ s.author = 'Nikolai Weibull'
9
+ s.email = 'now@bitwi.se'
10
+ s.homepage = 'https://github.com/now/yard-value'
11
+ }
12
+
13
+ Inventory::Rake::Tasks.unless_installing_dependencies do
14
+ require 'lookout/rake-3.0'
15
+ # TODO: Silence warnings generated from YARD (remove this once we plug them)
16
+ Lookout::Rake::Tasks::Test.new :options => []
17
+ end
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Namespace for YARD extensions for Value.
4
+ module YARDValue
5
+ load File.expand_path('../yard-value/version.rb', __FILE__)
6
+ Version.load
7
+ end
8
+
9
+ class YARD::Handlers::Ruby::ValuesHandler < YARD::Handlers::Ruby::Base
10
+ handles method_call('Value')
11
+ namespace_only
12
+
13
+ process do
14
+ parameters = statement.parameters(false)
15
+ if YARD::Parser::Ruby::AstNode === parameters[-1][0] and
16
+ parameters[-1][0].type == :assoc and
17
+ comparable = parameters[-1].find{ |e| e.jump(:ident).source == 'comparable' }
18
+ parameters.pop
19
+ comparables = (comparable[1].type == :array and comparable[1][0].map{ |e| e.jump(:ident).source })
20
+ ancestor 'Comparable'
21
+ ancestor 'Value::Comparable'
22
+ end
23
+ ancestor 'Value'
24
+ initialize = define('initialize', parameters.map{ |e| [e.jump(:ident).source, e.type == :array ? e[0][1].source : nil] })
25
+ initialize.docstring.tags(:param).select{ |e| e.text and not e.text.empty? }.each do |e|
26
+ define e.name.sub(/\A[&*]/, ''), [],
27
+ '@return [%s] %s' % [e.types ? e.types.join(', ') : '', e.text], :protected
28
+ e.text = ''
29
+ end
30
+ initialize.docstring.add_tag(YARD::Tags::Tag.new(:note, 'Comparisons between instances are made between %s.' % join(comparables))) if comparables
31
+ end
32
+
33
+ def ancestor(name)
34
+ modul = Proxy.new(:root, name).tap{ |m| m.type = :module }
35
+ namespace.mixins(scope).unshift(modul) unless namespace.mixins(scope).include? modul
36
+ end
37
+
38
+ def define(name, parameters, docstring = nil, visibility = :public)
39
+ YARD::CodeObjects::MethodObject.new(namespace, name).tap{ |m|
40
+ register(m)
41
+ m.signature = 'def %s%s' %
42
+ [name,
43
+ parameters.empty? ?
44
+ '' :
45
+ '(%s)' % parameters.map{ |n, d| d ? '%s = %s' % [n, d] : n }.join(', ')]
46
+ m.parameters = parameters
47
+ m.docstring = docstring if docstring
48
+ m.visibility = visibility
49
+ }
50
+ end
51
+
52
+ def join(items)
53
+ return items.join('') if items.size < 2
54
+ return items.join(' and ') if items.size < 3
55
+ return '%s, and %s' % [items[0..-2].join(', '), items[-1]]
56
+ end
57
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'inventory-1.0'
4
+
5
+ module YARDValue
6
+ Version = Inventory.new(1, 2, 0){
7
+ def dependencies
8
+ super + Inventory::Dependencies.new{
9
+ development 'inventory-rake', 1, 3, 0
10
+ development 'lookout', 3, 0, 0
11
+ development 'lookout-rake', 3, 0, 0
12
+ runtime 'yard', 0, 8, 0, :feature => 'yard'
13
+ }
14
+ end
15
+ }
16
+ 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
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-value
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nikolai Weibull
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: inventory
16
+ requirement: &2152770480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152770480
25
+ - !ruby/object:Gem::Dependency
26
+ name: inventory-rake
27
+ requirement: &2152769900 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.3'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152769900
36
+ - !ruby/object:Gem::Dependency
37
+ name: lookout
38
+ requirement: &2152769300 !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: *2152769300
47
+ - !ruby/object:Gem::Dependency
48
+ name: lookout-rake
49
+ requirement: &2152768740 !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: *2152768740
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard
60
+ requirement: &2152768060 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.8.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *2152768060
69
+ description: ! " YARD-Value\n\n YARD-Value 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/yard-value-1.0.rb
77
+ - lib/yard-value/version.rb
78
+ - test/unit/yard-value-1.0.rb
79
+ - test/unit/yard-value/version.rb
80
+ - README
81
+ - Rakefile
82
+ homepage: https://github.com/now/yard-value
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.11
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: YARD-Value provides YARD handlers for Value¹ objects.
106
+ test_files: []