duties 0.0.1 → 0.0.2

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: edbe40e92993677875bf20a969da0da52510e54a
4
- data.tar.gz: 1285e2050b670d768cca9e561d2524117d92a3aa
3
+ metadata.gz: 58c199bfac0f918469da8f3cd3ac3efdde00e725
4
+ data.tar.gz: 8f2c956d07738c6f47d6a45c37e74d1720d50fc0
5
5
  SHA512:
6
- metadata.gz: c1cde1edaf89b8d427d6b59a23b59727efe16e79b9692d6a7919b3ead4244107bbaccbc466c29cc2b97aa0721d669e9d17347a869dffe0c999478347651d84e0
7
- data.tar.gz: bf9e023647f0f35f8d2a0ea6cc618ef6f2f9f22abf3abc389cc87ebaa88fb32ffc3648e78308f0125cbe97e53fd6353d1c2678c5ce41e63e5841b5ad1ae1830f
6
+ metadata.gz: 23d892e0109a2c5cdc1d0adcefcffa1c569d50e157fb34a22c4f2e06f3e56437f7934d642c27102b5c9bab4f44679b0651726fe9fffc8720d3b668cc54a88b04
7
+ data.tar.gz: 4abb6fa7809ef118ad6cc6561984fb309d3574a13b0b5ac13fa79908d1277634db42616f794612eb906a24b0889a4eb3c86373e7b5498d19ae0799369b1a6437
data/README.md CHANGED
@@ -9,7 +9,7 @@ Duties are composed of one or more activities. These activities have positions,
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'duties', '0.0.1'
12
+ gem 'duties', '0.0.2'
13
13
  ```
14
14
 
15
15
  ## Usage
@@ -2,6 +2,7 @@ class Duties::ActivityRecord < ActiveRecord::Base
2
2
  self.table_name = 'duties_activity_records'
3
3
 
4
4
  belongs_to :duty_record, class_name: 'Duties::DutyRecord'
5
+ serialize :failures, JSON
5
6
 
6
7
  validates :name, presence: true
7
8
  validates :duty_record, presence: true
@@ -0,0 +1,5 @@
1
+ class AddErrorsToActivities < ActiveRecord::Migration
2
+ def change
3
+ add_column :duties_activity_records, :failures, :text, default: '[]'
4
+ end
5
+ end
data/duties.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'duties'
4
- spec.version = '0.0.1'
4
+ spec.version = '0.0.2'
5
5
  spec.authors = ['Pat Allan']
6
6
  spec.email = ['pat@freelancing-gods.com']
7
7
  spec.summary = %q{Run activities related to a duty in a specific order}
@@ -1,14 +1,11 @@
1
1
  class Duties::Activity
2
2
  def self.call(record)
3
- activity = new(record)
4
- begin
5
- activity.call
6
- record.update_attributes status: 'success'
3
+ new(record).call
7
4
 
8
- Duties::Next.call record.duty_record, record.position
9
- rescue => error
10
- record.update_attributes status: 'failure'
11
- end
5
+ record.status = record.failures.any? ? 'failure' : 'success'
6
+ record.save!
7
+
8
+ Duties::Next.call record.duty_record, record.position
12
9
  end
13
10
 
14
11
  def initialize(activity)
@@ -0,0 +1,36 @@
1
+ class Duties::Status
2
+ def initialize(id)
3
+ @record = Duties::DutyRecord.find id
4
+ end
5
+
6
+ def status
7
+ return 'failure' if statuses.include?('failure')
8
+ return 'pending' if statuses.include?('pending')
9
+
10
+ 'success'
11
+ end
12
+
13
+ def failure?
14
+ status == 'failure'
15
+ end
16
+
17
+ def failures
18
+ record.activity_records.pluck(:failures).flatten
19
+ end
20
+
21
+ def pending?
22
+ status == 'pending'
23
+ end
24
+
25
+ def success?
26
+ status == 'success'
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :record
32
+
33
+ def statuses
34
+ @statuses ||= record.activity_records.pluck :status
35
+ end
36
+ end
data/lib/duties.rb CHANGED
@@ -10,3 +10,4 @@ require 'duties/duty'
10
10
  require 'duties/duty_job'
11
11
  require 'duties/engine'
12
12
  require 'duties/next'
13
+ require 'duties/status'
@@ -8,6 +8,13 @@ module Running
8
8
  enqueue_activity 'success_two', at: 2
9
9
  end
10
10
  end
11
+
12
+ class ExampleTwo < ::Duties::Duty
13
+ def enqueue_activities
14
+ enqueue_activity 'fail_one', at: 1
15
+ enqueue_activity 'success_one', at: 2
16
+ end
17
+ end
11
18
  end
12
19
 
13
20
  module Activities
@@ -22,6 +29,12 @@ module Running
22
29
  #
23
30
  end
24
31
  end
32
+
33
+ class FailOne < ::Duties::Activity
34
+ def call
35
+ activity.failures << 'nope'
36
+ end
37
+ end
25
38
  end
26
39
  end
27
40
 
@@ -38,4 +51,12 @@ describe 'Running duties' do
38
51
  expect(duty.activity_records.length).to eq(2)
39
52
  expect(duty.activity_records.pluck(:status)).to eq(['success', 'success'])
40
53
  end
54
+
55
+ it 'stores errors' do
56
+ id = Duties::Duty.enqueue 'example_two'
57
+ status = Duties::Status.new id
58
+
59
+ expect(status).to be_failure
60
+ expect(status.failures).to eq(['nope'])
61
+ end
41
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duties
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -111,6 +111,7 @@ files:
111
111
  - app/models/duties/duty_record.rb
112
112
  - config.ru
113
113
  - db/migrate/1_create_duties_and_activities.rb
114
+ - db/migrate/2_add_errors_to_activities.rb
114
115
  - duties.gemspec
115
116
  - lib/duties.rb
116
117
  - lib/duties/activity.rb
@@ -119,6 +120,7 @@ files:
119
120
  - lib/duties/duty_job.rb
120
121
  - lib/duties/engine.rb
121
122
  - lib/duties/next.rb
123
+ - lib/duties/status.rb
122
124
  - spec/acceptance/running_duties_spec.rb
123
125
  - spec/internal/config/database.yml
124
126
  - spec/internal/config/routes.rb