paulcarey-merb_relaxdb 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
data/Generators ADDED
@@ -0,0 +1,3 @@
1
+ scope 'merb-gen' do
2
+ Merb.add_generators File.join(File.dirname(__FILE__), 'lib', 'generators', 'model')
3
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Paul Carey
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.textile ADDED
@@ -0,0 +1,79 @@
1
+ h2. Overview
2
+
3
+ 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).
4
+
5
+ The current release includes integration with merb-auth, but this should not yet be considered stable. A sample integration file is included below.
6
+
7
+ merb_relaxdb expects your merb app to augment the standard layout as described in the following tree.
8
+ couchdb.yml is mandatory. Reference data, sample data and views are optional.
9
+ merb-gen model my_model will create a sample couchdb.yml.
10
+
11
+ To use merb_relaxdb, list @dependency "merb_relaxdb", "0.9.9"@ in @config/dependencies.rb@ and @use_orm :relaxdb@ in @config/init.rb@
12
+
13
+ For more details on using RelaxDB, see the "RelaxDB wiki":http://github.com/paulcarey/relaxdb/wikis
14
+ <pre>
15
+ <code>
16
+
17
+ my_merb_app $ tree
18
+ .
19
+ |-- Rakefile
20
+ |-- app
21
+ |-- autotest
22
+ |-- config
23
+ | |-- couchdb.yml
24
+ |-- couchdb
25
+ | |-- data
26
+ | | |-- reference
27
+ | | | `-- reference_data.rb
28
+ | | `-- sample
29
+ | | `-- sample_data.rb
30
+ | `-- views
31
+ | `-- views.js
32
+ |-- lib
33
+ |-- log
34
+ |-- public
35
+ |-- scratch
36
+ `-- spec
37
+
38
+ </code>
39
+ </pre
40
+
41
+ h3. Sample merb/merb-auth/setup.rb
42
+
43
+ <pre>
44
+ <code>
45
+ begin
46
+ Merb::Authentication.user_class = User
47
+
48
+ # Mixin the salted user mixin
49
+ require 'merb-auth-more/mixins/salted_user'
50
+ require 'merb_relaxdb/rdb_salted_user'
51
+
52
+ Merb::Authentication.user_class.class_eval{ include Merb::Authentication::Mixins::SaltedUser }
53
+
54
+ # Setup the session serialization
55
+ class Merb::Authentication
56
+
57
+ def fetch_user(session_user_id)
58
+ RelaxDB.load(session_user_id) rescue nil
59
+ end
60
+
61
+ def store_user(user)
62
+ user.nil? ? user : user._id
63
+ end
64
+ end
65
+
66
+ rescue => e
67
+ Merb.logger.error <<-TEXT
68
+
69
+ You need to setup some kind of user class with merb-auth.
70
+ Merb::Authentication.user_class = User
71
+
72
+ If you want to fully customize your authentication you should use merb-core directly.
73
+
74
+ See lib/authentication/setup.rb and strategies.rb to customize your setup
75
+
76
+ TEXT
77
+ end
78
+ </code>
79
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'merb-core/tasks/merb_rake_helper'
4
+
5
+ PLUGIN = "merb_relaxdb"
6
+ GEM_NAME = "merb_relaxdb"
7
+ GEM_VERSION = "0.9.9"
8
+ AUTHOR = "Paul Carey"
9
+ EMAIL = "paul.p.carey@gmail.com"
10
+ HOMEPAGE = "http://github.com/paulcarey/merb_relaxdb/"
11
+ SUMMARY = "Merb plugin that provides integration with CouchDB"
12
+
13
+ spec = Gem::Specification.new do |s|
14
+ s.name = GEM_NAME
15
+ s.version = GEM_VERSION
16
+ s.platform = Gem::Platform::RUBY
17
+ s.has_rdoc = true
18
+ s.extra_rdoc_files = ["README.textile", "LICENSE"]
19
+ s.summary = SUMMARY
20
+ s.description = s.summary
21
+ s.author = AUTHOR
22
+ s.email = EMAIL
23
+ s.homepage = HOMEPAGE
24
+ s.add_dependency('merb', '>= 0.9.9')
25
+
26
+ # s.add_dependency('relaxdb', '>= 0.1.0') # causes rake install to fail
27
+ # s.add_dependency('paulcarey-relaxdb', '>= 0.1.0') # allows rake install to succeed
28
+
29
+ s.require_path = 'lib'
30
+ s.autorequire = PLUGIN
31
+ s.files = %w(LICENSE README.textile Rakefile Generators) + Dir.glob("{lib,spec}/**/*")
32
+ end
33
+
34
+ Rake::GemPackageTask.new(spec) do |pkg|
35
+ pkg.gem_spec = spec
36
+ end
37
+
38
+ desc "Install the gem"
39
+ task :install => [:package] do
40
+ sh %{sudo gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
41
+ end
42
+ # task :install do
43
+ # Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION, :local => true)
44
+ # end
45
+
46
+ desc "Uninstall the gem"
47
+ task :uninstall do
48
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
49
+ end
50
+
51
+ desc "Create a gemspec file"
52
+ task :gemspec do
53
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
54
+ file.puts spec.to_ruby
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ Merb::Generators::ModelGenerator.template :model_relaxdb, :orm => :relaxdb do |template|
2
+ template.source = File.dirname(__FILE__) / "templates/model/app/models/%file_name%.rb"
3
+ template.destination = "app/models" / base_path / "#{file_name}.rb"
4
+ end
@@ -0,0 +1,4 @@
1
+ <% with_modules(modules) do -%>
2
+ class <%= class_name %> < RelaxDB::Document
3
+ end
4
+ <% end -%>
@@ -0,0 +1,44 @@
1
+ module Merb
2
+ module RelaxDB
3
+
4
+ class << self
5
+
6
+ def config_file() Merb.dir_for(:config) / "couchdb.yml" end
7
+ def sample_dest() Merb.dir_for(:config) / "couchdb.yml.sample" end
8
+ def sample_source() File.dirname(__FILE__) / "couchdb.yml.sample" end
9
+
10
+ def connect
11
+ begin
12
+ configure_db
13
+ ::RelaxDB.db.get
14
+ Merb.logger.info "RelaxDB connected to CouchDB #{::RelaxDB.db.uri}"
15
+ rescue => e
16
+ uri = ::RelaxDB.db ? ::RelaxDB.db.uri : "<initialisation error>"
17
+ Merb.logger.fatal "RelaxDB could not connect to CouchDB at #{uri} \n\tRoot cause:#{e}\n#{e.backtrace.join("\n")}"
18
+ exit(1)
19
+ end
20
+ end
21
+
22
+ def configure_db
23
+ if File.exists?(config_file)
24
+ full_config = Erubis.load_yaml_file(config_file)
25
+ config = full_config[Merb.environment.to_sym]
26
+ config[:logger] = Merb.logger
27
+ ::RelaxDB.configure(config)
28
+ ::RelaxDB.use_db(config[:db])
29
+ else
30
+ copy_sample_config
31
+ Merb.logger.error! "No couchdb.yml file found in #{Merb.root}/config."
32
+ Merb.logger.error! "A sample file was created called couchdb.yml.sample for you to copy and edit."
33
+ exit(1)
34
+ end
35
+ end
36
+
37
+ def copy_sample_config
38
+ FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ :development:
2
+ :host: localhost
3
+ :port: 5984
4
+ :db: mydb_dev
5
+
6
+ :test:
7
+ :host: localhost
8
+ :port: 5984
9
+ :db: mydb_test
@@ -0,0 +1,40 @@
1
+ desc "Create CouchDB environment from scratch"
2
+ task :relaxdb => ["relaxdb:db", "relaxdb:views", "relaxdb:data", "relaxdb:sample"]
3
+
4
+ namespace :relaxdb do
5
+
6
+ desc "Create CouchDB database"
7
+ task :db => [:check_env, :merb_env] do
8
+ RelaxDB.delete_db(RelaxDB.db.name) rescue "ok"
9
+ RelaxDB.use_db(RelaxDB.db.name)
10
+ end
11
+
12
+ desc "Create CouchDB views"
13
+ task :views => [:check_env, :merb_env] do
14
+ Dir['couchdb/views/**/*.js'].each do |filename|
15
+ RelaxDB::ViewUploader.upload(filename)
16
+ end
17
+ end
18
+
19
+ desc "Create CouchDB reference data"
20
+ task :data => [:check_env, :merb_env] do
21
+ Dir['couchdb/data/reference/**/*.rb'].each do |filename|
22
+ require filename
23
+ end
24
+ end
25
+
26
+ desc "Create CouchDB sample data"
27
+ task :sample => [:check_env, :merb_env] do
28
+ Dir['couchdb/data/sample/**/*.rb'].each do |filename|
29
+ require filename
30
+ end
31
+ end
32
+
33
+ task :check_env do
34
+ unless ENV['MERB_ENV']
35
+ puts "MERB_ENV must be specified. Example: rake relaxdb MERB_ENV=development"
36
+ exit(1)
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,53 @@
1
+ class Merb::Authentication
2
+ module Mixins
3
+ module SaltedUser
4
+ module RDBClassMethods
5
+
6
+ def self.extended(base)
7
+ base.class_eval do
8
+
9
+ property :crypted_password
10
+ property :salt
11
+
12
+ before_save :password_checks
13
+
14
+ def password_checks
15
+ if password_required?
16
+ return false unless !password.blank? && password == password_confirmation
17
+ end
18
+ encrypt_password
19
+ true
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ def authenticate(login, password)
26
+ login_param = Merb::Authentication::Strategies::Basic::Base.login_param
27
+ @u = all.sorted_by(login_param) { |q| q.key(login) }.first
28
+ @u && @u.authenticated?(password) ? @u : nil
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ class Merb::Authentication
37
+ module Mixins
38
+ module SaltedUser
39
+
40
+ def self.included(base)
41
+ base.class_eval do
42
+ attr_accessor :password, :password_confirmation
43
+
44
+ include Merb::Authentication::Mixins::SaltedUser::InstanceMethods
45
+ extend Merb::Authentication::Mixins::SaltedUser::ClassMethods
46
+ extend Merb::Authentication::Mixins::SaltedUser::RDBClassMethods
47
+
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ # make sure we're running inside Merb
2
+ if defined?(Merb::Plugins)
3
+ dependency "relaxdb"
4
+
5
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
6
+ Merb::Plugins.config[:merb_relaxdb] = {
7
+ :chickens => false
8
+ }
9
+
10
+ Merb::BootLoader.before_app_loads do
11
+ end
12
+
13
+ Merb::BootLoader.after_app_loads do
14
+ require "yaml"
15
+ require "merb_relaxdb/connection.rb"
16
+ Merb::RelaxDB.connect
17
+ end
18
+
19
+ Merb::Plugins.add_rakefiles "merb_relaxdb/merbtasks"
20
+
21
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "merb_relaxdb" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paulcarey-merb_relaxdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.9
5
+ platform: ruby
6
+ authors:
7
+ - Paul Carey
8
+ autorequire: merb_relaxdb
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-17 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.9
23
+ version:
24
+ description:
25
+ email: paul.p.carey@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - LICENSE
34
+ - Generators
35
+ - README.textile
36
+ - Rakefile
37
+ - lib/generators
38
+ - lib/generators/model.rb
39
+ - lib/generators/templates
40
+ - lib/generators/templates/model
41
+ - lib/generators/templates/model/app
42
+ - lib/generators/templates/model/app/models
43
+ - lib/generators/templates/model/app/models/%file_name%.rb
44
+ - lib/merb_relaxdb
45
+ - lib/merb_relaxdb/connection.rb
46
+ - lib/merb_relaxdb/couchdb.yml.sample
47
+ - lib/merb_relaxdb/merbtasks.rb
48
+ - lib/merb_relaxdb/rdb_salted_user.rb
49
+ - lib/merb_relaxdb.rb
50
+ - spec/merb_relaxdb_spec.rb
51
+ - spec/spec_helper.rb
52
+ has_rdoc: false
53
+ homepage: http://github.com/paulcarey/merb_relaxdb/
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.2.0
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: Merb plugin that provides integration with CouchDB
78
+ test_files: []
79
+