day_planner 0.0.3.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba232608de836dc7719d47a3e0f78cf666bf2959
4
- data.tar.gz: 27f627cf08e43c49920dc264b08e68515bd57b49
3
+ metadata.gz: 087bf6c25abf28aae91daf4a2cc5588124c39ec0
4
+ data.tar.gz: ab0a8bd20205d887eed7284d2fb0525ec3f5acb6
5
5
  SHA512:
6
- metadata.gz: c5b6e762927a4d64dc2b1787fc77af13c43a45cc70235a19d94e3523491b7eff1272dff13f1f795e4e3deffc3d409181f20cd06c268b212cfe399d05525f76c2
7
- data.tar.gz: 08ab525349d6e9b54a840c6e86ddd95b0f6e380604fdc1dcb76de2ec2f0a2223d6eefd2494437f77cea215544e9a58570f314d1b4281e11452c0cb289d52a630
6
+ metadata.gz: 146334ddc8585204defae81055d90a9887a85014551cde59ed15b10a80718e553cf4b676c559f99203fee1d9abbf5ceb172aa40c14a1abce43b3b8c0b45875a9
7
+ data.tar.gz: f2a6f37630a0c7209903ca18d201ba23666bcde53d44c9978c4aa7434c9a1d2bb408eef3e7143e9bcbce411c0c31b7c8f53909ff7f89fbd6d2b95a7b1da540a9
data/README.md CHANGED
@@ -52,6 +52,19 @@ Specify your preferred interval (and whatever other goodies may be waiting in th
52
52
 
53
53
  I sort of think it might work without Rails, keeping in mind the various aforementioned caveats? I'm not really sure. If it totally doesn't, I'd appreciate feedback.
54
54
 
55
+ You can name a task thusly:
56
+ DayPlanner.schedule(every: 2.minutes, name: "my task") do
57
+ MyClass.my_class_method
58
+ end
59
+
60
+ If you do, you can find the task later:
61
+ DayPlanner.find_task("my task")
62
+
63
+ To cancel a task, you can either call the task's "destroy" method, or call a class method on DayPlanner:
64
+ DayPlanner.cancel(task)
65
+
66
+ You can either pass a name, if you named the task, or the task object.
67
+
55
68
  ## Contributing
56
69
 
57
70
  1. Fork it
@@ -1,5 +1,6 @@
1
1
  module DayPlanner
2
2
  @@tasks = []
3
+ @@named_tasks = {}
3
4
 
4
5
  class << self
5
6
  def tasks
@@ -12,6 +13,12 @@ module DayPlanner
12
13
  Task.new(options, &block)
13
14
  end
14
15
 
16
+ def cancel(task)
17
+ task = find_task(task) if task.is_a?(String)
18
+ raise ArgumentError, "DayPlanner couldn't find this task" if task.nil? || !task.is_a?(DayPlanner::Task)
19
+ task.destroy
20
+ end
21
+
15
22
  def activate
16
23
  @@master.kill if defined?(@@master)
17
24
 
@@ -31,6 +38,20 @@ module DayPlanner
31
38
  @@interval = value
32
39
  end
33
40
 
41
+ def find_task(name)
42
+ @@named_tasks[name]
43
+ end
44
+
45
+ def register_task_name(name, task)
46
+ raise ArgumentError unless task.is_a?(DayPlanner::Task)
47
+ raise ArgumentError unless @@named_tasks[name].nil?
48
+ @@named_tasks[name] = task
49
+ end
50
+
51
+ def delete_task_name(name)
52
+ @@named_tasks.delete(name)
53
+ end
54
+
34
55
  private
35
56
  def check_schedule
36
57
  tasks.each do |t|
@@ -59,6 +80,13 @@ module DayPlanner
59
80
  end
60
81
  end
61
82
 
83
+ def destroy
84
+ DayPlanner.tasks.delete(self)
85
+ if @name
86
+ DayPlanner.delete_task_name(@name)
87
+ end
88
+ end
89
+
62
90
  def initialize(options, &block)
63
91
  if options[:every]
64
92
  @interval = options[:every]
@@ -67,6 +95,14 @@ module DayPlanner
67
95
  raise ArgumentError, "DayPlanner: Scheduling tasks at anything other than simple intervals using 'every' is still not implemented, not even a little bit."
68
96
  end
69
97
 
98
+ if options[:name]
99
+ name = options.delete(:name)
100
+ if !DayPlanner.find_task(name)
101
+ @name = name
102
+ DayPlanner.register_task_name(name, self)
103
+ end
104
+ end
105
+
70
106
  @task = block
71
107
 
72
108
  DayPlanner.tasks.push(self)
@@ -1,8 +1,8 @@
1
1
  module DayPlanner
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- TINY = 3
5
- BUILD = 1
4
+ TINY = 4
5
+ BUILD = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, TINY, BUILD].compact.join(".")
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: day_planner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damon Siefert
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.0.3
78
+ rubygems_version: 2.0.14
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Built to have a way to schedule tasks without running an extra process and