la_maquina 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +130 -0
- data/LICENSE.txt +22 -0
- data/MIT-LICENSE +20 -0
- data/README.md +86 -0
- data/Rakefile +34 -0
- data/la_maquina.gemspec +25 -0
- data/lib/la_maquina/ciguenal.rb +23 -0
- data/lib/la_maquina/piston.rb +9 -0
- data/lib/la_maquina/pistons/cache_piston.rb +37 -0
- data/lib/la_maquina/version.rb +3 -0
- data/lib/la_maquina/volante.rb +81 -0
- data/lib/la_maquina.rb +20 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/admin.rb +11 -0
- data/test/dummy/app/models/admin_trait.rb +9 -0
- data/test/dummy/app/models/admin_trait_modifier.rb +8 -0
- data/test/dummy/app/models/danny_trejo.rb +5 -0
- data/test/dummy/app/models/guest.rb +10 -0
- data/test/dummy/app/models/guest_trait.rb +9 -0
- data/test/dummy/app/models/guest_trait_modifier.rb +7 -0
- data/test/dummy/app/models/machete.rb +8 -0
- data/test/dummy/app/models/property.rb +7 -0
- data/test/dummy/app/models/standalone.rb +4 -0
- data/test/dummy/app/models/trait.rb +4 -0
- data/test/dummy/config/application.rb +27 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +27 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cache_machine.rb +2 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20150228015009_schema.rb +47 -0
- data/test/dummy/db/schema.rb +16 -0
- data/test/dummy/lib/dummy_cache_machine_comm_object.rb +5 -0
- data/test/dummy/lib/exploding_cache_machine_comm_object.rb +5 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/log/development.log +16 -0
- data/test/dummy/log/test.log +3980 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/admin_trait_modifiers.yml +3 -0
- data/test/dummy/test/fixtures/admin_traits.yml +4 -0
- data/test/dummy/test/fixtures/admins.yml +5 -0
- data/test/dummy/test/fixtures/guest_trait_modifiers.yml +3 -0
- data/test/dummy/test/fixtures/guest_traits.yml +4 -0
- data/test/dummy/test/fixtures/guests.yml +5 -0
- data/test/dummy/test/fixtures/properties.yml +7 -0
- data/test/dummy/test/fixtures/standalones.yml +2 -0
- data/test/dummy/test/fixtures/traits.yml +5 -0
- data/test/la_maquina_test.rb +15 -0
- data/test/master_cache_object_test.rb +23 -0
- data/test/subordinate_cache_object_test.rb +136 -0
- data/test/test_helper.rb +22 -0
- metadata +219 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d18a4ef4eed5cd9ae9141c6177b17710a1df9242
|
4
|
+
data.tar.gz: 1be1594aad8a4ca3d445aaf9e73393a6d9a567cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 126281d86542110b43fe57c135f483cafb5fdbd0ce34e236570447e5597dd8302e20071946f47a766a4c0ea671b370f4c796486d96daf986c7d953d264e46eb1
|
7
|
+
data.tar.gz: db6e7be277c7d39881edf1f3b64582ff081e27f83e7392e5af00160863c0fb36f8e2ad82c3f903fc25100a874736931ff973cb61f4f33e463b2c985f2c32b8fe
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in cache_machine.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
rails_version = ENV["RAILS_VERSION"] || "default"
|
9
|
+
|
10
|
+
rails = case rails_version
|
11
|
+
when "default"
|
12
|
+
">= 4.2.0"
|
13
|
+
else
|
14
|
+
"~> #{rails_version}"
|
15
|
+
end
|
16
|
+
|
17
|
+
gem "rails", rails
|
18
|
+
gem "redis"
|
19
|
+
gem "redis-namespace"
|
20
|
+
|
21
|
+
gem 'test_after_commit', :group => :test
|
22
|
+
gem 'simplecov', :group => :test
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cache_machine (0.0.8)
|
5
|
+
redis
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.2.0)
|
11
|
+
actionpack (= 4.2.0)
|
12
|
+
actionview (= 4.2.0)
|
13
|
+
activejob (= 4.2.0)
|
14
|
+
mail (~> 2.5, >= 2.5.4)
|
15
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
+
actionpack (4.2.0)
|
17
|
+
actionview (= 4.2.0)
|
18
|
+
activesupport (= 4.2.0)
|
19
|
+
rack (~> 1.6.0)
|
20
|
+
rack-test (~> 0.6.2)
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
23
|
+
actionview (4.2.0)
|
24
|
+
activesupport (= 4.2.0)
|
25
|
+
builder (~> 3.1)
|
26
|
+
erubis (~> 2.7.0)
|
27
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
29
|
+
activejob (4.2.0)
|
30
|
+
activesupport (= 4.2.0)
|
31
|
+
globalid (>= 0.3.0)
|
32
|
+
activemodel (4.2.0)
|
33
|
+
activesupport (= 4.2.0)
|
34
|
+
builder (~> 3.1)
|
35
|
+
activerecord (4.2.0)
|
36
|
+
activemodel (= 4.2.0)
|
37
|
+
activesupport (= 4.2.0)
|
38
|
+
arel (~> 6.0)
|
39
|
+
activesupport (4.2.0)
|
40
|
+
i18n (~> 0.7)
|
41
|
+
json (~> 1.7, >= 1.7.7)
|
42
|
+
minitest (~> 5.1)
|
43
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
44
|
+
tzinfo (~> 1.1)
|
45
|
+
arel (6.0.0)
|
46
|
+
builder (3.2.2)
|
47
|
+
docile (1.1.5)
|
48
|
+
erubis (2.7.0)
|
49
|
+
globalid (0.3.3)
|
50
|
+
activesupport (>= 4.1.0)
|
51
|
+
hike (1.2.3)
|
52
|
+
i18n (0.7.0)
|
53
|
+
json (1.8.2)
|
54
|
+
loofah (2.0.1)
|
55
|
+
nokogiri (>= 1.5.9)
|
56
|
+
mail (2.6.3)
|
57
|
+
mime-types (>= 1.16, < 3)
|
58
|
+
mime-types (2.4.3)
|
59
|
+
mini_portile (0.6.2)
|
60
|
+
minitest (5.5.1)
|
61
|
+
multi_json (1.10.1)
|
62
|
+
nokogiri (1.6.6.2)
|
63
|
+
mini_portile (~> 0.6.0)
|
64
|
+
rack (1.6.0)
|
65
|
+
rack-test (0.6.3)
|
66
|
+
rack (>= 1.0)
|
67
|
+
rails (4.2.0)
|
68
|
+
actionmailer (= 4.2.0)
|
69
|
+
actionpack (= 4.2.0)
|
70
|
+
actionview (= 4.2.0)
|
71
|
+
activejob (= 4.2.0)
|
72
|
+
activemodel (= 4.2.0)
|
73
|
+
activerecord (= 4.2.0)
|
74
|
+
activesupport (= 4.2.0)
|
75
|
+
bundler (>= 1.3.0, < 2.0)
|
76
|
+
railties (= 4.2.0)
|
77
|
+
sprockets-rails
|
78
|
+
rails-deprecated_sanitizer (1.0.3)
|
79
|
+
activesupport (>= 4.2.0.alpha)
|
80
|
+
rails-dom-testing (1.0.5)
|
81
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
82
|
+
nokogiri (~> 1.6.0)
|
83
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
84
|
+
rails-html-sanitizer (1.0.1)
|
85
|
+
loofah (~> 2.0)
|
86
|
+
railties (4.2.0)
|
87
|
+
actionpack (= 4.2.0)
|
88
|
+
activesupport (= 4.2.0)
|
89
|
+
rake (>= 0.8.7)
|
90
|
+
thor (>= 0.18.1, < 2.0)
|
91
|
+
rake (10.4.2)
|
92
|
+
redis (3.2.1)
|
93
|
+
redis-namespace (1.5.1)
|
94
|
+
redis (~> 3.0, >= 3.0.4)
|
95
|
+
simplecov (0.9.1)
|
96
|
+
docile (~> 1.1.0)
|
97
|
+
multi_json (~> 1.0)
|
98
|
+
simplecov-html (~> 0.8.0)
|
99
|
+
simplecov-html (0.8.0)
|
100
|
+
sprockets (2.12.3)
|
101
|
+
hike (~> 1.2)
|
102
|
+
multi_json (~> 1.0)
|
103
|
+
rack (~> 1.0)
|
104
|
+
tilt (~> 1.1, != 1.3.0)
|
105
|
+
sprockets-rails (2.2.4)
|
106
|
+
actionpack (>= 3.0)
|
107
|
+
activesupport (>= 3.0)
|
108
|
+
sprockets (>= 2.8, < 4.0)
|
109
|
+
sqlite3 (1.3.10)
|
110
|
+
test_after_commit (0.4.0)
|
111
|
+
activerecord (>= 3.2)
|
112
|
+
thor (0.19.1)
|
113
|
+
thread_safe (0.3.4)
|
114
|
+
tilt (1.4.1)
|
115
|
+
tzinfo (1.2.2)
|
116
|
+
thread_safe (~> 0.1)
|
117
|
+
|
118
|
+
PLATFORMS
|
119
|
+
ruby
|
120
|
+
|
121
|
+
DEPENDENCIES
|
122
|
+
bundler (~> 1.6)
|
123
|
+
cache_machine!
|
124
|
+
rails (>= 4.2.0)
|
125
|
+
rake
|
126
|
+
redis
|
127
|
+
redis-namespace
|
128
|
+
simplecov
|
129
|
+
sqlite3
|
130
|
+
test_after_commit
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Greg Orlov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Greg Orlov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# La Maquina
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'la_maquina'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install la_maquina
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
### Pistons
|
24
|
+
|
25
|
+
Once the `Ciguenal` is called it fires the `Piston`s, the behavior of which is entirely up to you.
|
26
|
+
|
27
|
+
So, let's say, we have a couple objects that look like:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class DannyTrejo < ActiveRecord::Base
|
31
|
+
has_many :machetes
|
32
|
+
|
33
|
+
searchable do
|
34
|
+
double :machete_sharpness, multiple: true do
|
35
|
+
machetes.map(&:sharpness)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
```ruby
|
41
|
+
class Machete < ActiveRecord::Base
|
42
|
+
belongs_to :danny_trejo
|
43
|
+
|
44
|
+
include LaMaquina::Volante
|
45
|
+
updates :danny_trejo
|
46
|
+
end
|
47
|
+
```
|
48
|
+
and we want to let `DannyTrejo` know when his `Machete` has been updated so that we can reindex him.
|
49
|
+
|
50
|
+
`Machete` is set up to fire on update, so we'll set up a listener Piston that looks like this:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
class SunspotPiston < LaMaquina::Piston
|
54
|
+
class << self
|
55
|
+
def fire!(klass = "", id = nil)
|
56
|
+
indexed_class.find(id).index!
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def indexed_class(klass)
|
62
|
+
{"danny_trejo" => DannyTrejo}[klass] or raise "can't index class #{klass}!"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
```
|
68
|
+
Which finds the klass, does a find on it and fires off [Sunspot](https://github.com/sunspot/sunspot#reindexing-objects) `index!`
|
69
|
+
|
70
|
+
### Setup
|
71
|
+
|
72
|
+
The setup is pretty straightforward: you do all the setting up in `config/la_maquina.rb'.
|
73
|
+
|
74
|
+
The 2 things you have to do are: set up the pistons(if they need configuring) and install them.
|
75
|
+
For example, if you're using the CachePiston and need to set up Redis, here's how your `la_maquina.rb` will look
|
76
|
+
|
77
|
+
LaMaquina::Pistons::CachePiston.redis = Redis::Namespace.new(:cache_piston, redis: MyRedisInstance)
|
78
|
+
LaMaquina::Ciguenal.install MyPiston, LaMaquina::Pistons::CachePiston
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
1. Fork it ( https://github.com/[my-github-username]/la_maquina/fork )
|
83
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
86
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'CacheMachine'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
data/la_maquina.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'la_maquina/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "la_maquina"
|
8
|
+
spec.version = LaMaquina::VERSION
|
9
|
+
spec.authors = ["Greg Orlov"]
|
10
|
+
spec.email = ["greg@avvo.com"]
|
11
|
+
spec.summary = %q{depnendency tree update notifications}
|
12
|
+
spec.description = %q{lets you have inter-model update notifications without having to make database connections}
|
13
|
+
spec.homepage = "https://github.com/gaorlov/la_maquina"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "sqlite3"
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module LaMacquina
|
2
|
+
class Ciguenal
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def self.notify!(klass = "", id = nil)
|
6
|
+
pistons.each do |piston|
|
7
|
+
piston.fire! klass, id
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.install(*pistons)
|
12
|
+
pistons.each do |piston|
|
13
|
+
self.pistons << piston
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
attr_accessor :pistons
|
20
|
+
self.pistons = []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Pistons
|
2
|
+
class CachePiston < LaMaquina::Piston
|
3
|
+
class << self
|
4
|
+
attr_accessor :redis
|
5
|
+
|
6
|
+
def fire!(klass = "", id = nil)
|
7
|
+
|
8
|
+
updated_at = SecureRandom.uuid()
|
9
|
+
redis_key_string = redis_key klass, id
|
10
|
+
# make a class var with a default
|
11
|
+
|
12
|
+
cache_key = "#{redis_key_string}/#{updated_at}"
|
13
|
+
redis.set redis_key_string, cache_key
|
14
|
+
|
15
|
+
cache_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def cache_key(klass, id)
|
19
|
+
|
20
|
+
redis_key_string = redis_key klass, id
|
21
|
+
|
22
|
+
key = redis.get redis_key_string
|
23
|
+
# key found
|
24
|
+
return key if key
|
25
|
+
|
26
|
+
# there's no key; we can't very well rerun nil for cache_key. Let's make a new entry
|
27
|
+
touch_cache klass, id
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def redis_key(klass, id)
|
33
|
+
"#{klass}/#{id}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module LaMaquina
|
2
|
+
module Volante
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ActiveRecord::Callbacks
|
5
|
+
|
6
|
+
included do
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_reader :notified_objects
|
10
|
+
notified_objects = []
|
11
|
+
|
12
|
+
def notifies(object, opts = {})
|
13
|
+
notified_objects << {:object => object, :options => opts}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
after_commit :notify!
|
18
|
+
end
|
19
|
+
|
20
|
+
def notify!
|
21
|
+
notified_objects.each do |notified|
|
22
|
+
|
23
|
+
object = notified[:object]
|
24
|
+
options = notified[:options]
|
25
|
+
|
26
|
+
comm_object = options[:using]
|
27
|
+
|
28
|
+
klass = notified_klass( object, options )
|
29
|
+
id = notified_id( object, options )
|
30
|
+
|
31
|
+
begin
|
32
|
+
if comm_object
|
33
|
+
comm_object.notify(:notified_class => klass, :notified_id => id, :notifier_class => LaMaquina.format_object_name(self))
|
34
|
+
else
|
35
|
+
LaMaquina::Ciguenal.notify!(klass, id)
|
36
|
+
end
|
37
|
+
rescue => e
|
38
|
+
LaMaquina.update_error_handler.call( e,
|
39
|
+
:notified_class => klass,
|
40
|
+
:notified_id => id,
|
41
|
+
:subordinate_class => LaMaquina.format_object_name(self),
|
42
|
+
:subordinate_id => self.id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def notified_klass(object, options)
|
50
|
+
if object == :self
|
51
|
+
return LaMaquina.format_object_name(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
if options[:polymorphic]
|
55
|
+
return LaMaquina.format_class_name(self.send("#{object}_type"))
|
56
|
+
end
|
57
|
+
|
58
|
+
if options[:class_name]
|
59
|
+
return LaMaquina.format_class_name(options[:class_name])
|
60
|
+
end
|
61
|
+
|
62
|
+
if options[:class]
|
63
|
+
return LaMaquina.format_class_name(options[:class])
|
64
|
+
end
|
65
|
+
|
66
|
+
return object
|
67
|
+
end
|
68
|
+
|
69
|
+
def notified_id(object, options)
|
70
|
+
if object == :self
|
71
|
+
return self.id
|
72
|
+
end
|
73
|
+
|
74
|
+
if options[:through]
|
75
|
+
return self.send(options[:through]).send("#{object}_id")
|
76
|
+
end
|
77
|
+
|
78
|
+
self.send("#{object}_id")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/la_maquina.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "la_maquina/version"
|
2
|
+
|
3
|
+
module LaMaquina
|
4
|
+
autoload :Ciguenal, 'la_maquina/ciguenal'
|
5
|
+
autoload :Piston, 'la_maquina/piston'
|
6
|
+
autoload :Volante, 'la_maquina/volante'
|
7
|
+
|
8
|
+
autoload :CachePiston, 'la_maquina/pistons/cache_piston'
|
9
|
+
|
10
|
+
|
11
|
+
mattr_accessor :update_error_handler
|
12
|
+
|
13
|
+
def self.format_object_name(object)
|
14
|
+
object.class.to_s.demodulize.underscore
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.format_class_name(klass)
|
18
|
+
klass.to_s.demodulize.underscore
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Admin < ActiveRecord::Base
|
2
|
+
has_many :admin_traits
|
3
|
+
has_many :traits, :through => :admin_traits
|
4
|
+
|
5
|
+
has_many :properties, :as => :user
|
6
|
+
|
7
|
+
include CacheMachine::SubordinateCacheObject
|
8
|
+
updates_cache_master :self
|
9
|
+
|
10
|
+
updates_cache_master :self, :comm_object => ::DummyCacheMachineCommObject
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class AdminTrait < ActiveRecord::Base
|
2
|
+
belongs_to :user, :class_name => "Admin"
|
3
|
+
belongs_to :thing, :class_name => "Trait"
|
4
|
+
|
5
|
+
include CacheMachine::SubordinateCacheObject
|
6
|
+
|
7
|
+
updates_cache_master :user, :class => Admin
|
8
|
+
updates_cache_master :thing, :class_name => "Trait"
|
9
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AdminTraitModifier < ActiveRecord::Base
|
2
|
+
belongs_to :admin_trait
|
3
|
+
|
4
|
+
include CacheMachine::SubordinateCacheObject
|
5
|
+
|
6
|
+
updates_cache_master :user, :through => :admin_trait, :class_name => "Admin"
|
7
|
+
updates_cache_master :thing, :through => :admin_trait, :class => Trait
|
8
|
+
end
|