mimeo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-ohm-model.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Radamanthus Batnag
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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Mimeo
2
+
3
+ This lets you easily call your Ohm model's save from within your Rails models after_save.
4
+
5
+ It creates an after_save callback insider your ActiveRecord model. The callback finds the matching Redis record and updates it with the content of the AR instance.
6
+ If a matching record is not found, a new one is created and saved.
7
+
8
+ All accessible attributes (attr_accessible) are used to populate the Redis record. There should be a one-to-one correspondence between the Rails and the Redis attribute names.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'mimeo'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install mimeo
23
+
24
+ ## Usage
25
+
26
+ Inside your ActiveRecord model, add:
27
+
28
+ ohm_model <ModelName>
29
+
30
+ where ModelName is the name of your Ohm model.
31
+
32
+ Inside your Ohm model, add:
33
+
34
+ attribute :rails_id, Type::Integer
35
+ index :rails_id
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Mimeo
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mimeo.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "mimeo/version"
2
+
3
+ module Mimeo
4
+ module ClassMethods
5
+ def ohm_model(model, options = {})
6
+ cattr_accessor :ohm_model_class, :ohm_model_index
7
+
8
+ self.ohm_model_class = model
9
+ self.ohm_model_index = options[:index]
10
+
11
+ self.set_callback :save, :after do
12
+ self.save_to_redis
13
+ end
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+ def save_to_redis
19
+ redis_record = get_redis_record(ohm_model_class, ohm_model_index)
20
+ populate redis_record
21
+ redis_record.save
22
+ return true
23
+ end
24
+
25
+ def get_redis_record(model, index)
26
+ model.find(rails_id: self.id).first || model.new
27
+ end
28
+
29
+ def populate(record)
30
+ self.class.accessible_attributes.to_a.reject{|a| a.blank?}.map{|a| a.to_sym}.each do |attr|
31
+ val = self.send(attr)
32
+ record.send("#{attr}=", val)
33
+ record.rails_id = self.id
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ ActiveRecord::Base.extend Mimeo::ClassMethods
40
+ ActiveRecord::Base.send(:include, Mimeo::InstanceMethods)
data/mimeo.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/mimeo/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Radamanthus Batnag"]
6
+ gem.email = ["radamanthus@gmail.com"]
7
+ gem.description = %q{ActiveRecord extension for saving data to Redis using a given Ohm model.}
8
+ gem.summary = %q{
9
+ This is an ActiveRecord extension for saving data to Redis using a given Ohm model. I will give more details when I have more time.
10
+ }
11
+ gem.homepage = "http://radamanthus.github.com/mimeo"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "mimeo"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Mimeo::VERSION
19
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mimeo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Radamanthus Batnag
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ActiveRecord extension for saving data to Redis using a given Ohm model.
15
+ email:
16
+ - radamanthus@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/mimeo.rb
27
+ - lib/mimeo/version.rb
28
+ - mimeo.gemspec
29
+ homepage: http://radamanthus.github.com/mimeo
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: This is an ActiveRecord extension for saving data to Redis using a given
53
+ Ohm model. I will give more details when I have more time.
54
+ test_files: []