date_defaulter 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/date_defaulter.rb +50 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 711095d607d56c36e4b23f96773ec80b417d062c73e93fea9937be9c122f4aa5
|
4
|
+
data.tar.gz: 0f87189882a82eba28953998e3f4281e565d1d03acf0fb0f4a51b0d21369e7d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2050e365ac00045e542144a4907f287a9a5aa36e7bf9bceec147307692860b8b14f6dae4d1d64ebbe7076308347bf462957a869897c49ca34ea4ae30f615e779
|
7
|
+
data.tar.gz: bd0e39555cdc75fe4cb83fb9fe9eee10a22963cad468958173de78fcf4524e3eee088f29ee9fcc24733199964e85d4c7d518b14763aceff72bb2cba5e0709c89
|
data/lib/date_defaulter.rb
CHANGED
@@ -1,7 +1,56 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
|
+
module DateDefaulter
|
4
|
+
@@config = {}
|
5
|
+
|
6
|
+
class Configuration
|
7
|
+
@@instance = Configuration.new
|
8
|
+
|
9
|
+
attr_accessor :format
|
10
|
+
|
11
|
+
private_class_method :new
|
12
|
+
|
13
|
+
def self.instance
|
14
|
+
@@instance
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def configuration
|
21
|
+
Configuration.instance.tap do |configuration|
|
22
|
+
yield configuration if block_given?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def format
|
27
|
+
configuration.format
|
28
|
+
end
|
29
|
+
|
30
|
+
def format=(format)
|
31
|
+
configuration.format = format
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
3
35
|
class Date
|
36
|
+
alias_method :date_defaulter_strftime, :strftime
|
37
|
+
alias_method :date_defaulter_to_s, :to_s
|
38
|
+
|
4
39
|
def to_s
|
5
|
-
|
40
|
+
if DateDefaulter.format.nil?
|
41
|
+
date_defaulter_to_s
|
42
|
+
else
|
43
|
+
strftime(DateDefaulter.format)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def strftime(*args)
|
48
|
+
return date_defaulter_strftime(*args) if args.any?
|
49
|
+
|
50
|
+
if DateDefaulter.format.nil?
|
51
|
+
date_defaulter_strftime
|
52
|
+
else
|
53
|
+
date_defaulter_strftime(DateDefaulter.format)
|
54
|
+
end
|
6
55
|
end
|
7
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_defaulter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shkumbin Delija
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|