diva 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32c42c53cdc1c9bbdcaca44be78cb1802a4a8c2d
4
- data.tar.gz: 5a82b7d204e5d1da8b4be122b5a760d218ee4f18
3
+ metadata.gz: bbd71e6eab2ac33b0889772975d9eca73bc410b4
4
+ data.tar.gz: 9b22e2df9cef290b873554f511266cbd844cbebc
5
5
  SHA512:
6
- metadata.gz: adbe743fa2579e3575623f0923e33f25b2e8ecf1dfab8ffdd8b0cd994d2416642d264af978e48b2a0f43add06d2d2739fc4415cfe0c1ed20d7b9e6b386e40d20
7
- data.tar.gz: 175d0fb4142c27b823862135330f73e2969f8be74e6abc4977d10c035ed6492fe0192b57da6ee8add473b3d7a794abf56207e1f21ff80945122c1060c89cfdb1
6
+ metadata.gz: 5f13d1159a00b3476b2ce4718a11d3dda0cd037210bab256d3d6b2e32aa0fcd71afc2b3366446b538ba867b0a907411f91f54f45a722cfe17f723a80fd0c1bd9
7
+ data.tar.gz: 60a7677cbba7d4716b7246428c36b9b27e15ad9a4fc7299a7eb03de2594fcb8cb6f9f5945f40f7d4a4877121e005c4c3008608ab65307ff4d095fa0f16b7f7b6
@@ -19,6 +19,10 @@ module Diva
19
19
  @required = !!required
20
20
  end
21
21
 
22
+ def dump_for_json(value)
23
+ type.dump_for_json(value)
24
+ end
25
+
22
26
  def required?
23
27
  required
24
28
  end
@@ -86,7 +86,9 @@ class Diva::Model
86
86
  end
87
87
 
88
88
  def to_json(*rest, **kwrest)
89
- to_hash.to_json(*rest, **kwrest)
89
+ Hash[
90
+ self.class.fields.map{|f| [f.name, f.dump_for_json(fetch(f.name))] }
91
+ ].to_json(*rest, **kwrest)
90
92
  end
91
93
 
92
94
  # カラムの生の内容を返す
@@ -27,6 +27,8 @@ Diva::Modelのサブクラスであれば、それを制約とすることがで
27
27
  配列の全ての要素が設定された制約を満たしていれば、配列制約が満たされたことになる。
28
28
 
29
29
  =end
30
+ require "time"
31
+
30
32
  module Diva::Type
31
33
  extend self
32
34
 
@@ -61,6 +63,10 @@ module Diva::Type
61
63
  name.to_s
62
64
  end
63
65
 
66
+ def dump_for_json(value)
67
+ value
68
+ end
69
+
64
70
  def inspect
65
71
  "Diva::Type(#{to_s})"
66
72
  end
@@ -113,14 +119,19 @@ module Diva::Type
113
119
  v.to_s
114
120
  end
115
121
  end
116
- TIME = AtomicType.new(:time) do |v|
122
+ class TimeType < AtomicType
123
+ def dump_for_json(value)
124
+ cast(value).iso8601
125
+ end
126
+ end
127
+ TIME = TimeType.new(:time) do |v|
117
128
  case v
118
129
  when Time
119
130
  v
120
131
  when Integer, Float
121
132
  Time.at(v)
122
133
  when String
123
- Time.new(v)
134
+ Time.iso8601(v)
124
135
  else
125
136
  raise Diva::InvalidTypeError, "The value is not a `#{name}'."
126
137
  end
@@ -171,6 +182,10 @@ module Diva::Type
171
182
  value.to_a.map(&@type.method(:cast))
172
183
  end
173
184
 
185
+ def dump_for_json(value)
186
+ value.to_a.map(&@type.method(:dump_for_json))
187
+ end
188
+
174
189
  def to_s
175
190
  "Array of #{@type.to_s}"
176
191
  end
@@ -190,6 +205,14 @@ module Diva::Type
190
205
  end
191
206
  end
192
207
 
208
+ def dump_for_json(value)
209
+ if value.nil?
210
+ value
211
+ else
212
+ @type.dump_for_json(value)
213
+ end
214
+ end
215
+
193
216
  def to_s
194
217
  "#{@type.to_s}|nil"
195
218
  end
@@ -1,3 +1,3 @@
1
1
  module Diva
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.3.0
4
+ version: 0.3.1
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-09-30 00:00:00.000000000 Z
11
+ date: 2018-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.6.13
151
+ rubygems_version: 2.6.14
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Implementation of expression for handling things.