glue_gun_dsl 0.1.3 → 0.1.5

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: e97baa6c4e171ff7016d72e17e6aa8bbaac29f1787334e2adf179286e6e3acab
4
- data.tar.gz: bf07da1a28c264674715852b26548c82b91c8a752079ce81ab463dddf33dd54c
3
+ metadata.gz: b1f17db06be196fb63b2941e0ba636af749f6ccbff64bf4032311b05db781739
4
+ data.tar.gz: e240a34a00b9417f5051a100daa614d14df500c15ccd805e60be0c4410d6aca2
5
5
  SHA512:
6
- metadata.gz: 773d89754959c7bcdc8aa211e52ba5f62d51803388bbf0938081efea5acbb0eba69fae543a5ef9b41315018fcaa530a2f709e78afe89615f57c85912848fc2e3
7
- data.tar.gz: c85ffa384466da228d4442b303db20bd07ae83262981b24b10675d67eaca168f7bdf6a14f88ee617c780402086b10677fc0302b8d08096851bfbcebb5294a2bf
6
+ metadata.gz: 74168264b965a8bc8174d638a9151d87669cdb004d548c08261b231dc67e0101e4a67f6a85d7025e82f5c47c04a8b9dc7fa6bf7a71f6857a2a96e3d0455ff1bd
7
+ data.tar.gz: fd61db3f0571df81e06c019a2da1f811145c3238201c0e0d4f3b6130d7faa11402322ba611f7cb0d2c4543ed84ea11bd402b8b0fd3789a859d24e39dd677d440
@@ -0,0 +1,26 @@
1
+ module GlueGun
2
+ module Types
3
+ class DateTimeType < ActiveModel::Type::Value
4
+ def cast(value)
5
+ case value
6
+ when String
7
+ parse_string(value)
8
+ when Date, DateTime
9
+ value
10
+ end
11
+ end
12
+
13
+ def serialize(value)
14
+ value.to_s
15
+ end
16
+
17
+ private
18
+
19
+ def parse_string(value)
20
+ DateTime.parse(value).utc
21
+ rescue ArgumentError
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module GlueGun
2
+ module Types
3
+ class DateType < ActiveModel::Type::Value
4
+ def cast(value)
5
+ case value
6
+ when String
7
+ parse_string(value).to_date
8
+ when Date, DateTime
9
+ value.to_date
10
+ end
11
+ end
12
+
13
+ def serialize(value)
14
+ value.to_s
15
+ end
16
+
17
+ private
18
+
19
+ def parse_string(value)
20
+ DateTime.parse(value).utc
21
+ rescue ArgumentError
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,9 +1,15 @@
1
1
  module GlueGun
2
2
  module Types
3
- require_relative "glue_gun/types/hash_type"
3
+ require_relative "types/hash_type"
4
4
  ActiveModel::Type.register(:hash, GlueGun::Types::HashType)
5
5
 
6
- require_relative "glue_gun/types/array_type"
6
+ require_relative "types/array_type"
7
7
  ActiveModel::Type.register(:array, GlueGun::Types::ArrayType)
8
+
9
+ require_relative "types/date_type"
10
+ ActiveModel::Type.register(:date, GlueGun::Types::DateType)
11
+
12
+ require_relative "types/date_time_type"
13
+ ActiveModel::Type.register(:datetime, GlueGun::Types::DateTimeType)
8
14
  end
9
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GlueGun
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/glue_gun.rb CHANGED
@@ -2,6 +2,7 @@ require "active_model"
2
2
  require "active_support/concern"
3
3
 
4
4
  module GlueGun
5
+ require_relative "glue_gun/version"
5
6
  require_relative "glue_gun/types"
6
7
  require_relative "glue_gun/dsl"
7
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glue_gun_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Shollenberger
@@ -131,6 +131,8 @@ files:
131
131
  - lib/glue_gun/dsl.rb
132
132
  - lib/glue_gun/types.rb
133
133
  - lib/glue_gun/types/array_type.rb
134
+ - lib/glue_gun/types/date_time_type.rb
135
+ - lib/glue_gun/types/date_type.rb
134
136
  - lib/glue_gun/types/hash_type.rb
135
137
  - lib/glue_gun/version.rb
136
138
  homepage: https://github.com/brettshollenberger/glue_gun