Module: CouchPotato

Defined in:
lib/couch_potato.rb,
lib/couch_potato/railtie.rb,
lib/couch_potato/database.rb,
lib/couch_potato/validation.rb,
lib/couch_potato/view/lists.rb,
lib/couch_potato/persistence.rb,
lib/couch_potato/rspec/matchers.rb,
lib/couch_potato/view/view_query.rb,
lib/couch_potato/persistence/json.rb,
lib/couch_potato/view/custom_views.rb,
lib/couch_potato/view/raw_view_spec.rb,
lib/couch_potato/view/base_view_spec.rb,
lib/couch_potato/view/model_view_spec.rb,
lib/couch_potato/persistence/callbacks.rb,
lib/couch_potato/view/custom_view_spec.rb,
lib/couch_potato/persistence/properties.rb,
lib/couch_potato/persistence/attachments.rb,
lib/couch_potato/persistence/type_caster.rb,
lib/couch_potato/view/properties_view_spec.rb,
lib/couch_potato/persistence/simple_property.rb,
lib/couch_potato/validation/with_validatable.rb,
lib/couch_potato/persistence/dirty_attributes.rb,
lib/couch_potato/persistence/ghost_attributes.rb,
lib/couch_potato/persistence/magic_timestamps.rb,
lib/couch_potato/validation/with_active_model.rb,
lib/couch_potato/rspec/matchers/map_to_matcher.rb,
lib/couch_potato/rspec/matchers/list_as_matcher.rb,
lib/couch_potato/rspec/matchers/reduce_to_matcher.rb,
lib/couch_potato/persistence/active_model_compliance.rb

Defined Under Namespace

Modules: Attachments, GhostAttributes, MagicTimestamps, Persistence, RSpec, Validation, View Classes: Database, Railtie

Constant Summary collapse

DEFAULT_TYPE_FIELD =
'ruby_class'
Config =
Struct.new(:database_name, :validation_framework).new
@@type_field =

The name of the type field of CouchDB documents

DEFAULT_TYPE_FIELD
@@design_name_fun =

The function mapping classes to the corresponding CouchDB design document.

lambda do |klass|
  klass_name = klass.to_s
  klass_name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  klass_name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  klass_name.tr!("-", "_")
  klass_name.downcase
end

Class Method Summary collapse

Class Method Details

.bypass_view_creationObject

We can bypass creation of views completely, so we can use views that are created via other means, such as CouchApp. The default is not to bypass creation. TODO: enable this bypass for specific view in the view specification, instead of globally



6
7
8
# File 'lib/couch_potato/view/view_query.rb', line 6

def self.bypass_view_creation
  @bypass_view_creation
end

.bypass_view_creation=(flag) ⇒ Object



10
11
12
# File 'lib/couch_potato/view/view_query.rb', line 10

def self.bypass_view_creation= flag
  @bypass_view_creation = flag
end

.couchrest_databaseObject

Returns the underlying CouchRest database object if you want low level access to your CouchDB. You have to set the CouchPotato::Config.database_name before this works.



51
52
53
# File 'lib/couch_potato.rb', line 51

def self.couchrest_database
  @@__couchrest_database ||= CouchRest.database(full_url_to_database)
end

.databaseObject

Returns a database instance which you can then use to create objects and query views. You have to set the CouchPotato::Config.database_name before this works.



46
47
48
# File 'lib/couch_potato.rb', line 46

def self.database
  @@__database ||= Database.new(self.couchrest_database)
end

.design_name_funObject

Get the lambda to use for conversion from a class to the design document name



34
35
36
# File 'lib/couch_potato.rb', line 34

def self.design_name_fun
  @@design_name_fun
end

.design_name_fun=(fun) ⇒ Object



38
39
40
# File 'lib/couch_potato.rb', line 38

def self.design_name_fun= fun
  @@design_name_fun = fun
end

.rails_initObject



5
6
7
8
9
10
11
12
13
# File 'lib/couch_potato/railtie.rb', line 5

def self.rails_init
  config = YAML::load(ERB.new(File.read(Rails.root.join('config/couchdb.yml'))).result)[RAILS_ENV]
  if config.is_a?(String)
    CouchPotato::Config.database_name = config
  else
    CouchPotato::Config.database_name = config['database']
    CouchPotato::Config.validation_framework = config['validation_framework']
  end
end

.type_fieldObject

Get the type field name to use. NOTE: this is universal, so will transcend individual databases



25
26
27
# File 'lib/couch_potato.rb', line 25

def self.type_field
  @@type_field
end

.type_field=(type_field) ⇒ Object



29
30
31
# File 'lib/couch_potato.rb', line 29

def self.type_field= type_field
  @@type_field = type_field
end