montrose 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/montrose/schedule.rb +48 -17
- data/lib/montrose/version.rb +1 -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: c6375eeb97c6ac8c0ea36b6be0b5281b4ffeceb5fa6fa591f4aab7c801240fcc
|
4
|
+
data.tar.gz: 903145e001fb0ddd6a4dff5f7cf9a9e0583e9d2242a1b00283e1a3de3d5a03ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9598d8bc00e29c9adbf8b1d9323dcd02a2dc7aa54ae6d6a25ccc61ab5ffdc9dc1f0c8a390732bf6a1a8181b287fbee5a11c2c4b399b6cc81871276c374391baf
|
7
|
+
data.tar.gz: 74813535d8ec8248ee87e0ce2aa500a3e85722a0ad06b310b8de62d50fadc1819cd914046b04c4a0bd9fc6e76217de62510fa9a7af60ebe63d80c2b7e9fdd63b
|
data/lib/montrose/schedule.rb
CHANGED
@@ -10,25 +10,52 @@ module Montrose
|
|
10
10
|
class Schedule
|
11
11
|
attr_accessor :rules
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
class << self
|
14
|
+
# Instantiates a schedule and yields the instance to an optional
|
15
|
+
# block for building recurrences inline
|
16
|
+
#
|
17
|
+
# @example Build a schedule with multiple rules added in the given block
|
18
|
+
# schedule = Montrose::Schedule.build do |s|
|
19
|
+
# s << { every: :day }
|
20
|
+
# s << { every: :year }
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# @return [Montrose::Schedule]
|
24
|
+
#
|
25
|
+
def build
|
26
|
+
schedule = new
|
27
|
+
yield schedule if block_given?
|
28
|
+
schedule
|
29
|
+
end
|
30
|
+
|
31
|
+
def dump(obj)
|
32
|
+
return nil if obj.nil?
|
33
|
+
return dump(load(obj)) if obj.is_a?(String)
|
34
|
+
|
35
|
+
array = case obj
|
36
|
+
when Array
|
37
|
+
new(obj).to_a
|
38
|
+
when self
|
39
|
+
obj.to_a
|
40
|
+
else
|
41
|
+
fail SerializationError,
|
42
|
+
"Object was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
|
43
|
+
end
|
44
|
+
|
45
|
+
JSON.dump(array)
|
46
|
+
end
|
47
|
+
|
48
|
+
def load(json)
|
49
|
+
return nil if json.blank?
|
50
|
+
|
51
|
+
new JSON.parse(json)
|
52
|
+
rescue JSON::ParserError => e
|
53
|
+
fail SerializationError, "Could not parse JSON: #{e}"
|
54
|
+
end
|
28
55
|
end
|
29
56
|
|
30
|
-
def initialize
|
31
|
-
@rules =
|
57
|
+
def initialize(rules = [])
|
58
|
+
@rules = rules.map { |rule| Montrose::Recurrence.new(rule) }
|
32
59
|
end
|
33
60
|
|
34
61
|
# Add a recurrence rule to the schedule, either by hash or recurrence
|
@@ -79,6 +106,10 @@ module Montrose
|
|
79
106
|
end
|
80
107
|
end
|
81
108
|
|
109
|
+
def to_a
|
110
|
+
@rules.map(&:to_hash)
|
111
|
+
end
|
112
|
+
|
82
113
|
private
|
83
114
|
|
84
115
|
def active_enums(enums)
|
data/lib/montrose/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: montrose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ross Kaffenberger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|