Sha256: 32cab2f5d078e011f091942156b1c6952f8e9a8624c431f90fd48bc732ec8092

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

module Bowline
  module Binders
    class Collection < Base
      class << self
        # Associate the binder with a model to setup callbacks so 
        # changes to the model are automatically reflected in the view.
        # Example:
        #   bind Post
        #
        # When the bound class is created/updated/deleted
        # the binder's callbacks are executed and the view
        # updated accordingly.
        # 
        # Classes inheriting from ActiveRecord and SuperModel are 
        # automatically compatible, but if you're using your own custom model
        # you need to make sure it responds to the following methods:
        #  * all                    - return all records
        #  * find(id)               - find record by id
        #  * after_create(method)   - after_create callback
        #  * after_update(method)   - after_update callback
        #  * after_destroy(method)  - after_destroy callback
        #
        # The klass' instance needs to respond to:
        #   * id      - returns record id
        #   * to_js   - return record's attribute hash
        #
        # You can override the to_js method on the model instance
        # in order to return specific attributes for the view.
        def bind(klass)
          @klass = klass
          observer = Observer.new(self)
          @klass.add_observer(observer)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bowline-0.9.4 lib/bowline/binders/collection.rb
bowline-0.9.3 lib/bowline/binders/collection.rb
bowline-0.9.2 lib/bowline/binders/collection.rb
bowline-0.9.1 lib/bowline/binders/collection.rb
bowline-0.6.3 lib/bowline/binders/collection.rb
bowline-0.6.2 lib/bowline/binders/collection.rb
bowline-0.6.1 lib/bowline/binders/collection.rb
bowline-0.6.0 lib/bowline/binders/collection.rb