beaconable 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +29 -1
- data/lib/beaconable/version.rb +1 -1
- data/lib/generators/beacon/USAGE +8 -0
- data/lib/generators/beacon/beacon_generator.rb +17 -0
- data/lib/generators/beacon/templates/beacon.rb.tt +12 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d87286b430dfcb3dcaf437a08cf30061ce7473de5c7c690b49fa9a1f0433cd5
|
4
|
+
data.tar.gz: 4f4a10e54f1bc8a3056079bc6f266fb84691bc75c006a3bc127c7c73c38d67a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a268d17e4a4727bc872bee67784fe6bf0956ce1e3d0a3b20233a978ccd89ccd49683f12ac6aebc93c2b4e980fa2523e450e2370911766757b44fe20bfb1d51b2
|
7
|
+
data.tar.gz: 3b225ef36a9e871d2cc37b25c75adb306b1fed0ff2af6bab3e24d2e282baebd6d8a997ab91b5c74c3d835e63944752901bdb71bfef0f15a4d376a34448b8efb1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -19,8 +19,36 @@ Or install it yourself as:
|
|
19
19
|
$ gem install beaconable
|
20
20
|
|
21
21
|
## Usage
|
22
|
+
When you include Beaconable in your model it will fire your Beacon everytime after you create or save an entry. Inside your Beacon you have access to the following:
|
22
23
|
|
23
|
-
|
24
|
+
- object (and an alias with the name of your model, i.e user): the instance of your object after changes.
|
25
|
+
- 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
|
+
- 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
|
28
|
+
|
29
|
+
### Rails Generator
|
30
|
+
You can use the bundled generator if you are using the library inside of
|
31
|
+
a Rails project:
|
32
|
+
|
33
|
+
rails g beacon User
|
34
|
+
|
35
|
+
This will do the following:
|
36
|
+
1. Create a new beacon file in `app/beacons/user_beacon.rb`
|
37
|
+
2. Will add "include Beaconable" in your User Model.
|
38
|
+
|
39
|
+
|
40
|
+
### Beacon Definition
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
class UserBeacon < Beaconable::BaseBeacon
|
44
|
+
alias user object
|
45
|
+
alias user_was object_was
|
46
|
+
|
47
|
+
def call
|
48
|
+
WelcomeUserJob.perform_later(self.id) if new_entry?
|
49
|
+
UpdateExternalServiceJob.perform_later(self.id) if field_changed? :email
|
50
|
+
end
|
51
|
+
end
|
24
52
|
|
25
53
|
## Development
|
26
54
|
|
data/lib/beaconable/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
class BeaconGenerator < Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def create_beacon_file
|
9
|
+
template 'beacon.rb.tt', File.join('app', 'beacons', class_path, "#{file_name}_beacon.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
def insert_inclusion_into_model_file
|
13
|
+
inject_into_class "app/models/#{file_name}.rb", class_name do
|
14
|
+
" include Beaconable\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
class <%= class_name %>Beacon < Beaconable::BaseBeacon
|
5
|
+
alias <%= file_name %> object
|
6
|
+
alias <%= file_name %>_was object_was
|
7
|
+
|
8
|
+
def call
|
9
|
+
# Put your callbacks and side-effects here
|
10
|
+
end
|
11
|
+
end
|
12
|
+
<% end -%>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaconable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerardo Raiden
|
@@ -131,6 +131,9 @@ files:
|
|
131
131
|
- lib/beaconable/base_beacon.rb
|
132
132
|
- lib/beaconable/object_was.rb
|
133
133
|
- lib/beaconable/version.rb
|
134
|
+
- lib/generators/beacon/USAGE
|
135
|
+
- lib/generators/beacon/beacon_generator.rb
|
136
|
+
- lib/generators/beacon/templates/beacon.rb.tt
|
134
137
|
homepage: https://github.com/Lastimoso/beaconable
|
135
138
|
licenses:
|
136
139
|
- MIT
|