Skip to content

Commit

Permalink
Made compatible with Merb 1.0 RC1 and added support for merb-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcarey committed Oct 17, 2008
1 parent aed8055 commit 50c25e1
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Generators
@@ -0,0 +1,3 @@
scope 'merb-gen' do
Merb.add_generators File.join(File.dirname(__FILE__), 'lib', 'generators', 'model')
end
55 changes: 51 additions & 4 deletions README.textile
@@ -1,14 +1,18 @@
h2. Overview

merb_relaxdb is a merb plugin that provides integration with CouchDB via the RelaxDB gem.
merb_relaxdb is a merb plugin that provides integration with CouchDB via the RelaxDB gem. Version numbers indicate compatability with Merb. The current version has been tested against merb RC1 (0.9.9).

merb_relaxdb expects your merb app to augment the standard layout as described in the tree below.
The current release includes integration with merb-auth, but this should not yet be considered stable. A sample integration file is included below.

merb_relaxdb expects your merb app to augment the standard layout as described in the following tree.
couchdb.yml is mandatory. Reference data, sample data and views are optional.
couchdb.yml.sample is supplied in this distribution. Copy and modify as necessary.
merb-gen model my_model will create a sample couchdb.yml.

To use merb_relaxdb, list @dependency "merb_relaxdb"@ in the dependency section of your_merb_app/config/init.rb, but not in the @Merb::BootLoader.after_app_loads@ block.
To use merb_relaxdb, list @dependency "merb_relaxdb", "0.9.9"@ in @config/dependencies.rb@ and @use_orm :relaxdb@ in @config/init.rb@

For more details on using RelaxDB, see the "RelaxDB wiki":http://github.com/paulcarey/relaxdb/wikis
<pre>
<code>

