Skip to content

Commit

Permalink
Added gemspec and rake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
soveran committed May 27, 2009
1 parent ea13a57 commit 507f19d
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pkg
test/db
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2009 Michel Martens and Damian Janowski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
74 changes: 74 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Ohm
============

Object-hash mapping library for Redis.

Description
-----------

Ohm is a library that allows to store an object in
[Redis](http://code.google.com/p/redis/), a persistent key-value
database. It includes an extensible list of validations and has very
good performance.

Usage
-----

require 'ohm'

$redis = Redis.new

class Event < Ohm::Model
attribute :name
set :participants

def validate
assert_present :name
end
end

event = Event.create(:name => "Ruby Tuesday")
event.participants << "Michel Martens"
event.participants << "Damian Janowski"

another_event = Event.new
another_event.valid? #=> false
another_event.errors #=> [[:name, :nil]]

another_event.name = ""
another_event.valid? #=> false
another_event.errors #=> [[:name, :empty]]

another_event.name = "Ruby Lunch"
another_event.save #=> true

Installation
------------

$ sudo gem install ohm

License
-------

Copyright (c) 2009 Michel Martens and Damian Janowski

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
28 changes: 26 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
require "rake/testtask"
require 'rake/gempackagetask'

task :default => :test

gem_spec_file = 'ohm.gemspec'
gem_spec = eval(File.read(gem_spec_file)) rescue nil

desc 'Run all tests'
Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*_test.rb']
Rake::TestTask.new(:test) do |t|
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

Rake::GemPackageTask.new(gem_spec) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
rm_f FileList['pkg/**/*.*']
end if gem_spec

desc "Generate the gemspec file."
task :gemspec do
require 'erb'

File.open(gem_spec_file, 'w') do |f|
f.write ERB.new(File.read("#{gem_spec_file}.erb")).result(binding)
end
end

desc "Builds and installs the gem."
task :install => :repackage do
`sudo gem install pkg/#{gem_spec.name}-#{gem_spec.version}.gem`
end
19 changes: 19 additions & 0 deletions ohm.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Gem::Specification.new do |s|
s.name = 'ohm'
s.version = '0.0.1'
s.summary = %{Object-hash mapping library for Redis.}
s.date = %q{2009-03-13}
s.author = "Michel Martens, Damian Janowski"
s.email = "[email protected]"
s.homepage = "http://github.com/soveran/ohm"

s.specification_version = 2 if s.respond_to? :specification_version=

s.files = ["lib/ohm.rb", "README.markdown", "LICENSE", "Rakefile", "test/all_tests.rb", "test/benchmarks.rb", "test/db/dump.rdb", "test/db/redis.pid", "test/model_test.rb", "test/test.conf", "test/test_helper.rb", "test/validations_test.rb"]

s.require_paths = ['lib']

s.add_dependency("redis", ">= 1.0")

s.has_rdoc = false
end
19 changes: 19 additions & 0 deletions ohm.gemspec.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Gem::Specification.new do |s|
s.name = 'ohm'
s.version = '0.0.1'
s.summary = %{Object-hash mapping library for Redis.}
s.date = %q{2009-03-13}
s.author = "Michel Martens, Damian Janowski"
s.email = "[email protected]"
s.homepage = "http://github.com/soveran/ohm"

s.specification_version = 2 if s.respond_to? :specification_version=

s.files = <%= FileList['lib/**/*.rb', 'README*', 'LICENSE', 'Rakefile', 'test/**/*.*'].inspect %>

s.require_paths = ['lib']

s.add_dependency("redis", ">= 1.0")

s.has_rdoc = false
end
8 changes: 4 additions & 4 deletions test/validations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Validatable

include Ohm::Validations
end

setup do
@target = Validatable.new
end
Expand Down Expand Up @@ -122,15 +122,15 @@ def @target.validate

assert_equal [[:name, :nil]], @target.errors
end

should "fail when the attribute is empty" do
@target.name = ""
@target.validate

assert_equal [[:name, :empty]], @target.errors
end
end

context "assert_not_nil" do
should "fail when the attribute is nil" do
def @target.validate
Expand All @@ -140,7 +140,7 @@ def @target.validate
@target.validate

assert_equal [[:name, :nil]], @target.errors

@target.errors.clear
@target.name = ""
@target.validate
Expand Down

0 comments on commit 507f19d

Please sign in to comment.