beaconable 0.1.2 → 0.3.1

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
  SHA256:
3
- metadata.gz: b133e116dce56a3c9a54fbd591646329af2f06d659e51757d2c7368b54aef8ed
4
- data.tar.gz: 257b7432b42229381bf2b59dfdc8081fa98194e6061bfc63274ed65e11968274
3
+ metadata.gz: bec79a862ecc4920422fa44d559651bf347e777851475e52477c42ef33873839
4
+ data.tar.gz: a0d5adad3dd5446597f72f74a8d04bb327317f907037312dc15b93f1d7159092
5
5
  SHA512:
6
- metadata.gz: 2e532f351dc9a62a622bf9f50e9bf3e59e257ac144fd55ab34181045de26ff3c20747bf7c125394cd0486b6fdc25b3037f49697fc950054368e1616ecbeef87c
7
- data.tar.gz: 1cd842ed8136ae51d735c59fcd2557e3e2a491bcdd981da5565a92b39139686ef939af22c31e9f73876a7b4d82b98f2f85c8c41d7b4247e105aff26532b28a71
6
+ metadata.gz: 7c048d0131bcc789c886077b1e6dc3d1a4a198760da76ae0f881de26f3016638553c167507d1232e4be125aa445d4521d3cb3eeb97cbc9cdbd07634fa8c1530b
7
+ data.tar.gz: 93c58a920aa1d8b3ed2d80cc34460ccb8ee576489589cfb5f79289fa6de2f4a648ea6ea86f304834c9d41dec0201dcc51b8d66cd378776cf89b8758a28b21a99
@@ -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
@@ -0,0 +1,21 @@
1
+ ## 0.3.1 (2020-09-16)
2
+
3
+ - Fixes #fire_beacon not to use dirty attributes to check changes
4
+
5
+ ## 0.3.0 (2020-08-03)
6
+
7
+ - Changed ObjectWas initialization to wrap al all the changes for a transaction
8
+
9
+ ## 0.2.2 (2019-12-16)
10
+
11
+ - Added new tests for chained methods
12
+ - Fixed chained methods
13
+
14
+ ## 0.2.1 (2019-12-16)
15
+
16
+ - Made #field_change, #from and #to public
17
+
18
+ ## 0.2.0 (2019-12-12)
19
+
20
+ - Added new test and fixes styles
21
+ - Added #field_change, #from, #to
@@ -1,29 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beaconable (0.1.1)
4
+ beaconable (0.3.1)
5
5
  activerecord (>= 4.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.0.0)
11
- activesupport (= 6.0.0)
12
- activerecord (6.0.0)
13
- activemodel (= 6.0.0)
14
- activesupport (= 6.0.0)
15
- activesupport (6.0.0)
10
+ activemodel (6.0.2)
11
+ activesupport (= 6.0.2)
12
+ activerecord (6.0.2)
13
+ activemodel (= 6.0.2)
14
+ activesupport (= 6.0.2)
15
+ activesupport (6.0.2)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
19
19
  tzinfo (~> 1.1)
20
- zeitwerk (~> 2.1, >= 2.1.8)
20
+ zeitwerk (~> 2.2)
21
21
  ansi (1.5.0)
22
22
  ast (2.4.0)
23
23
  builder (3.2.3)
24
24
  byebug (10.0.2)
25
- concurrent-ruby (1.1.5)
26
- i18n (1.6.0)
25
+ concurrent-ruby (1.1.6)
26
+ i18n (1.8.2)
27
27
  concurrent-ruby (~> 1.0)
28
28
  jaro_winkler (1.5.3)
29
29
  minitest (5.11.3)
@@ -47,10 +47,10 @@ GEM
47
47
  ruby-progressbar (1.10.1)
48
48
  sqlite3 (1.4.1)
49
49
  thread_safe (0.3.6)
50
- tzinfo (1.2.5)
50
+ tzinfo (1.2.7)
51
51
  thread_safe (~> 0.1)
52
52
  unicode-display_width (1.6.0)
53
- zeitwerk (2.1.9)
53
+ zeitwerk (2.2.2)
54
54
 
55
55
  PLATFORMS
56
56
  ruby
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
@@ -15,12 +15,11 @@ module Beaconable
15
15
  private
16
16
 
17
17
  def save_for_beacon
18
- @object_was = ObjectWas.new(self).call
18
+ @object_was ||= ObjectWas.new(self).call
19
19
  end
20
20
 
21
21
  def fire_beacon
22
- if self.saved_changes?
23
- "#{self.class.name}Beacon".constantize.new(self, @object_was).call
24
- end
22
+ "#{self.class.name}Beacon".constantize.new(self, @object_was).call
23
+ @object_was = nil
25
24
  end
26
25
  end
@@ -9,6 +9,23 @@ module Beaconable
9
9
  @object_was = object_was
10
10
  end
11
11
 
12
+ def field_changed(field)
13
+ @field = field
14
+ @result = field_changed? field
15
+ self
16
+ end
17
+
18
+ def from(*values)
19
+ return self unless @result
20
+
21
+ @result = values.include? object_was.send(@field)
22
+ self
23
+ end
24
+
25
+ def to(*values)
26
+ @result && values.include?(object.send(@field))
27
+ end
28
+
12
29
  private
13
30
 
14
31
  def field_changed?(field)
@@ -25,5 +42,6 @@ module Beaconable
25
42
  def new_entry?
26
43
  object_was.created_at.nil?
27
44
  end
45
+
28
46
  end
29
47
  end
@@ -10,7 +10,7 @@ module Beaconable
10
10
 
11
11
  def call
12
12
  hashed_object = {}
13
- symbolized_column_names = object.class.column_names.map {|column_name| column_name.to_sym}
13
+ symbolized_column_names = object.class.column_names.map(&:to_sym)
14
14
  symbolized_column_names.each do |column_name|
15
15
  hashed_object[column_name] = object.send("#{column_name}_was")
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Beaconable
2
- VERSION = "0.1.2"
2
+ VERSION = "0.3.1"
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.3.1
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: 2020-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -132,6 +132,7 @@ extra_rdoc_files: []
132
132
  files:
133
133
  - ".gitignore"
134
134
  - ".travis.yml"
135
+ - CHANGELOG.md
135
136
  - CODE_OF_CONDUCT.md
136
137
  - Gemfile
137
138
  - Gemfile.lock