acts_as_holdable 0.1.1 → 0.1.2

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: ab95215af6bfe8d8811807c536ca35ca837a7c83d030c087986fd4d78fb37716
4
- data.tar.gz: 548d98f061d57a4c7e12cf3a71cefa9808c0109e793c124d06747a52dfacd073
3
+ metadata.gz: 70207e4125f5f3dfeb69e009aadc9ce94af642ccfb0701a4bb79c14c61dfaf38
4
+ data.tar.gz: a4657bf33acac47b7582b7a81b86359e6e9975593f1d8202baf3d7291acc543e
5
5
  SHA512:
6
- metadata.gz: f43dd7e5ff2f853233b100bcc814615faad4ade99b49b5a4107e3a65c7caf1a73e2d99111ba786f7ea144098db761e92c7f345ba19a3655ae8a5fa6730bb0641
7
- data.tar.gz: 54f10fd2c304f946f6bcab51aff8fced9c88842e44873e47611a9dbc44ad5de98b4d0479a1ddc094fa6565d7fb0cd06dbcfdf4092b4a5449a45535ebe50d6bed
6
+ metadata.gz: 36a87fb538e2a15d94d6a07afdbcd9d0c27bc38bf3c177df5c80a2ba8d842445ff61d85d5e5119973c8081327fa4d7831efaf8929d1fe52497e66c02f91785e4
7
+ data.tar.gz: f15f3111648bf35eeae52026ae3813e7171a259ac612ccd31796e04582d79f07117f852eedc6b1e8fa1db5cd5a9c6b499dda7cdf83f1e3f4ceac0da9890d96f1
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
+ [![Build Status](https://travis-ci.org/aromaron/acts_as_holdable.svg?branch=master)](https://travis-ci.org/aromaron/acts_as_holdable)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/74d210e67822c530e218/maintainability)](https://codeclimate.com/github/aromaron/acts_as_holdable/maintainability)
3
+ [![Coverage Status](https://coveralls.io/repos/github/aromaron/acts_as_holdable/badge.svg?branch=master)](https://coveralls.io/github/aromaron/acts_as_holdable?branch=master)
4
+
1
5
  # ActsAsHoldable
2
6
  ActsAsHoldable allows resources to be held by users. It:
3
7
 
4
- * Is a MVC solution based on Rails engines
8
+ * Is a solution based on Rails engines
5
9
 
6
10
  ## Installation
7
11
  Add this line to your application's Gemfile:
@@ -99,7 +103,7 @@ end
99
103
 
100
104
  > WARNING - **migration needed!** - with this option the model must have an attribute `on_hand: :integer`
101
105
 
102
- The model is holdable until its `capacity` is reached. (e.g. an event't tickets types)
106
+ The model is holdable until its `capacity` is reached. (e.g. an event't tickets)
103
107
 
104
108
  **Configuration**
105
109
 
@@ -129,6 +133,12 @@ Each instance of the model must define its capacity.
129
133
  @user3.hold! @ticket, amount: 10 # overholding! raise ActsAsHoldable::AvailabilityError
130
134
  ```
131
135
 
136
+ #### Holdings Track - `on_hold_track: :true`
137
+
138
+ Useful if you want an easier way to keep track of how many holdings you currently have. Every time a holding is created or deleted the `on_hold` counter gets uptaded on your model
139
+
140
+ > WARNING - **migration needed!** - with this option the model must have an attribute `on_hold: :integer`
141
+
132
142
  ## Holding resources on a span of time
133
143
 
134
144
  Holdings can be created to be 'living' within a span of time, if the holding doesn't gets confirmed within the time span, it will be destroyed.
@@ -153,4 +163,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
153
163
 
154
164
  ### Acknowledgements
155
165
 
156
- To speed-up the initialization process of this project, the structure of this repository was strongly influenced by ActsAsBookable by Tandù srl.
166
+ To speed-up the initialization process of this project, the structure of this repository was strongly influenced by ActsAsBookable by Tandù srl.
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: true
1
+ # frozen_string_literal: false
2
2
 
3
3
  module ActsAsHoldable
4
4
  module Holdable
@@ -61,6 +61,7 @@ module ActsAsHoldable
61
61
  # Validates options
62
62
  permitted_options = {
63
63
  on_hand_type: %i[open closed none],
64
+ on_hold_track: [true, false],
64
65
  preset: [:ticket]
65
66
  }
66
67
 
@@ -77,11 +78,13 @@ module ActsAsHoldable
77
78
  defaults = case holding_opts[:preset]
78
79
  when :ticket
79
80
  {
80
- on_hand_type: :open
81
+ on_hand_type: :open,
82
+ on_hold_track: true
81
83
  }
82
84
  else
83
85
  {
84
- on_hand_type: :none
86
+ on_hand_type: :none,
87
+ on_hold_track: false
85
88
  }
86
89
  end
87
90
 
@@ -17,6 +17,17 @@ module ActsAsHoldable
17
17
  validates :amount, presence: true, numericality: { only_integer: true,
18
18
  greater_than_or_equal_to: 0 }
19
19
 
20
+ after_save :update_on_hold, if: :on_hold_required?
21
+
22
+ def update_on_hold
23
+ holdable.update(on_hold: holdable.holdings.sum(:amount)) if holdable.respond_to?(:on_hold)
24
+ holdable.reload
25
+ end
26
+
27
+ def on_hold_required?
28
+ holdable.holding_opts && holdable.holding_opts[:on_hold_track] != false
29
+ end
30
+
20
31
  private
21
32
 
22
33
  # Validation method. Check if the holded model is actually holdable
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsHoldable
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_holdable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nora Gabriela Alvarado