value 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +16 -5
- data/lib/value/comparable.rb +13 -0
- data/lib/value/values.rb +44 -0
- data/lib/value/version.rb +18 -2
- data/lib/value/yard.rb +47 -0
- data/lib/value.rb +41 -26
- data/test/unit/value/comparable.rb +17 -0
- data/test/unit/value/values.rb +4 -0
- data/test/unit/value/version.rb +4 -0
- data/test/unit/value/yard.rb +126 -0
- data/test/unit/value.rb +121 -25
- metadata +46 -84
data/Rakefile
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'inventory/rake/tasks'
|
3
4
|
require 'lookout/rake/tasks'
|
4
|
-
require 'yard'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
7
|
+
require 'value/version'
|
8
|
+
|
9
|
+
Inventory::Rake::Tasks.define Value::Version, :gem => proc{ |_, s|
|
10
|
+
s.author = 'Nikolai Weibull'
|
11
|
+
s.email = 'now@bitwi.se'
|
12
|
+
s.homepage = 'https://github.com/now/value'
|
13
|
+
|
14
|
+
s.add_development_dependency 'yard', '~> 0.7.0'
|
15
|
+
|
16
|
+
s.add_runtime_dependency 'inventory', '~> 0.2.0'
|
17
|
+
}
|
18
|
+
|
19
|
+
# TODO: Silence warnings generated from YARD (remove this once we plug them)
|
20
|
+
Lookout::Rake::Tasks::Test.new :options => []
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Value::Comparable
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
def <=>(other)
|
7
|
+
return nil unless self.class == other.class
|
8
|
+
v = nil
|
9
|
+
(values.comparable.any?{ |e| v = (send(e) <=> other.send(e)).nonzero? } and v) or 0
|
10
|
+
end
|
11
|
+
|
12
|
+
alias eql? ==
|
13
|
+
end
|
data/lib/value/values.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class Value::Values
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(*values)
|
7
|
+
options = Hash === values.last ? values.pop : {}
|
8
|
+
values.pop if @block = values.last.to_s.start_with?('&') ? values.last.to_s[1..-1].to_sym : nil
|
9
|
+
values.pop if @splat = (values.last and values.last.to_s.start_with?('*')) ?
|
10
|
+
values.last.to_s[1..-1].to_sym : nil
|
11
|
+
required, optional = values.partition{ |e| not(Array === e) }
|
12
|
+
@required = required.map(&:to_sym)
|
13
|
+
@optional = optional.map{ |e| [e.first.to_sym, e.last] }
|
14
|
+
all = to_a
|
15
|
+
@comparable = Array === options[:comparable] ?
|
16
|
+
options[:comparable].each{ |e|
|
17
|
+
raise ArgumentError, '%p is not among comparable members %s' % [e, all.map(&:inspect).join(', ')] unless all.include?(e)
|
18
|
+
} :
|
19
|
+
all
|
20
|
+
end
|
21
|
+
|
22
|
+
def each
|
23
|
+
return enum_for(__method__) unless block_given?
|
24
|
+
required.each do |value|
|
25
|
+
yield value
|
26
|
+
end
|
27
|
+
optional.each do |value, _|
|
28
|
+
yield value
|
29
|
+
end
|
30
|
+
yield splat if splat
|
31
|
+
yield block if block
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def ==(other)
|
36
|
+
self.class == other.class and
|
37
|
+
required == other.required and
|
38
|
+
optional == other.optional and
|
39
|
+
splat == other.splat and
|
40
|
+
block == other.block
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_reader :required, :optional, :splat, :block, :comparable
|
44
|
+
end
|
data/lib/value/version.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'inventory'
|
4
|
+
|
5
|
+
module Value
|
6
|
+
Version = Inventory.new(0, 2, 0){
|
7
|
+
def libs
|
8
|
+
%w'
|
9
|
+
value/comparable.rb
|
10
|
+
value/values.rb
|
11
|
+
'
|
12
|
+
end
|
13
|
+
|
14
|
+
def additional_libs
|
15
|
+
super +
|
16
|
+
%w'
|
17
|
+
value/yard.rb
|
18
|
+
'
|
19
|
+
end
|
20
|
+
}
|
5
21
|
end
|
data/lib/value/yard.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
class YARD::Handlers::Ruby::ValuesHandler < YARD::Handlers::Ruby::Base
|
6
|
+
handles method_call('Value')
|
7
|
+
namespace_only
|
8
|
+
|
9
|
+
process do
|
10
|
+
parameters = statement.parameters(false)
|
11
|
+
if YARD::Parser::Ruby::AstNode === parameters[-1][0] and
|
12
|
+
parameters[-1][0].type == :assoc and
|
13
|
+
parameters[-1].jump(:ident).source == 'comparable'
|
14
|
+
parameters.pop
|
15
|
+
ancestor 'Comparable'
|
16
|
+
ancestor 'Value::Comparable'
|
17
|
+
end
|
18
|
+
ancestor 'Value'
|
19
|
+
define('initialize', parameters.map{ |e| [e.jump(:ident).source, e.type == :array ? e[0][1].source : nil] }).
|
20
|
+
docstring.tags(:param).select{ |e| e.text and not e.text.empty? }.each do |e|
|
21
|
+
define e.name.sub(/\A[&*]/, ''), [],
|
22
|
+
'@return [%s] %s' % [e.types.join(', '), e.text], :protected
|
23
|
+
e.text = ''
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def ancestor(name)
|
28
|
+
modul = Proxy.new(:root, name).tap{ |m| m.type = :module }
|
29
|
+
namespace.mixins(scope).unshift(modul) unless namespace.mixins(scope).include? modul
|
30
|
+
end
|
31
|
+
|
32
|
+
def define(name, parameters, docstring = nil, visibility = :public)
|
33
|
+
YARD::CodeObjects::MethodObject.new(namespace, name).tap{ |m|
|
34
|
+
register(m)
|
35
|
+
m.signature = 'def %s%s' %
|
36
|
+
[name,
|
37
|
+
parameters.empty? ?
|
38
|
+
'' :
|
39
|
+
'(%s)' % parameters.map{ |n, d| d ? '%s = %s' % [n, d] : n }.join(', ')]
|
40
|
+
m.parameters = parameters
|
41
|
+
m.docstring = docstring if docstring
|
42
|
+
m.visibility = visibility
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
YARD::Handlers::Ruby::MacroHandler::IGNORE_METHODS['Value'] = true
|
data/lib/value.rb
CHANGED
@@ -1,49 +1,64 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
4
|
-
autoload :Version, 'value/version'
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def values(*values)
|
8
|
-
if values.empty?
|
9
|
-
raise RuntimeError,
|
10
|
-
'no values have been set for class: %p' % self if not defined? @values
|
11
|
-
@values
|
12
|
-
else
|
13
|
-
@values ||= []
|
14
|
-
@values.concat values.map{ |value| value.to_sym }.tap{ |symbols|
|
15
|
-
attr_reader(*symbols)
|
16
|
-
protected(*symbols)
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
3
|
+
module Value
|
22
4
|
def initialize(*arguments)
|
23
5
|
raise ArgumentError,
|
24
6
|
'wrong number of arguments (%d for %d)' %
|
25
|
-
[arguments.length,
|
26
|
-
arguments.length
|
27
|
-
|
7
|
+
[arguments.length, values.required.length] if
|
8
|
+
arguments.length < values.required.length
|
9
|
+
raise ArgumentError,
|
10
|
+
'wrong number of arguments (%d for %d)' %
|
11
|
+
[arguments.length,
|
12
|
+
values.required.length + values.optional.length] if
|
13
|
+
arguments.length > values.required.length +
|
14
|
+
values.optional.length and not values.splat
|
15
|
+
instance_variable_set :"@#{values.block}",
|
16
|
+
block_given? ? Proc.new : nil if values.block
|
17
|
+
instance_variable_set :"@#{values.splat}",
|
18
|
+
arguments[values.required.length +
|
19
|
+
values.optional.length..-1] if values.splat
|
20
|
+
values.required.each_with_index do |value, index|
|
28
21
|
instance_variable_set :"@#{value}", arguments[index]
|
29
22
|
end
|
30
|
-
|
23
|
+
values.optional.each_with_index do |(value, default), index|
|
24
|
+
offset = values.required.length + index
|
25
|
+
instance_variable_set :"@#{value}",
|
26
|
+
offset >= arguments.length ? default : arguments[offset]
|
27
|
+
end
|
31
28
|
end
|
32
29
|
|
33
30
|
def ==(other)
|
34
31
|
self.class == other.class and
|
35
|
-
|
32
|
+
values.all?{ |value| send(value) == other.send(value) }
|
36
33
|
end
|
37
34
|
|
38
35
|
alias eql? ==
|
39
36
|
|
40
37
|
def hash
|
41
|
-
self.class.hash ^
|
38
|
+
self.class.hash ^ values.map{ |value| send(value) }.hash
|
42
39
|
end
|
43
40
|
|
44
41
|
def inspect
|
45
42
|
'%s.new(%s)' %
|
46
43
|
[self.class,
|
47
|
-
|
44
|
+
values.map{ |value| send(value).inspect }.join(', ')]
|
45
|
+
end
|
46
|
+
|
47
|
+
load File.expand_path('../value/version.rb', __FILE__)
|
48
|
+
Version.load
|
49
|
+
end
|
50
|
+
|
51
|
+
class Module
|
52
|
+
def Value(first, *rest)
|
53
|
+
options = Hash === rest.last ? rest.pop : {}
|
54
|
+
values = Value::Values.new(*([first] + rest).push({:comparable => options[:comparable]}))
|
55
|
+
attr_reader(*values)
|
56
|
+
protected(*values)
|
57
|
+
define_method :values do
|
58
|
+
values
|
59
|
+
end
|
60
|
+
private :values
|
61
|
+
include Value::Comparable if options[:comparable]
|
62
|
+
include Value
|
48
63
|
end
|
49
64
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
Expectations do
|
4
|
+
expect 0 do
|
5
|
+
c = Class.new{ Value(:a, :comparable => true) }
|
6
|
+
c.new(1) <=> c.new(1)
|
7
|
+
end
|
8
|
+
|
9
|
+
expect 0 do
|
10
|
+
c = Class.new{ Value(:a, :b, :comparable => [:a]) }
|
11
|
+
c.new(1, 2) <=> c.new(1, 3)
|
12
|
+
end
|
13
|
+
|
14
|
+
expect ArgumentError.new(':c is not among comparable members :a, :b') do
|
15
|
+
Class.new{ Value(:a, :b, :comparable => [:c]) }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'value/yard'
|
4
|
+
|
5
|
+
Expectations do
|
6
|
+
expect [YARD::CodeObjects::Proxy.new(:root, 'Value')] do
|
7
|
+
YARD::Registry.clear
|
8
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
9
|
+
class A
|
10
|
+
# @param [String] a
|
11
|
+
# @param [Integer] b The b
|
12
|
+
Value(:a, :b)
|
13
|
+
end
|
14
|
+
EOS
|
15
|
+
YARD::Registry.at('A').mixins(:instance)
|
16
|
+
end
|
17
|
+
|
18
|
+
expect 'Represents As.' do
|
19
|
+
YARD::Registry.clear
|
20
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
21
|
+
class A
|
22
|
+
# Represents As.
|
23
|
+
Value(:a, :b)
|
24
|
+
end
|
25
|
+
EOS
|
26
|
+
YARD::Registry.at('A#initialize').docstring
|
27
|
+
end
|
28
|
+
|
29
|
+
expect [['a', nil], ['b', '3']] do
|
30
|
+
YARD::Registry.clear
|
31
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
32
|
+
class A
|
33
|
+
Value(:a, [:b, 3])
|
34
|
+
end
|
35
|
+
EOS
|
36
|
+
YARD::Registry.at('A#initialize').parameters
|
37
|
+
end
|
38
|
+
|
39
|
+
expect [:b, :initialize] do
|
40
|
+
YARD::Registry.clear
|
41
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
42
|
+
class A
|
43
|
+
# @param [String] a
|
44
|
+
# @param [Integer] b The b
|
45
|
+
Value(:a, :b)
|
46
|
+
end
|
47
|
+
EOS
|
48
|
+
YARD::Registry.all(:method).map(&:name).sort
|
49
|
+
end
|
50
|
+
|
51
|
+
expect [:b, :initialize] do
|
52
|
+
YARD::Registry.clear
|
53
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
54
|
+
class A
|
55
|
+
# @param [String] a
|
56
|
+
# @param [Integer] *b The b
|
57
|
+
Value(:a, :'*b')
|
58
|
+
end
|
59
|
+
EOS
|
60
|
+
YARD::Registry.all(:method).map(&:name).sort
|
61
|
+
end
|
62
|
+
|
63
|
+
expect [:b, :initialize] do
|
64
|
+
YARD::Registry.clear
|
65
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
66
|
+
class A
|
67
|
+
# @param [String] a
|
68
|
+
# @param [Integer] &b The b
|
69
|
+
Value(:a, :'&b')
|
70
|
+
end
|
71
|
+
EOS
|
72
|
+
YARD::Registry.all(:method).map(&:name).sort
|
73
|
+
end
|
74
|
+
|
75
|
+
expect nil do
|
76
|
+
YARD::Registry.clear
|
77
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
78
|
+
class A
|
79
|
+
# @param [String] a
|
80
|
+
# @param [Integer] b The b
|
81
|
+
Value(:a, :b)
|
82
|
+
end
|
83
|
+
EOS
|
84
|
+
YARD::Registry.at('A#a')
|
85
|
+
end
|
86
|
+
|
87
|
+
expect '@return [Integer] The b' do
|
88
|
+
YARD::Registry.clear
|
89
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
90
|
+
class A
|
91
|
+
# @param [String] a
|
92
|
+
# @param [Integer] b The b
|
93
|
+
Value(:a, :b)
|
94
|
+
end
|
95
|
+
EOS
|
96
|
+
YARD::Registry.at('A#b').docstring.to_raw
|
97
|
+
end
|
98
|
+
|
99
|
+
expect %w'Value Value::Comparable Comparable' do
|
100
|
+
YARD::Registry.clear
|
101
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
102
|
+
class A
|
103
|
+
# @param [String] a
|
104
|
+
Value(:a, :comparable => true)
|
105
|
+
end
|
106
|
+
EOS
|
107
|
+
YARD::Registry.at('A').inheritance_tree(true)[1..3].map(&:path)
|
108
|
+
end
|
109
|
+
|
110
|
+
expect %w'Value Value::Comparable Comparable' do
|
111
|
+
YARD::Registry.clear
|
112
|
+
YARD::Parser::SourceParser.parse_string(<<EOS)
|
113
|
+
module A
|
114
|
+
# @param [String] a
|
115
|
+
Value(:a, :comparable => true)
|
116
|
+
end
|
117
|
+
class B
|
118
|
+
include A
|
119
|
+
# @param [String] a
|
120
|
+
# @param [String] b
|
121
|
+
Value(:a, :b, :comparable => true)
|
122
|
+
end
|
123
|
+
EOS
|
124
|
+
YARD::Registry.at('B').inheritance_tree(true)[1..3].map(&:path)
|
125
|
+
end
|
126
|
+
end
|
data/test/unit/value.rb
CHANGED
@@ -1,82 +1,178 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
Expectations do
|
4
|
-
expect
|
5
|
-
Class.new(
|
4
|
+
expect ArgumentError.new('wrong number of arguments (0 for 1)') do
|
5
|
+
Class.new{ Value(:a) }.new
|
6
6
|
end
|
7
7
|
|
8
|
-
expect
|
9
|
-
Class.new
|
8
|
+
expect ArgumentError.new('wrong number of arguments (2 for 1)') do
|
9
|
+
Class.new{ Value(:a) }.new(1, 2)
|
10
10
|
end
|
11
11
|
|
12
|
-
expect
|
13
|
-
Class.new
|
12
|
+
expect Value do
|
13
|
+
Class.new{ Value(:a) }.new(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
expect NoMethodError do
|
17
|
+
Class.new{ Value(:a) }.new(1).a
|
18
|
+
end
|
19
|
+
|
20
|
+
expect 1 do
|
21
|
+
Class.new{ Value(:a) }.new(1).instance_eval{ a }
|
22
|
+
end
|
23
|
+
|
24
|
+
expect 1 do
|
25
|
+
Class.new{ Value(:a) }.new(1).instance_variable_get(:@a)
|
26
|
+
end
|
27
|
+
|
28
|
+
expect [] do
|
29
|
+
Class.new{ Value(:'*a') }.new.instance_eval{ a }
|
30
|
+
end
|
31
|
+
|
32
|
+
expect [1, 2, 3] do
|
33
|
+
Class.new{ Value(:'*a') }.new(1, 2, 3).instance_eval{ a }
|
14
34
|
end
|
15
35
|
|
16
36
|
expect ArgumentError.new('wrong number of arguments (0 for 1)') do
|
17
|
-
Class.new
|
37
|
+
Class.new{ Value(:a, :'*b') }.new
|
18
38
|
end
|
19
39
|
|
20
|
-
expect
|
21
|
-
Class.new
|
40
|
+
expect 1 do
|
41
|
+
Class.new{ Value(:a, :'*b') }.new(1).instance_eval{ a }
|
22
42
|
end
|
23
43
|
|
24
|
-
expect
|
25
|
-
|
44
|
+
expect [] do
|
45
|
+
Class.new{ Value(:a, :'*b', :'&c') }.new(1).instance_eval{ b }
|
26
46
|
end
|
27
47
|
|
28
|
-
expect
|
29
|
-
Class.new
|
48
|
+
expect 1 do
|
49
|
+
Class.new{ Value(:a, :'*b') }.new(1, 2, 3).instance_eval{ a }
|
30
50
|
end
|
31
51
|
|
32
|
-
expect
|
33
|
-
Class.new
|
52
|
+
expect [2, 3] do
|
53
|
+
Class.new{ Value(:a, :'*b') }.new(1, 2, 3).instance_eval{ b }
|
54
|
+
end
|
55
|
+
|
56
|
+
expect nil do
|
57
|
+
Class.new{ Value(:'&a') }.new.instance_eval{ a }
|
58
|
+
end
|
59
|
+
|
60
|
+
expect 1 do
|
61
|
+
Class.new{ Value(:'&a') }.new{ 1 }.instance_eval{ a.call }
|
34
62
|
end
|
35
63
|
|
36
64
|
expect 1 do
|
37
|
-
Class.new
|
65
|
+
Class.new{ Value(:a, :'&b') }.new(1).instance_eval{ a }
|
66
|
+
end
|
67
|
+
|
68
|
+
expect nil do
|
69
|
+
Class.new{ Value(:a, :'&b') }.new(1).instance_eval{ b }
|
70
|
+
end
|
71
|
+
|
72
|
+
expect 1 do
|
73
|
+
Class.new{ Value(:a, :'&b') }.new(1){ 2 }.instance_eval{ a }
|
74
|
+
end
|
75
|
+
|
76
|
+
expect 2 do
|
77
|
+
Class.new{ Value(:a, :'&b') }.new(1){ 2 }.instance_eval{ b.call }
|
38
78
|
end
|
39
79
|
|
40
80
|
expect 1 do
|
41
|
-
Class.new
|
81
|
+
Class.new{ Value(:a, :'*b', :'&c') }.new(1).instance_eval{ a }
|
82
|
+
end
|
83
|
+
|
84
|
+
expect [] do
|
85
|
+
Class.new{ Value(:a, :'*b', :'&c') }.new(1).instance_eval{ b }
|
86
|
+
end
|
87
|
+
|
88
|
+
expect nil do
|
89
|
+
Class.new{ Value(:a, :'*b', :'&c') }.new(1).instance_eval{ c }
|
90
|
+
end
|
91
|
+
|
92
|
+
expect 1 do
|
93
|
+
Class.new{ Value(:a, :'*b', :'&c') }.new(1, 2, 3){ 4 }.instance_eval{ a }
|
94
|
+
end
|
95
|
+
|
96
|
+
expect [2, 3] do
|
97
|
+
Class.new{ Value(:a, :'*b', :'&c') }.new(1, 2, 3){ 4 }.instance_eval{ b }
|
98
|
+
end
|
99
|
+
|
100
|
+
expect 4 do
|
101
|
+
Class.new{ Value(:a, :'*b', :'&c') }.new(1, 2, 3){ 4 }.instance_eval{ c.call }
|
102
|
+
end
|
103
|
+
|
104
|
+
expect ArgumentError.new('wrong number of arguments (0 for 1)') do
|
105
|
+
Class.new{ Value(:a, [:b, 2]) }.new
|
106
|
+
end
|
107
|
+
|
108
|
+
expect 1 do
|
109
|
+
Class.new{ Value(:a, [:b, 2]) }.new(1).instance_eval{ a }
|
110
|
+
end
|
111
|
+
|
112
|
+
expect 2 do
|
113
|
+
Class.new{ Value(:a, [:b, 2]) }.new(1).instance_eval{ b }
|
114
|
+
end
|
115
|
+
|
116
|
+
expect ArgumentError.new('wrong number of arguments (3 for 2)') do
|
117
|
+
Class.new{ Value(:a, [:b, 2]) }.new(1, 2, 3)
|
118
|
+
end
|
119
|
+
|
120
|
+
expect 1 do
|
121
|
+
Class.new{ Value(:a, [:b, 2], :'*c') }.new(1, 4, 2).instance_eval{ a }
|
122
|
+
end
|
123
|
+
|
124
|
+
expect 4 do
|
125
|
+
Class.new{ Value(:a, [:b, 2], :'*c') }.new(1, 4, 2).instance_eval{ b }
|
126
|
+
end
|
127
|
+
|
128
|
+
expect [2] do
|
129
|
+
Class.new{ Value(:a, [:b, 2], :'*c') }.new(1, 4, 2).instance_eval{ c }
|
42
130
|
end
|
43
131
|
|
44
132
|
expect true do
|
45
|
-
c = Class.new
|
133
|
+
c = Class.new{ Value(:a, :b, :c) }
|
46
134
|
c.new(1, 2, 3) == c.new(1, 2, 3)
|
47
135
|
end
|
48
136
|
|
49
137
|
expect false do
|
50
|
-
c = Class.new
|
138
|
+
c = Class.new{ Value(:a, :b, :c) }
|
51
139
|
c.new(1, 2, 3) == c.new(2, 3, 1)
|
52
140
|
end
|
53
141
|
|
54
142
|
expect true do
|
55
|
-
c = Class.new
|
143
|
+
c = Class.new{ Value(:a, :b, :c) }
|
56
144
|
c.new(1, 2, 3).eql? c.new(1, 2, 3)
|
57
145
|
end
|
58
146
|
|
59
147
|
expect false do
|
60
|
-
c = Class.new
|
148
|
+
c = Class.new{ Value(:a, :b, :c) }
|
61
149
|
c.new(1, 2, 3).eql? c.new(2, 3, 1)
|
62
150
|
end
|
63
151
|
|
64
152
|
expect true do
|
65
|
-
c = Class.new
|
153
|
+
c = Class.new{ Value(:a, :b, :c) }
|
66
154
|
c.new(1, 2, 3).hash == c.new(1, 2, 3).hash
|
67
155
|
end
|
68
156
|
|
69
157
|
expect false do
|
70
|
-
c = Class.new
|
158
|
+
c = Class.new{ Value(:a, :b, :c) }
|
71
159
|
c.new(1, 2, 3).hash == c.new(2, 3, 1).hash
|
72
160
|
end
|
73
161
|
|
74
162
|
expect false do
|
75
|
-
c = Class.new
|
163
|
+
c = Class.new{ Value(:a, :b, :c) }
|
76
164
|
c.new(1, 2, 3).hash == [1, 2, 3].hash
|
77
165
|
end
|
78
166
|
|
79
167
|
expect(/\A#<Class:0x[[:xdigit:]]+>\.new\(1, 2, 3\)\z/) do
|
80
|
-
Class.new
|
168
|
+
Class.new{ Value(:a, :b, :c) }.new(1, 2, 3).inspect
|
169
|
+
end
|
170
|
+
|
171
|
+
expect 1 do
|
172
|
+
Class.new{ include Module.new{ Value(:a) } }.new(1).instance_eval{ a }
|
173
|
+
end
|
174
|
+
|
175
|
+
expect [Value, Value::Comparable, Comparable] do
|
176
|
+
Class.new{ Value(:a, :comparable => true) }.ancestors[1..3]
|
81
177
|
end
|
82
178
|
end
|
metadata
CHANGED
@@ -1,117 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: value
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Nikolai Weibull
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
name: lookout
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-04-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yard
|
16
|
+
requirement: &2152363560 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
18
|
+
requirements:
|
27
19
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 0
|
33
|
-
version: "2.0"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.7.0
|
34
22
|
type: :development
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rbtags
|
38
23
|
prerelease: false
|
39
|
-
|
24
|
+
version_requirements: *2152363560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: inventory
|
27
|
+
requirement: &2152363060 !ruby/object:Gem::Requirement
|
40
28
|
none: false
|
41
|
-
requirements:
|
29
|
+
requirements:
|
42
30
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
|
46
|
-
- 0
|
47
|
-
- 1
|
48
|
-
- 0
|
49
|
-
version: 0.1.0
|
50
|
-
type: :development
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: yard
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.2.0
|
33
|
+
type: :runtime
|
54
34
|
prerelease: false
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 3
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
- 7
|
64
|
-
- 0
|
65
|
-
version: 0.7.0
|
66
|
-
type: :development
|
67
|
-
version_requirements: *id003
|
68
|
-
description: " Value\n\n Value is a library for defining value objects in Ruby.\n"
|
35
|
+
version_requirements: *2152363060
|
36
|
+
description: ! " Value\n\n Value is a library
|
37
|
+
for defining value objects in Ruby.\n"
|
69
38
|
email: now@bitwi.se
|
70
39
|
executables: []
|
71
|
-
|
72
40
|
extensions: []
|
73
|
-
|
74
41
|
extra_rdoc_files: []
|
75
|
-
|
76
|
-
|
77
|
-
- lib/value/
|
42
|
+
files:
|
43
|
+
- lib/value/comparable.rb
|
44
|
+
- lib/value/values.rb
|
78
45
|
- lib/value.rb
|
46
|
+
- lib/value/version.rb
|
47
|
+
- lib/value/yard.rb
|
48
|
+
- test/unit/value/comparable.rb
|
49
|
+
- test/unit/value/values.rb
|
79
50
|
- test/unit/value.rb
|
51
|
+
- test/unit/value/version.rb
|
52
|
+
- test/unit/value/yard.rb
|
80
53
|
- README
|
81
54
|
- Rakefile
|
82
|
-
|
83
|
-
homepage: http://github.com/now/value
|
55
|
+
homepage: https://github.com/now/value
|
84
56
|
licenses: []
|
85
|
-
|
86
57
|
post_install_message:
|
87
58
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
59
|
+
require_paths:
|
90
60
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
62
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
|
97
|
-
|
98
|
-
- 0
|
99
|
-
version: "0"
|
100
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
68
|
none: false
|
102
|
-
requirements:
|
103
|
-
- -
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
version: "0"
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
109
73
|
requirements: []
|
110
|
-
|
111
74
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.8.11
|
113
76
|
signing_key:
|
114
77
|
specification_version: 3
|
115
78
|
summary: Value is a library for defining value objects in Ruby.
|
116
79
|
test_files: []
|
117
|
-
|