beaconable 0.1.2 → 0.2.0

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: b133e116dce56a3c9a54fbd591646329af2f06d659e51757d2c7368b54aef8ed
4
- data.tar.gz: 257b7432b42229381bf2b59dfdc8081fa98194e6061bfc63274ed65e11968274
3
+ metadata.gz: 336e4ae5705c0b9ee21fc361ceaf332053bbe93ca56a81718c9f532d29f0e7e6
4
+ data.tar.gz: cf182b37f1b77fac9a4fea24572e511f10e34c8ba4e56d8e5bde050e435f569c
5
5
  SHA512:
6
- metadata.gz: 2e532f351dc9a62a622bf9f50e9bf3e59e257ac144fd55ab34181045de26ff3c20747bf7c125394cd0486b6fdc25b3037f49697fc950054368e1616ecbeef87c
7
- data.tar.gz: 1cd842ed8136ae51d735c59fcd2557e3e2a491bcdd981da5565a92b39139686ef939af22c31e9f73876a7b4d82b98f2f85c8c41d7b4247e105aff26532b28a71
6
+ metadata.gz: c9e165fe20b54a5d12a45f7cee82288d54dac268dc887fac802369c2a2ac685112cbda57135929e3774a8bc9bac411e485aaa68e8717cea1bf8ed4bd152de377
7
+ data.tar.gz: 496e617282226952d40b960ea599cb1842d89600851c6be77573801d0525fdc7b1b108504346d6fc375dfb6263f12b7b585070d2fcb1baf37d3f520793596f07
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.5.3
5
- before_install: gem install bundler -v 1.16.1
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 1.17.2
6
7
  script:
7
8
  - bundle exec rake
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beaconable (0.1.1)
4
+ beaconable (0.2.0)
5
5
  activerecord (>= 4.0)
6
6
 
7
7
  GEM
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
- - new_entry? : Returns true if the item saved is new
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
@@ -1,3 +1,3 @@
1
1
  module Beaconable
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.2
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-08-26 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord