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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55f9fa301c3ed8240b86672ef33e1abfe95cc648f68e629cd855a905d479c007
4
- data.tar.gz: 367caefeb3598b7fd9454a056b1eafca2c88c0e4d7ca226c70f0be716575baa8
3
+ metadata.gz: 9d87286b430dfcb3dcaf437a08cf30061ce7473de5c7c690b49fa9a1f0433cd5
4
+ data.tar.gz: 4f4a10e54f1bc8a3056079bc6f266fb84691bc75c006a3bc127c7c73c38d67a2
5
5
  SHA512:
6
- metadata.gz: 01ed1385b08b58c60eaa4453aaaca02cca6157b313039bdea6ef543ebd71310359eb4aec19c6c6baafe8e1f8105c470921e3f99e8eac2eb86ac4a879fc1e8b37
7
- data.tar.gz: 4472b96a5f7fcd8e1d69756451e06b845f80f0dc28be36d3a94dfb9b550296e43572233604f52212e1dd3e49986b0f76273ce3c14f0b1e753d86e4168c9f2bfc
6
+ metadata.gz: a268d17e4a4727bc872bee67784fe6bf0956ce1e3d0a3b20233a978ccd89ccd49683f12ac6aebc93c2b4e980fa2523e450e2370911766757b44fe20bfb1d51b2
7
+ data.tar.gz: 3b225ef36a9e871d2cc37b25c75adb306b1fed0ff2af6bab3e24d2e282baebd6d8a997ab91b5c74c3d835e63944752901bdb71bfef0f15a4d376a34448b8efb1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beaconable (0.1.0)
4
+ beaconable (0.1.1)
5
5
  activerecord (>= 4.0)
6
6
 
7
7
  GEM
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
- TODO: Write usage instructions here
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
 
@@ -1,3 +1,3 @@
1
1
  module Beaconable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a beacon for the given model.
3
+
4
+ Example:
5
+ rails generate beacon User
6
+
7
+ This will create:
8
+ app/beacons/user_beacon.rb
@@ -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.0
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