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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0db24b32e84647b7cbcc6ef866ae5e4b281586988c204db9121aa7e34b3bc00b
4
- data.tar.gz: de8cd6aff8fed30f62691433931fb20dab2f7d759f985969753f2615687f073d
3
+ metadata.gz: c6375eeb97c6ac8c0ea36b6be0b5281b4ffeceb5fa6fa591f4aab7c801240fcc
4
+ data.tar.gz: 903145e001fb0ddd6a4dff5f7cf9a9e0583e9d2242a1b00283e1a3de3d5a03ce
5
5
  SHA512:
6
- metadata.gz: a17683c42b4660c9c4b10c22566d33043b1fbf2e38ada33966520b69ff5ce64f7f420e992379b3db2f0d301d467afa69ff965bec42c184a09b466b686db5749e
7
- data.tar.gz: 4d5c02063938b9573efccfabf454ac733f6fbbcd916722ef6b923d8a9c70bb466d85c2dc2a9d3216fdc3a1e6c7463ada8cdf2b8740e82a5f967c1bae64039fcc
6
+ metadata.gz: 9598d8bc00e29c9adbf8b1d9323dcd02a2dc7aa54ae6d6a25ccc61ab5ffdc9dc1f0c8a390732bf6a1a8181b287fbee5a11c2c4b399b6cc81871276c374391baf
7
+ data.tar.gz: 74813535d8ec8248ee87e0ce2aa500a3e85722a0ad06b310b8de62d50fadc1819cd914046b04c4a0bd9fc6e76217de62510fa9a7af60ebe63d80c2b7e9fdd63b
@@ -10,25 +10,52 @@ module Montrose
10
10
  class Schedule
11
11
  attr_accessor :rules
12
12
 
13
- # Instantiates a schedule and yields the instance to an optional
14
- # block for building recurrences inline
15
- #
16
- # @example Build a schedule with multiple rules added in the given block
17
- # schedule = Montrose::Schedule.build do |s|
18
- # s << { every: :day }
19
- # s << { every: :year }
20
- # end
21
- #
22
- # @return [Montrose::Schedule]
23
- #
24
- def self.build
25
- schedule = new
26
- yield schedule if block_given?
27
- schedule
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Montrose
4
- VERSION = "0.10.0"
4
+ VERSION = "0.10.1"
5
5
  end
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.0
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-18 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport