beaconable 0.1.1 → 0.2.3

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: 9d87286b430dfcb3dcaf437a08cf30061ce7473de5c7c690b49fa9a1f0433cd5
4
- data.tar.gz: 4f4a10e54f1bc8a3056079bc6f266fb84691bc75c006a3bc127c7c73c38d67a2
3
+ metadata.gz: b1110a4b0e426b277132f84ad26662bd312339ed2442bf300943b9607983bea4
4
+ data.tar.gz: c15046bf2c149a9618057da5617dbe7e3aeda9e72506bf181b68bdb4d1486ee7
5
5
  SHA512:
6
- metadata.gz: a268d17e4a4727bc872bee67784fe6bf0956ce1e3d0a3b20233a978ccd89ccd49683f12ac6aebc93c2b4e980fa2523e450e2370911766757b44fe20bfb1d51b2
7
- data.tar.gz: 3b225ef36a9e871d2cc37b25c75adb306b1fed0ff2af6bab3e24d2e282baebd6d8a997ab91b5c74c3d835e63944752901bdb71bfef0f15a4d376a34448b8efb1
6
+ metadata.gz: e0636144adbcb4f25a166fe5192617f07f8c0eb1ec22d8fb59abe4db8c2cd2fd9d195d920ad990989cc2914b779e2531aeeb7ec852e988e0506bd0b0e9b1f10b
7
+ data.tar.gz: 1fda0620bb1caaf045e6a017f607791cc412412edd8e2ae68bb3d0a3ac42d23a60f88dd1c2c171a0c2812508544c80a557de4639ebc908f8df64ee3661d4d45d
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /tmp/
9
9
  .ruby-version
10
10
  /vendor
11
+ .byebug_history
@@ -1,5 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.6
5
- before_install: gem install bundler -v 1.16.1
4
+ - 2.5.3
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 1.17.2
7
+ script:
8
+ - bundle exec rake
@@ -0,0 +1,17 @@
1
+ ## 0.3.0 (2020-08-03)
2
+
3
+ - Changed ObjectWas initialization to wrap al all the changes for a transaction
4
+
5
+ ## 0.2.2 (2019-12-16)
6
+
7
+ - Added new tests for chained methods
8
+ - Fixed chained methods
9
+
10
+ ## 0.2.1 (2019-12-16)
11
+
12
+ - Made #field_change, #from and #to public
13
+
14
+ ## 0.2.0 (2019-12-12)
15
+
16
+ - Added new test and fixes styles
17
+ - Added #field_change, #from, #to
@@ -1,28 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beaconable (0.1.1)
4
+ beaconable (0.2.3)
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
- concurrent-ruby (1.1.5)
25
- i18n (1.6.0)
24
+ byebug (10.0.2)
25
+ concurrent-ruby (1.1.6)
26
+ i18n (1.8.2)
26
27
  concurrent-ruby (~> 1.0)
27
28
  jaro_winkler (1.5.3)
28
29
  minitest (5.11.3)
@@ -46,10 +47,10 @@ GEM
46
47
  ruby-progressbar (1.10.1)
47
48
  sqlite3 (1.4.1)
48
49
  thread_safe (0.3.6)
49
- tzinfo (1.2.5)
50
+ tzinfo (1.2.7)
50
51
  thread_safe (~> 0.1)
51
52
  unicode-display_width (1.6.0)
52
- zeitwerk (2.1.9)
53
+ zeitwerk (2.2.2)
53
54
 
54
55
  PLATFORMS
55
56
  ruby
@@ -57,6 +58,7 @@ PLATFORMS
57
58
  DEPENDENCIES
58
59
  beaconable!
59
60
  bundler (~> 1.16)
61
+ byebug (~> 10.0)
60
62
  minitest (~> 5.0)
61
63
  minitest-reporters (~> 1.3)
62
64
  rake (~> 10.0)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Beaconable
2
2
 
3
+ [![Build Status](https://travis-ci.org/Lastimoso/beaconable.svg?branch=master)](https://travis-ci.org/Lastimoso/beaconable) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues)
4
+
3
5
  Small OO patern to isolate side-effects and callbacks for your ActiveRecord Models.
4
6
 
5
7
  ## Installation
@@ -24,7 +26,11 @@ When you include Beaconable in your model it will fire your Beacon everytime aft
24
26
  - object (and an alias with the name of your model, i.e user): the instance of your object after changes.
25
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
26
28
  - field_changed?(:field_name) : It allows you to check if a specific field was modified.
27
- - 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')
28
34
 
29
35
  ### Rails Generator
30
36
  You can use the bundled generator if you are using the library inside of
@@ -41,14 +47,15 @@ This will do the following:
41
47
 
42
48
  ```ruby
43
49
  class UserBeacon < Beaconable::BaseBeacon
44
- alias user object
50
+ alias user object
45
51
  alias user_was object_was
46
-
52
+
47
53
  def call
48
54
  WelcomeUserJob.perform_later(self.id) if new_entry?
49
55
  UpdateExternalServiceJob.perform_later(self.id) if field_changed? :email
50
56
  end
51
57
  end
58
+ ```
52
59
 
53
60
  ## Development
54
61
 
@@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency 'rake', '~> 10.0'
39
39
  spec.add_development_dependency 'rubocop', '~> 0.74.0'
40
40
  spec.add_development_dependency 'sqlite3', '~> 1.3'
41
+ spec.add_development_dependency 'byebug', '~> 10.0'
41
42
  end
@@ -15,12 +15,13 @@ 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
22
  if self.saved_changes?
23
23
  "#{self.class.name}Beacon".constantize.new(self, @object_was).call
24
24
  end
25
+ @object_was = nil
25
26
  end
26
27
  end
@@ -9,14 +9,39 @@ 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)
15
32
  object.send(field) != object_was.send(field)
16
33
  end
17
34
 
35
+ def any_field_changed?(*fields)
36
+ fields.each do |field|
37
+ return true if field_changed?(field)
38
+ end
39
+ false
40
+ end
41
+
18
42
  def new_entry?
19
43
  object_was.created_at.nil?
20
44
  end
45
+
21
46
  end
22
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.1"
2
+ VERSION = "0.2.3"
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.1
4
+ version: 0.2.3
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-25 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
111
125
  description: Small OO patern to isolate side-effects and callbacks for your ActiveRecord
112
126
  Models
113
127
  email:
@@ -118,6 +132,7 @@ extra_rdoc_files: []
118
132
  files:
119
133
  - ".gitignore"
120
134
  - ".travis.yml"
135
+ - CHANGELOG.md
121
136
  - CODE_OF_CONDUCT.md
122
137
  - Gemfile
123
138
  - Gemfile.lock