2010-09-17 23:00:55 +02:00
|
|
|
module CouchRest
|
|
|
|
|
|
|
|
# CouchRest Model Configuration support, stolen from Carrierwave by jnicklas
|
|
|
|
# http://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/uploader/configuration.rb
|
|
|
|
|
|
|
|
module Model
|
|
|
|
module Configuration
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
add_config :model_type_key
|
2010-09-18 15:19:15 +02:00
|
|
|
add_config :mass_assign_any_attribute
|
2011-04-17 02:46:33 +02:00
|
|
|
add_config :auto_update_design_doc
|
2011-04-29 21:40:36 +02:00
|
|
|
add_config :environment
|
|
|
|
add_config :connection
|
|
|
|
add_config :connection_config_file
|
2011-04-17 02:46:33 +02:00
|
|
|
|
2010-09-17 23:00:55 +02:00
|
|
|
configure do |config|
|
2011-04-30 13:13:38 +02:00
|
|
|
config.model_type_key = 'type' # was 'couchrest-type'
|
2010-09-18 15:19:15 +02:00
|
|
|
config.mass_assign_any_attribute = false
|
2011-04-17 02:46:33 +02:00
|
|
|
config.auto_update_design_doc = true
|
2011-04-29 21:40:36 +02:00
|
|
|
|
2011-04-30 00:34:12 +02:00
|
|
|
config.environment = :development
|
|
|
|
config.connection_config_file = File.join(Dir.pwd, 'config', 'couchdb.yml')
|
2011-04-29 21:40:36 +02:00
|
|
|
config.connection = {
|
|
|
|
:protocol => 'http',
|
|
|
|
:host => 'localhost',
|
|
|
|
:port => '5984',
|
2011-04-30 00:34:12 +02:00
|
|
|
:prefix => 'couchrest',
|
2011-04-29 21:40:36 +02:00
|
|
|
:suffix => nil,
|
2011-04-29 23:06:31 +02:00
|
|
|
:join => '_',
|
2011-04-29 21:40:36 +02:00
|
|
|
:username => nil,
|
|
|
|
:password => nil
|
|
|
|
}
|
2010-09-17 23:00:55 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
|
|
|
|
def add_config(name)
|
|
|
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
|
|
def self.#{name}(value=nil)
|
|
|
|
@#{name} = value if value
|
|
|
|
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
|
|
|
|
name = superclass.#{name}
|
|
|
|
return nil if name.nil? && !instance_variable_defined?("@#{name}")
|
|
|
|
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.#{name}=(value)
|
|
|
|
@#{name} = value
|
|
|
|
end
|
|
|
|
|
|
|
|
def #{name}
|
|
|
|
self.class.#{name}
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure
|
|
|
|
yield self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|