Sha256: d1afe9ec7c6596c0af392694aee607f77b2ceff22d08bc9005d8b54dbc477468

Contents?: true

Size: 1.99 KB

Versions: 6

Compression:

Stored size: 1.99 KB

Contents

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
        add_config :mass_assign_any_attribute
        add_config :auto_update_design_doc
        add_config :environment
        add_config :connection
        add_config :connection_config_file

        configure do |config|
          config.model_type_key = 'type' # was 'couchrest-type'
          config.mass_assign_any_attribute = false
          config.auto_update_design_doc = true

          config.environment = :development
          config.connection_config_file = File.join(Dir.pwd, 'config', 'couchdb.yml')
          config.connection = {
            :protocol => 'http',
            :host     => 'localhost',
            :port     => '5984',
            :prefix   => 'couchrest',
            :suffix   => nil,
            :join     => '_',
            :username => nil,
            :password => nil
          }
        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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
openlogic-couchrest_model-1.0.0 lib/couchrest/model/configuration.rb
couchrest_model-1.1.2 lib/couchrest/model/configuration.rb
couchrest_model-1.1.1 lib/couchrest/model/configuration.rb
couchrest_model-1.1.0 lib/couchrest/model/configuration.rb
couchrest_model-1.1.0.rc1 lib/couchrest/model/configuration.rb
couchrest_model-1.1.0.beta5 lib/couchrest/model/configuration.rb