diva 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/diva/combinator.rb +66 -0
- data/lib/diva/model.rb +2 -0
- data/lib/diva/type.rb +10 -4
- data/lib/diva/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc21e64173564102b7a3da104909d3a1742e5c58
|
4
|
+
data.tar.gz: 0c826bb45017d63bde247bc292e775e04b17b9fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17bdfd00b4008192e9b859276a9684b5a3b475d6dde53f2e94b8845236373f95f66fdda5db0410fe29cb19acfb4bbffc3239809f423005ee4c104072a8d0bebd
|
7
|
+
data.tar.gz: 534176c4015edc96efc3714c004692084cd49e78b94e4be8541c755a7fa855823ccba4d88c39cf70c9f2f8a4d82e3629699c3c797abf18e7014d37c5341144af
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Diva::Combinable
|
4
|
+
class Combinator
|
5
|
+
def initialize(a, b)
|
6
|
+
@a, @b = a, b
|
7
|
+
end
|
8
|
+
|
9
|
+
# コンストラクタに渡された二つの値が _behavior_ をサポートしていれば真を返す
|
10
|
+
# ==== Args
|
11
|
+
# [behavior] 想定する振る舞い(Symbol)
|
12
|
+
# ==== Return
|
13
|
+
# true or false
|
14
|
+
def =~(behavior)
|
15
|
+
@a.respond_to?(behavior) && @a.__send__(behavior, @b) || @b.respond_to?(behavior) && @b.__send__(behavior, @a)
|
16
|
+
end
|
17
|
+
alias_method :===, :=~
|
18
|
+
|
19
|
+
# このCombinatorが持っている値のすべての組み合わせのうち、適切に _behavior_
|
20
|
+
# をサポートしている組み合わせについて繰り返すEnumeratorを返す
|
21
|
+
# ==== Args
|
22
|
+
# [behavior] 想定する振る舞い(Symbol)
|
23
|
+
# ==== Return
|
24
|
+
# [レシーバ, 引数] のペアを列挙するEnumerator
|
25
|
+
def enum(behavior)
|
26
|
+
Enumerator.new do |yielder|
|
27
|
+
yielder << [@a, @b] if @a.respond_to?(behavior) && @a.__send__(behavior, @b)
|
28
|
+
yielder << [@b, @a] if @b.respond_to?(behavior) && @b.__send__(behavior, @a)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_missing(behavior, *rest)
|
33
|
+
if rest.empty?
|
34
|
+
return self =~ behavior
|
35
|
+
end
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class EnumerableCombinator < Combinator
|
41
|
+
def =~(behavior)
|
42
|
+
@b.any?{|b| !enum(behavior).empty? }
|
43
|
+
end
|
44
|
+
|
45
|
+
def enum(behavior)
|
46
|
+
Enumerator.new do |yielder|
|
47
|
+
@b.each do |b|
|
48
|
+
(@a | b).enum(behavior).each(&yielder.method(:<<))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# _other_ との Diva::Conbinable::Combinator を生成する
|
55
|
+
# ==== Args
|
56
|
+
# [other] Diva::Modelか、Diva::Modelを列挙するEnumerable
|
57
|
+
# ==== Return
|
58
|
+
# Diva::Conbinable::Combinator
|
59
|
+
def |(other)
|
60
|
+
if other.is_a? Enumerable
|
61
|
+
EnumerableCombinator.new(self, other)
|
62
|
+
else
|
63
|
+
Combinator.new(self, other)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/diva/model.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
いろんなリソースの基底クラス
|
4
4
|
=end
|
5
5
|
|
6
|
+
require 'diva/combinator'
|
6
7
|
require 'diva/model_extend'
|
7
8
|
require 'diva/uri'
|
8
9
|
require 'diva/spec'
|
@@ -11,6 +12,7 @@ require 'securerandom'
|
|
11
12
|
|
12
13
|
class Diva::Model
|
13
14
|
include Comparable
|
15
|
+
include Diva::Combinable
|
14
16
|
extend Diva::ModelExtend
|
15
17
|
|
16
18
|
def initialize(args)
|
data/lib/diva/type.rb
CHANGED
@@ -144,8 +144,14 @@ module Diva::Type
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def cast(value)
|
147
|
-
|
148
|
-
|
147
|
+
case value
|
148
|
+
when model
|
149
|
+
value
|
150
|
+
when Hash
|
151
|
+
model.new(value)
|
152
|
+
else
|
153
|
+
raise Diva::InvalidTypeError, "The value #{value.inspect} is not a `#{model}'."
|
154
|
+
end
|
149
155
|
end
|
150
156
|
|
151
157
|
def to_s
|
@@ -166,7 +172,7 @@ module Diva::Type
|
|
166
172
|
end
|
167
173
|
|
168
174
|
def to_s
|
169
|
-
"Array of #{type.to_s}"
|
175
|
+
"Array of #{@type.to_s}"
|
170
176
|
end
|
171
177
|
end
|
172
178
|
|
@@ -185,7 +191,7 @@ module Diva::Type
|
|
185
191
|
end
|
186
192
|
|
187
193
|
def to_s
|
188
|
-
"#{type.to_s}|nil"
|
194
|
+
"#{@type.to_s}|nil"
|
189
195
|
end
|
190
196
|
end
|
191
197
|
|
data/lib/diva/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diva
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshiaki Asai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- bin/setup
|
118
118
|
- diva.gemspec
|
119
119
|
- lib/diva.rb
|
120
|
+
- lib/diva/combinator.rb
|
120
121
|
- lib/diva/datasource.rb
|
121
122
|
- lib/diva/error.rb
|
122
123
|
- lib/diva/field.rb
|
@@ -147,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
version: '0'
|
148
149
|
requirements: []
|
149
150
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.6.
|
151
|
+
rubygems_version: 2.6.11
|
151
152
|
signing_key:
|
152
153
|
specification_version: 4
|
153
154
|
summary: Implementation of expression for handling things.
|