my_merb_app $ tree
.
Expand All @@ -30,3 +34,46 @@ For more details on using RelaxDB, see the "RelaxDB wiki":http://github.com/paul
|-- public
|-- scratch
`-- spec

</code>
</pre

h3. Sample merb/merb-auth/setup.rb

<pre>
<code>
begin
Merb::Authentication.user_class = User

# Mixin the salted user mixin
require 'merb-auth-more/mixins/salted_user'
require 'merb_relaxdb/rdb_salted_user'

Merb::Authentication.user_class.class_eval{ include Merb::Authentication::Mixins::SaltedUser }

# Setup the session serialization
class Merb::Authentication

def fetch_user(session_user_id)
RelaxDB.load(session_user_id) rescue nil
end

def store_user(user)
user.nil? ? user : user._id
end
end

rescue => e
Merb.logger.error <<-TEXT

You need to setup some kind of user class with merb-auth.
Merb::Authentication.user_class = User

If you want to fully customize your authentication you should use merb-core directly.

See lib/authentication/setup.rb and strategies.rb to customize your setup

TEXT
end
</code>
</pre>
33 changes: 20 additions & 13 deletions Rakefile
@@ -1,16 +1,17 @@
require 'rubygems'
require 'rake/gempackagetask'
require 'merb-core/tasks/merb_rake_helper'

PLUGIN = "merb_relaxdb"
NAME = "merb_relaxdb"
GEM_VERSION = "0.1.0"
GEM_NAME = "merb_relaxdb"
GEM_VERSION = "0.9.9"
AUTHOR = "Paul Carey"
EMAIL = "paul.p.carey@gmail.com"
HOMEPAGE = "http://github.com/paulcarey/merb_relaxdb/"
SUMMARY = "Merb plugin that provides integration with CouchDB"

spec = Gem::Specification.new do |s|
s.name = NAME
s.name = GEM_NAME
s.version = GEM_VERSION
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
Expand All @@ -20,30 +21,36 @@ spec = Gem::Specification.new do |s|
s.author = AUTHOR
s.email = EMAIL
s.homepage = HOMEPAGE
s.add_dependency('merb', '>= 0.9.4')
s.add_dependency('merb', '>= 0.9.9')

# s.add_dependency('relaxdb', '>= 0.1.0') # causes rake install to fail
# s.add_dependency('paulcarey-relaxdb', '>= 0.1.0') # allows rake install to succeed

s.require_path = 'lib'
s.autorequire = PLUGIN
s.files = %w(LICENSE README.textile Rakefile) + Dir.glob("{lib,spec}/**/*")
s.files = %w(LICENSE README.textile Rakefile Generators) + Dir.glob("{lib,spec}/**/*")
end

Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end

desc "Install"
desc "Install the gem"
task :install => [:package] do
sh %{sudo gem install --local pkg/#{NAME}-#{GEM_VERSION} --no-update-sources}
sh %{sudo gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
end
# task :install do
# Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION, :local => true)
# end

namespace :jruby do
desc "Uninstall the gem"
task :uninstall do
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
end

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh %{#{SUDO} jruby -S gem install pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
desc "Create a gemspec file"
task :gemspec do
File.open("#{GEM_NAME}.gemspec", "w") do |file|
file.puts spec.to_ruby
end

end
end
6 changes: 3 additions & 3 deletions lib/generators/model.rb
@@ -1,4 +1,4 @@
Merb::Generators::ModelGenerator.template :model_relaxdb, :orm => :relaxdb do
source(File.dirname(__FILE__), "templates/model/app/models/%file_name%.rb")
destination("app/models", base_path, "#{file_name}.rb")
Merb::Generators::ModelGenerator.template :model_relaxdb, :orm => :relaxdb do |template|
template.source = File.dirname(__FILE__) / "templates/model/app/models/%file_name%.rb"
template.destination = "app/models" / base_path / "#{file_name}.rb"
end
9 changes: 3 additions & 6 deletions lib/merb_relaxdb.rb
@@ -1,13 +1,13 @@
# make sure we're running inside Merb
if defined?(Merb::Plugins)
dependency "relaxdb"

# Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
Merb::Plugins.config[:merb_relaxdb] = {
:chickens => false
}

Merb::BootLoader.before_app_loads do
require 'relaxdb'
end

Merb::BootLoader.after_app_loads do
Expand All @@ -17,8 +17,5 @@
end

Merb::Plugins.add_rakefiles "merb_relaxdb/merbtasks"

generators = File.join(File.dirname(__FILE__), 'generators')
Merb.add_generators generators / :model

end

end
53 changes: 53 additions & 0 deletions lib/merb_relaxdb/rdb_salted_user.rb
@@ -0,0 +1,53 @@
class Merb::Authentication
module Mixins
module SaltedUser
module RDBClassMethods

def self.extended(base)
base.class_eval do

property :crypted_password
property :salt

before_save :password_checks

def password_checks
if password_required?
return false unless !password.blank? && password == password_confirmation
end
encrypt_password
true
end

end
end

def authenticate(login, password)
login_param = Merb::Authentication::Strategies::Basic::Base.login_param
@u = all.sorted_by(login_param) { |q| q.key(login) }.first
@u && @u.authenticated?(password) ? @u : nil
end

end
end
end
end

class Merb::Authentication
module Mixins
module SaltedUser

def self.included(base)
base.class_eval do
attr_accessor :password, :password_confirmation

include Merb::Authentication::Mixins::SaltedUser::InstanceMethods
extend Merb::Authentication::Mixins::SaltedUser::ClassMethods
extend Merb::Authentication::Mixins::SaltedUser::RDBClassMethods

end
end

end
end
end
8 changes: 5 additions & 3 deletions merb_relaxdb.gemspec
@@ -1,13 +1,14 @@
Gem::Specification.new do |s|
s.name = "merb_relaxdb"
s.version = "0.1.0"
s.date = "2008-08-26"
s.version = "0.9.9"
s.date = "2008-10-17"
s.summary = "Merb plugin that provides integration with CouchDB"
s.email = "paul.p.carey@gmail.com"
s.homepage = "http://github.com/paulcarey/merb_relaxdb/"
s.has_rdoc = false
s.authors = ["Paul Carey"]
s.files = ["LICENSE",
"Generators",
"README.textile",
"Rakefile",
"lib/generators",
Expand All @@ -21,12 +22,13 @@ Gem::Specification.new do |s|
"lib/merb_relaxdb/connection.rb",
"lib/merb_relaxdb/couchdb.yml.sample",
"lib/merb_relaxdb/merbtasks.rb",
"lib/merb_relaxdb/rdb_salted_user.rb",
"lib/merb_relaxdb.rb",
"spec/merb_relaxdb_spec.rb",
"spec/spec_helper.rb"]
s.bindir = "bin"
s.autorequire = "merb_relaxdb"
s.add_dependency "merb", ">= 0.9.4" # removed ", runtime" as was failing locally
s.add_dependency "merb", ">= 0.9.9" # removed ", runtime" as was failing locally
s.require_paths = ["lib"]
s.required_rubygems_version = ">= 0"
end

0 comments on commit 50c25e1

Please sign in to comment.