cachely 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +27 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +35 -0
- data/cachely.gemspec +18 -0
- data/config/database.yml +6 -0
- data/db/migrate/001_create_dummy_model.rb +9 -0
- data/lib/cachely/version.rb +3 -0
- data/lib/cachely.rb +29 -0
- data/test/models/dummy_class.rb +92 -0
- data/test/models/dummy_model.rb +3 -0
- data/test/unit/base_test.rb +18 -0
- data/test/unit/cachely_test.rb +7 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in cachely.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'pg'
|
8
|
+
gem 'activerecord', :require => "active_record"
|
9
|
+
gem 'activesupport'
|
10
|
+
gem 'test-unit'
|
11
|
+
gem 'cucumber'
|
12
|
+
gem 'json_spec'
|
13
|
+
gem 'capybara'
|
14
|
+
gem 'rack-test'
|
15
|
+
gem 'rake'
|
16
|
+
gem 'pry'
|
17
|
+
gem 'rest-client'
|
18
|
+
gem 'spork'
|
19
|
+
gem 'spork-testunit'
|
20
|
+
gem 'guard-spork'
|
21
|
+
gem 'guard-rspec'
|
22
|
+
gem 'guard'
|
23
|
+
gem 'ruby-prof'
|
24
|
+
gem 'guard-test'
|
25
|
+
gem 'libnotify'
|
26
|
+
end
|
27
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jordan Prince
|
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,29 @@
|
|
1
|
+
# Cachely
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cachely'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cachely
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'yaml'
|
4
|
+
require 'logger'
|
5
|
+
require 'active_record'
|
6
|
+
require 'pry'
|
7
|
+
namespace :db do
|
8
|
+
|
9
|
+
task :environment do
|
10
|
+
DATABASE_ENV = ENV['DATABASE_ENV'] || 'development'
|
11
|
+
MIGRATIONS_DIR = ENV['MIGRATIONS_DIR'] || 'db/migrate'
|
12
|
+
end
|
13
|
+
|
14
|
+
task :configuration => :environment do
|
15
|
+
@config = YAML.load_file('config/database.yml')[DATABASE_ENV]
|
16
|
+
end
|
17
|
+
|
18
|
+
task :configure_connection => :configuration do
|
19
|
+
ActiveRecord::Base.establish_connection @config
|
20
|
+
ActiveRecord::Base.logger = Logger.new STDOUT if @config['logger']
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Migrate the database (options: VERSION=x, VERBOSE=false).'
|
24
|
+
task :migrate => :configure_connection do
|
25
|
+
ActiveRecord::Migration.verbose = true
|
26
|
+
ActiveRecord::Migrator.migrate MIGRATIONS_DIR, ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
30
|
+
task :rollback => :configure_connection do
|
31
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
32
|
+
ActiveRecord::Migrator.rollback MIGRATIONS_DIR, step
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/cachely.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/cachely/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jordan Prince"]
|
6
|
+
gem.email = ["jordanmprince@gmail.com"]
|
7
|
+
gem.description = %q{Coming soon.}
|
8
|
+
gem.summary = %q{Use em-redis to transparently cache results from your class methods. Eventmachine compatible out of the box!}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "cachely"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Cachely::VERSION
|
17
|
+
gem.add_dependency "em-hiredis"
|
18
|
+
end
|
data/config/database.yml
ADDED
data/lib/cachely.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "cachely/version"
|
2
|
+
|
3
|
+
module Cachely
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def method_added(name)
|
7
|
+
if(@cachely_fcns.include?(name) and !@cachely_fcns_added.include?(name))
|
8
|
+
@cachely_fcns_added << name #this method'll get called when we do define method below
|
9
|
+
#this halts that.
|
10
|
+
|
11
|
+
self.class_eval("alias #{"#{name.to_s}_old".to_sym} #{name}") #alias old function out
|
12
|
+
|
13
|
+
self.define_method name do |*args| #define new one
|
14
|
+
send "#{name.to_s}_old".to_sym, *args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def cachely(fcn, opts = {}, &extension)
|
20
|
+
@cachely_fcns_added ||= []
|
21
|
+
@cachely_fcns = []
|
22
|
+
@cachely_fcns << fcn
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.included(base)
|
27
|
+
base.extend ClassMethods
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
class DummyClass
|
2
|
+
include Cachely
|
3
|
+
cachely :test_function_num, time: 3.minutes
|
4
|
+
#cachely :test_function_array, time: 2.minutes
|
5
|
+
#cachely :test_function_hash, time: 2.minutes
|
6
|
+
#cachely :test_function_string, time: 3.minutes
|
7
|
+
#cachely :test_function_obj, time: 4.minutes
|
8
|
+
#cachely :test_function_array_obj, time: 5.minutes
|
9
|
+
#cachely :test_function_hash_obj, time: 6.minutes
|
10
|
+
|
11
|
+
def test_function_num
|
12
|
+
rand(500)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.class_test_function_num
|
16
|
+
rand(500)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.class_test_function_not_cached
|
20
|
+
rand(500)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_function_not_cached
|
24
|
+
rand(500)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_function_array
|
28
|
+
[1,2,3,4,5,6, rand(500)]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.class_test_function_array
|
32
|
+
[1,2,3,4,5,6, rand(500)]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_function_hash
|
36
|
+
{
|
37
|
+
:foo => "bar#{rand(500)}",
|
38
|
+
:baz => "boof"
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.class_test_function_hash
|
43
|
+
{
|
44
|
+
:foo => "bar#{rand(500)}",
|
45
|
+
:baz => "boof"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_function_string
|
50
|
+
rand(500).to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.class_test_function_string
|
54
|
+
rand(500).to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_function_obj
|
58
|
+
DummyModel.create(
|
59
|
+
:attr1 => rand(500),
|
60
|
+
:attr2 => rand(500)
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.class_test_function_obj
|
65
|
+
DummyModel.create(
|
66
|
+
:attr1 => rand(500),
|
67
|
+
:attr2 => rand(500)
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_function_array_obj
|
72
|
+
[test_function_obj, test_function_obj]
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.class_test_function_array_obj
|
76
|
+
[test_function_obj, test_function_obj]
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_function_hash_obj
|
80
|
+
{
|
81
|
+
:foo => test_function_obj,
|
82
|
+
:bar => test_function_obj
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.class_test_function_hash_obj
|
87
|
+
{
|
88
|
+
:foo => test_function_obj,
|
89
|
+
:bar => test_function_obj
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
require 'yaml'
|
5
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), "../.."))
|
6
|
+
require base_dir + "/lib/cachely.rb"
|
7
|
+
require_relative '../models/dummy_model.rb'
|
8
|
+
require_relative '../models/dummy_class.rb'
|
9
|
+
|
10
|
+
class BaseTest < ActiveSupport::TestCase
|
11
|
+
def setup
|
12
|
+
database_config ||= YAML.load(File.open(File.dirname(__FILE__)+'/../../config/database.yml', 'r'))
|
13
|
+
ActiveRecord::Base.configurations = database_config
|
14
|
+
ActiveRecord::Base.establish_connection("test")
|
15
|
+
|
16
|
+
DummyModel.destroy_all
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cachely
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jordan Prince
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: em-hiredis
|
16
|
+
requirement: &15818540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *15818540
|
25
|
+
description: Coming soon.
|
26
|
+
email:
|
27
|
+
- jordanmprince@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- cachely.gemspec
|
38
|
+
- config/database.yml
|
39
|
+
- db/migrate/001_create_dummy_model.rb
|
40
|
+
- lib/cachely.rb
|
41
|
+
- lib/cachely/version.rb
|
42
|
+
- test/models/dummy_class.rb
|
43
|
+
- test/models/dummy_model.rb
|
44
|
+
- test/unit/base_test.rb
|
45
|
+
- test/unit/cachely_test.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Use em-redis to transparently cache results from your class methods. Eventmachine
|
70
|
+
compatible out of the box!
|
71
|
+
test_files:
|
72
|
+
- test/models/dummy_class.rb
|
73
|
+
- test/models/dummy_model.rb
|
74
|
+
- test/unit/base_test.rb
|
75
|
+
- test/unit/cachely_test.rb
|