datory 1.0.0.rc5 → 1.0.0.rc6

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
  SHA256:
3
- metadata.gz: 6f0d3dcd343bb011dc9a4f364a9d62b14deaa0920c48495a48c36ed23d08143e
4
- data.tar.gz: c299b7365488894f8467c094f3e11445fde073eab82b14d45ff63c284a98f67f
3
+ metadata.gz: 36c9c3d73db41d95c3d5bafd98df4bb5002ea1f36cacc7fafa808ccb9f8af8d7
4
+ data.tar.gz: 56304b66db42d82a4b143711f1192df86f3139979711a0a9c4d6bf6be7f95d85
5
5
  SHA512:
6
- metadata.gz: b7a458af89e5be1b6ca35f1064da7deb50a8da75751cce60d4c7bf5b93cc559c20ab6ea13156667e2be8e0d984ebebef82c2bc1a08f5c2f6fc7bccca9d9d6dfd
7
- data.tar.gz: abaf617dcbcaf4d8e6661cca45fb39ec17d1f69f656f2afc85ee42ccf3beb197c56c60acc07a82d0818d4a5af425b8b2e080bbdecf76815fadb966d08ed70706
6
+ metadata.gz: 7a741dd5da9f0ad4782c101ce76c1063668fe5c77074ff650edb23e16216dffe3bceb7b049b13301a06a6ac4de37156da84b3ebc3754297bf2509ef9cb09195e
7
+ data.tar.gz: ec355c7bb2073c0236d4556e6005c874987b3c513389f2efb5c64adb25de3b35f16077579c5468661e53b60a6933217be561d246031d261d8c1e5ab11be0758a
@@ -60,6 +60,11 @@ module Datory
60
60
  attribute(name, **options)
61
61
  end
62
62
 
63
+ def duration(name, **options)
64
+ options = options.merge(from: ActiveSupport::Duration)
65
+ attribute(name, **options)
66
+ end
67
+
63
68
  def date(name, **options)
64
69
  options = options.merge(from: Date)
65
70
  attribute(name, **options)
@@ -39,6 +39,8 @@ module Datory
39
39
  output_formatter.call(value: value)
40
40
  elsif [Date, Time, DateTime].include?(value.class)
41
41
  value.to_s
42
+ elsif ActiveSupport::Duration == value.class
43
+ value.iso8601
42
44
  else
43
45
  value
44
46
  end
data/lib/datory/utils.rb CHANGED
@@ -5,13 +5,14 @@ module Datory
5
5
  module_function
6
6
 
7
7
  TRANSFORMATIONS = {
8
- Date => ->(value) { Date.parse(value) },
9
- Time => ->(value) { Time.parse(value) },
10
- DateTime => ->(value) { DateTime.parse(value) },
11
8
  Symbol => ->(value) { value.to_sym },
12
9
  String => ->(value) { value.to_s },
13
10
  Integer => ->(value) { value.to_i },
14
- Float => ->(value) { value.to_f }
11
+ Float => ->(value) { value.to_f },
12
+ Date => ->(value) { Date.parse(value) },
13
+ Time => ->(value) { Time.parse(value) },
14
+ DateTime => ->(value) { DateTime.parse(value) },
15
+ ActiveSupport::Duration => ->(value) { ActiveSupport::Duration.parse(value) }
15
16
  }.freeze
16
17
 
17
18
  private_constant :TRANSFORMATIONS
@@ -5,7 +5,7 @@ module Datory
5
5
  MAJOR = 1
6
6
  MINOR = 0
7
7
  PATCH = 0
8
- PRE = "rc5"
8
+ PRE = "rc6"
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datory
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc5
4
+ version: 1.0.0.rc6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov