ledger 0.0.3 → 0.0.4
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.
- data/README.md +19 -11
- data/lib/ledger/creates_events.rb +2 -3
- data/lib/ledger/event.rb +2 -2
- data/lib/ledger/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
3
|
Does your app have the concept of accounts, with multiple users per account?
|
4
4
|
|
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
27
27
|
Start by adding the `HasEvents` module to your account object.
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
class
|
30
|
+
class Accounts
|
31
31
|
…
|
32
32
|
include Ledger::HasEvents
|
33
33
|
…
|
@@ -37,7 +37,7 @@ end
|
|
37
37
|
Add in the `CreatesEvents` module to your controller.
|
38
38
|
|
39
39
|
```ruby
|
40
|
-
class CategoriesController
|
40
|
+
class CategoriesController
|
41
41
|
…
|
42
42
|
include Ledger::CreatesEvents
|
43
43
|
…
|
@@ -49,7 +49,7 @@ Now all you need to do is call `#create_event` when you do something.
|
|
49
49
|
```ruby
|
50
50
|
def update
|
51
51
|
@category.update_attributes! params[:category]
|
52
|
-
create_event :
|
52
|
+
create_event :updated, @category
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
@@ -68,7 +68,6 @@ Each event has the following (by default, for options see further down).
|
|
68
68
|
|
69
69
|
```
|
70
70
|
{
|
71
|
-
"key"=>"category_updated",
|
72
71
|
"action"=>"updated",
|
73
72
|
"object"=>"Category",
|
74
73
|
"actor"=>{
|
@@ -122,13 +121,12 @@ end
|
|
122
121
|
|
123
122
|
Want to send more information about events? Just send through the information at the end of the `#create_event` call.
|
124
123
|
|
125
|
-
```
|
124
|
+
```ruby
|
126
125
|
create_event :state_changed, @category, from: from_state, to: @category.state
|
127
126
|
```
|
128
|
-
```
|
129
127
|
|
128
|
+
```
|
130
129
|
{
|
131
|
-
"key"=>"category_state_changed",
|
132
130
|
"action"=>"state_changed",
|
133
131
|
"object"=>"Category",
|
134
132
|
"actor"=>{
|
@@ -164,16 +162,16 @@ end
|
|
164
162
|
|
165
163
|
### Manual Events
|
166
164
|
|
167
|
-
You can add an event manually by creating an instance of `Ledger::Event`, then adding
|
165
|
+
You can add an event manually by creating an instance of `Ledger::Event`, then adding that in via `account.add_event`.
|
168
166
|
|
169
167
|
```ruby
|
170
|
-
new_event = Ledger::Event.new
|
168
|
+
new_event = Ledger::Event.new action: "create", object: "manual_event", data: { some: "thing" }
|
171
169
|
account.add_event new_event
|
172
170
|
```
|
173
171
|
|
174
172
|
### Direct Redis access
|
175
173
|
|
176
|
-
You can access redis directly through `#events`. This will be a [Nest](https://github.com/soveran/nest) instance
|
174
|
+
You can access redis directly through `#events`. This will be a [Nest](https://github.com/soveran/nest) instance and you can call on it, or use its naming schema to do some other magic.
|
177
175
|
|
178
176
|
```ruby
|
179
177
|
# Trim the events down to the last 100 events
|
@@ -183,6 +181,16 @@ account.events.ltrim 0, 100
|
|
183
181
|
account.events["something_else"].lpush "Some data"
|
184
182
|
```
|
185
183
|
|
184
|
+
## Who
|
185
|
+
|
186
|
+
Created with love by [Mal Curtis](http://github.com/snikch)
|
187
|
+
|
188
|
+
Twitter: [snikchnz](http://twitter.com/snikchnz)
|
189
|
+
|
190
|
+
## License
|
191
|
+
|
192
|
+
MIT. See license file.
|
193
|
+
|
186
194
|
|
187
195
|
## Contributing
|
188
196
|
|
@@ -10,11 +10,10 @@ module Ledger
|
|
10
10
|
object that does."
|
11
11
|
end
|
12
12
|
|
13
|
-
object_name = object.class.name
|
14
|
-
|
13
|
+
object_name = object.class.name == "String" ? \
|
14
|
+
object : object.class.name.downcase
|
15
15
|
|
16
16
|
details = {
|
17
|
-
key: key,
|
18
17
|
action: action,
|
19
18
|
object: object_name,
|
20
19
|
actor: {},
|
data/lib/ledger/event.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ledger
|
2
2
|
class Event
|
3
|
-
attr_accessor :actor, :
|
3
|
+
attr_accessor :actor, :action, :object, :data, :created_at
|
4
4
|
|
5
5
|
def initialize opts
|
6
6
|
opts.each do |attr, value|
|
@@ -8,7 +8,7 @@ module Ledger
|
|
8
8
|
end
|
9
9
|
self.created_at = Time.now
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
class << self
|
13
13
|
def from_json json
|
14
14
|
require 'json'
|
data/lib/ledger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nest
|