benpickles-contentz 0.2.1

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ben Pickles
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,21 @@
1
+ = contentz
2
+
3
+ Contentz (pronounced "content zee") is an ActiveRecord extension that uses Zlib to compress/uncompress attribute data on write/read.
4
+
5
+ == Usage
6
+
7
+ Require the gem in <tt>config/environment.rb</tt>:
8
+
9
+ Rails::Initializer.run do |config|
10
+ config.gem 'benpickles-contentz', :lib => 'contentz', :source => 'http://gems.github.com'
11
+ end
12
+
13
+ Use the <tt>contentz</tt> method in any ActiveRecord model to apply compression to attribute(s):
14
+
15
+ class Article < ActiveRecord::Base
16
+ contentz :body
17
+ end
18
+
19
+ == Copyright
20
+
21
+ Copyright (c) 2009 Ben Pickles. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "contentz"
8
+ gem.summary = 'Contentz (pronounced "content zee") is an ActiveRecord extension that uses Zlib to compress/uncompress attribute data on write/read.'
9
+ gem.email = "spideryoung@gmail.com"
10
+ gem.homepage = "http://github.com/benpickles/contentz"
11
+ gem.authors = ["Ben Pickles"]
12
+ gem.add_dependency "activerecord"
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ end
17
+
18
+ require 'rake/testtask'
19
+ Rake::TestTask.new(:test) do |test|
20
+ test.libs << 'lib' << 'test'
21
+ test.pattern = 'test/**/*_test.rb'
22
+ test.verbose = true
23
+ end
24
+
25
+ begin
26
+ require 'rcov/rcovtask'
27
+ Rcov::RcovTask.new do |test|
28
+ test.libs << 'test'
29
+ test.pattern = 'test/**/*_test.rb'
30
+ test.verbose = true
31
+ end
32
+ rescue LoadError
33
+ task :rcov do
34
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
35
+ end
36
+ end
37
+
38
+ task :default => :test
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ if File.exist?('VERSION.yml')
43
+ config = YAML.load(File.read('VERSION.yml'))
44
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
+ else
46
+ version = ""
47
+ end
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "contentz #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
54
+
55
+ require File.join(File.dirname(__FILE__), 'test', 'config')
56
+
57
+ namespace :db do
58
+ desc 'Build the MySQL test database.'
59
+ task :build do
60
+ `mysqladmin -u #{DB_USER} create #{DB_NAME}`
61
+ end
62
+
63
+ desc 'Drop the MySQL test database.'
64
+ task :drop do
65
+ `mysqladmin -u #{DB_USER} -f drop #{DB_NAME}`
66
+ end
67
+
68
+ desc 'Rebuild the MySQL test databases'
69
+ task :rebuild => [:drop, :build]
70
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 2
4
+ :patch: 1
data/lib/contentz.rb ADDED
@@ -0,0 +1,29 @@
1
+ module Contentz
2
+ require 'zlib'
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def contentz(*methods)
10
+ methods.each do |name|
11
+ define_method name do
12
+ begin
13
+ data = read_attribute(name)
14
+ Zlib::Inflate.inflate(data.to_s)
15
+ rescue Zlib::BufError
16
+ ''
17
+ end
18
+ end
19
+
20
+ define_method "#{name}=" do |value|
21
+ data = Zlib::Deflate.deflate(value.to_s, Zlib::BEST_COMPRESSION)
22
+ write_attribute(name, data)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ ActiveRecord::Base.send :include, Contentz
data/test/config.rb ADDED
@@ -0,0 +1,2 @@
1
+ DB_USER = 'root'
2
+ DB_NAME = 'contentz_gem_test'
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class ContentzTest < Test::Unit::TestCase
4
+ context 'contextz method defined' do
5
+ test 'on ActiveRecord::Base' do
6
+ assert_respond_to ActiveRecord::Base, :contentz
7
+ end
8
+ end
9
+
10
+ context 'read/write data:' do
11
+ setup do
12
+ Article.contentz :body
13
+ @article = Article.new
14
+ end
15
+
16
+ test 'read non-binary (or unset/nil/empty) content as a blank string' do
17
+ assert_equal '', @article.body
18
+ end
19
+
20
+ test 'store content as binary data' do
21
+ @article.body = 'True or false, yes or no, the choice is yours.'
22
+ assert @article.read_attribute(:body).is_binary_data?
23
+ end
24
+
25
+ test 'store nil as a empty string' do
26
+ @article.body = ''
27
+ assert_equal '', @article.body
28
+ @article.body = nil
29
+ assert_equal '', @article.body
30
+ end
31
+
32
+ test 'write/read correctly' do
33
+ [
34
+ 'Lorem ipsum',
35
+ '!@£$%^&*()œ∑†¥¨πåß∂ƒ©˙∆˚¬Ω≈ç√∫',
36
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' * 666
37
+ ].each do |string|
38
+ @article.body = string
39
+ assert_equal string, @article.body
40
+ end
41
+ end
42
+ end
43
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,5 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :articles, :force => true do |t|
3
+ t.binary :body
4
+ end
5
+ end
data/test/setup.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'config'
2
+ require 'logger'
3
+
4
+ ActiveRecord::Base.configurations = {
5
+ 'test' => {
6
+ :adapter => 'mysql',
7
+ :database => DB_NAME,
8
+ :username => DB_USER
9
+ }
10
+ }
11
+
12
+ ActiveRecord::Base.establish_connection 'test'
13
+
14
+ require 'schema'
15
+
16
+ class Article < ActiveRecord::Base; end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'activerecord'
4
+
5
+ begin
6
+ require 'context'
7
+ rescue LoadError
8
+ puts 'Context not available. Install it with: sudo gem install jeremymcanally-context -s http://gems.github.com'
9
+ exit
10
+ end
11
+
12
+ require 'setup' # ActiveRecord setup.
13
+
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+
17
+ require 'contentz'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benpickles-contentz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Pickles
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: spideryoung@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - VERSION.yml
39
+ - lib/contentz.rb
40
+ - test/config.rb
41
+ - test/contentz_test.rb
42
+ - test/schema.rb
43
+ - test/setup.rb
44
+ - test/test_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/benpickles/contentz
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Contentz (pronounced "content zee") is an ActiveRecord extension that uses Zlib to compress/uncompress attribute data on write/read.
71
+ test_files:
72
+ - test/config.rb
73
+ - test/contentz_test.rb
74
+ - test/schema.rb
75
+ - test/setup.rb
76
+ - test/test_helper.rb