Class: CouchTap::Changes
- Inherits:
-
Object
- Object
- CouchTap::Changes
- Defined in:
- lib/couch_tap/changes.rb
Constant Summary collapse
- COUCHDB_HEARTBEAT =
30
- INACTIVITY_TIMEOUT =
70
- RECONNECT_TIMEOUT =
15
Instance Attribute Summary collapse
-
#database(opts = nil) ⇒ Object
readonly
Dual-purpose method, accepts configuration of database or returns a previous definition.
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
-
#seq ⇒ Object
Returns the value of attribute seq.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #document(filter = {}, &block) ⇒ Object
-
#initialize(opts = "", &block) ⇒ Changes
constructor
Start a new Changes instance by connecting to the provided CouchDB to see if the database exists.
-
#schema(name) ⇒ Object
END DSL.
-
#start ⇒ Object
Start listening to the CouchDB changes feed.
Constructor Details
#initialize(opts = "", &block) ⇒ Changes
Start a new Changes instance by connecting to the provided CouchDB to see if the database exists.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/couch_tap/changes.rb', line 15 def initialize(opts = "", &block) raise "Block required for changes!" unless block_given? @schemas = {} @handlers = [] @source = CouchRest.database(opts) info = @source.info logger.info "Connected to CouchDB: #{info['db_name']}" # Prepare the definitions instance_eval(&block) end |
Instance Attribute Details
#database(opts = nil) ⇒ Object (readonly)
Dual-purpose method, accepts configuration of database or returns a previous definition.
33 34 35 |
# File 'lib/couch_tap/changes.rb', line 33 def database @database end |
#handlers ⇒ Object (readonly)
Returns the value of attribute handlers.
9 10 11 |
# File 'lib/couch_tap/changes.rb', line 9 def handlers @handlers end |
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
9 10 11 |
# File 'lib/couch_tap/changes.rb', line 9 def schemas @schemas end |
#seq ⇒ Object
Returns the value of attribute seq.
11 12 13 |
# File 'lib/couch_tap/changes.rb', line 11 def seq @seq end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/couch_tap/changes.rb', line 9 def source @source end |
Instance Method Details
#document(filter = {}, &block) ⇒ Object
41 42 43 |
# File 'lib/couch_tap/changes.rb', line 41 def document(filter = {}, &block) @handlers << DocumentHandler.new(self, filter, &block) end |
#schema(name) ⇒ Object
END DSL
47 48 49 |
# File 'lib/couch_tap/changes.rb', line 47 def schema(name) @schemas[name.to_sym] ||= Schema.new(database, name) end |
#start ⇒ Object
Start listening to the CouchDB changes feed. Must be called from a EventMachine run block for the HttpRequest to take control. By this stage we should have a sequence id so we know where to start from and all the filters should have been prepared.
55 56 57 58 |
# File 'lib/couch_tap/changes.rb', line 55 def start prepare_parser perform_request end |