beaconable 0.1.2 → 0.2.0
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/.travis.yml +2 -1
- data/Gemfile.lock +1 -1
- data/README.md +7 -3
- data/lib/beaconable/base_beacon.rb +19 -0
- data/lib/beaconable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 336e4ae5705c0b9ee21fc361ceaf332053bbe93ca56a81718c9f532d29f0e7e6
|
4
|
+
data.tar.gz: cf182b37f1b77fac9a4fea24572e511f10e34c8ba4e56d8e5bde050e435f569c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e165fe20b54a5d12a45f7cee82288d54dac268dc887fac802369c2a2ac685112cbda57135929e3774a8bc9bac411e485aaa68e8717cea1bf8ed4bd152de377
|
7
|
+
data.tar.gz: 496e617282226952d40b960ea599cb1842d89600851c6be77573801d0525fdc7b1b108504346d6fc375dfb6263f12b7b585070d2fcb1baf37d3f520793596f07
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,11 @@ When you include Beaconable in your model it will fire your Beacon everytime aft
|
|
26
26
|
- object (and an alias with the name of your model, i.e user): the instance of your object after changes.
|
27
27
|
- object_was (and an alias with the name of your model, i.e. user_was): the instance of your object as it was before your changes
|
28
28
|
- field_changed?(:field_name) : It allows you to check if a specific field was modified.
|
29
|
-
-
|
29
|
+
- any_field_changed?(:field_name, :other_field_name) : It allows you to check if any of multiple fields was modified.
|
30
|
+
- new_entry? : Returns true if the item saved is new
|
31
|
+
|
32
|
+
You can also used the following chained methods
|
33
|
+
- field_change(:field_name).from('first_alternative', 'n_alternative').to('first_alternative_for_to', 'second_alternative_for_to', 'n_alternative_for_toq')
|
30
34
|
|
31
35
|
### Rails Generator
|
32
36
|
You can use the bundled generator if you are using the library inside of
|
@@ -43,9 +47,9 @@ This will do the following:
|
|
43
47
|
|
44
48
|
```ruby
|
45
49
|
class UserBeacon < Beaconable::BaseBeacon
|
46
|
-
alias user object
|
50
|
+
alias user object
|
47
51
|
alias user_was object_was
|
48
|
-
|
52
|
+
|
49
53
|
def call
|
50
54
|
WelcomeUserJob.perform_later(self.id) if new_entry?
|
51
55
|
UpdateExternalServiceJob.perform_later(self.id) if field_changed? :email
|
@@ -25,5 +25,24 @@ module Beaconable
|
|
25
25
|
def new_entry?
|
26
26
|
object_was.created_at.nil?
|
27
27
|
end
|
28
|
+
|
29
|
+
def field_changed(field)
|
30
|
+
@field = field
|
31
|
+
@result = field_changed? field
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def from(*values)
|
36
|
+
return self if @result == false
|
37
|
+
|
38
|
+
@result = values.include? object_was.send(@field)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def to(*values)
|
43
|
+
return false if @result == false
|
44
|
+
|
45
|
+
values.include? object.send(@field)
|
46
|
+
end
|
28
47
|
end
|
29
48
|
end
|
data/lib/beaconable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaconable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerardo Raiden
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|