glue_gun_dsl 0.1.4 → 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: 87d462fd4e0019174b6d06d77c582e67dfd16ddb64e65a3ccb7cf176bdd18f22
4
- data.tar.gz: f067c0c223ad8a3fafc76fe74a9e42b4abdf6978b219f32d58108ef8bc278e5e
3
+ metadata.gz: b1f17db06be196fb63b2941e0ba636af749f6ccbff64bf4032311b05db781739
4
+ data.tar.gz: e240a34a00b9417f5051a100daa614d14df500c15ccd805e60be0c4410d6aca2
5
5
  SHA512:
6
- metadata.gz: 6433593537948d2bf7cda82c8f0d0cdc0b2883c8584f4e0447ccedf32353b3f57c400ce904d97cedf34b1929d0fdcb044da80390b1845d7536292ab390efc80d
7
- data.tar.gz: 443140a736857306a802c2058b657b793b4a102ec8d06151853a2d18c0fbbccff40c67b24743321f2b152dd9895c2b155c34ba483112e2e03927814c3d50ed1b
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
@@ -5,5 +5,11 @@ module GlueGun
5
5
 
6
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.4"
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.4
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