railhead_memorize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
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.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = RailheadMemorize
2
+
3
+ RailheadMemorize is a Ruby on Rails plugin that easily memorize model functions.
4
+
5
+ == Installation
6
+
7
+ Installation is available as gem (recommended):
8
+
9
+ config.gem 'railhead_memorize'
10
+
11
+ Or as Rails plugin:
12
+
13
+ $ ruby script/plugin install git://github.com/nagybence/railhead_memorize.git
14
+
15
+ == License
16
+
17
+ Copyright (c) 2011 Bence Nagy (nagybence@tipogral.hu), released under the MIT license.
18
+
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'railhead_memorize'
2
+
@@ -0,0 +1,61 @@
1
+ require 'active_support'
2
+
3
+
4
+ module RailheadMemorize
5
+
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def memorize(key, options = {})
13
+ class_eval <<-END
14
+ alias #{key}_unmemorized #{key}
15
+ before_create :initialize_memorized_#{key}
16
+
17
+ def initialize_memorized_#{key}
18
+ self.memorized_#{key} = #{options[:default] ? options[:default].inspect : '[]'}.to_msgpack if respond_to?(:memorized_#{key})
19
+ end
20
+
21
+ def memorize_#{key}
22
+ update_attribute :memorized_#{key}, #{key}_unmemorized.to_msgpack if respond_to?(:memorized_#{key})
23
+ end
24
+
25
+ def #{key}
26
+ @#{key} ||= if respond_to?(:memorized_#{key})
27
+ if not memorized_#{key}.blank?
28
+ MessagePack.unpack(memorized_#{key})
29
+ elsif #{!!options[:on_view]}
30
+ memorize_#{key}
31
+ #{key}
32
+ else
33
+ #{key}_unmemorized
34
+ end
35
+ else
36
+ #{key}_unmemorized
37
+ end
38
+ end
39
+ END
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+ module RailheadMemorizeLoader
46
+
47
+ def self.included(base)
48
+ base.extend ClassMethods
49
+ end
50
+
51
+ module ClassMethods
52
+
53
+ def use_memorize
54
+ include RailheadMemorize
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ ActiveRecord::Base.send :include, RailheadMemorizeLoader
61
+
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "railhead_memorize"
3
+ s.version = "0.0.1"
4
+ s.date = "2011-03-06"
5
+ s.summary = "RailheadMemorize is a Ruby on Rails plugin that easily memorize model functions."
6
+ s.email = "nagybence@tipogral.hu"
7
+ s.homepage = "http://github.com/nagybence/railhead_memorize"
8
+ s.description = "RailheadMemorize is a Ruby on Rails plugin that easily memorize model functions."
9
+ s.has_rdoc = true
10
+ s.authors = ["Bence Nagy"]
11
+ s.files = ["MIT-LICENSE",
12
+ "README.rdoc",
13
+ "init.rb",
14
+ "railhead_memorize.gemspec",
15
+ "lib/railhead_memorize.rb"]
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.extra_rdoc_files = ["README.rdoc"]
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railhead_memorize
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Bence Nagy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-06 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: RailheadMemorize is a Ruby on Rails plugin that easily memorize model functions.
23
+ email: nagybence@tipogral.hu
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - MIT-LICENSE
32
+ - README.rdoc
33
+ - init.rb
34
+ - railhead_memorize.gemspec
35
+ - lib/railhead_memorize.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/nagybence/railhead_memorize
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --main
43
+ - README.rdoc
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: RailheadMemorize is a Ruby on Rails plugin that easily memorize model functions.
71
+ test_files: []
72
+