acts_as_holdable 0.1.1 → 0.1.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 +4 -4
- data/README.md +13 -3
- data/lib/acts_as_holdable/holdable/core.rb +6 -3
- data/lib/acts_as_holdable/holding.rb +11 -0
- data/lib/acts_as_holdable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70207e4125f5f3dfeb69e009aadc9ce94af642ccfb0701a4bb79c14c61dfaf38
|
4
|
+
data.tar.gz: a4657bf33acac47b7582b7a81b86359e6e9975593f1d8202baf3d7291acc543e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36a87fb538e2a15d94d6a07afdbcd9d0c27bc38bf3c177df5c80a2ba8d842445ff61d85d5e5119973c8081327fa4d7831efaf8929d1fe52497e66c02f91785e4
|
7
|
+
data.tar.gz: f15f3111648bf35eeae52026ae3813e7171a259ac612ccd31796e04582d79f07117f852eedc6b1e8fa1db5cd5a9c6b499dda7cdf83f1e3f4ceac0da9890d96f1
|
data/README.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
[](https://travis-ci.org/aromaron/acts_as_holdable)
|
2
|
+
[](https://codeclimate.com/github/aromaron/acts_as_holdable/maintainability)
|
3
|
+
[](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
|
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
|
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:
|
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
|