Sha256: ab840febf7ef7cf8ca885fa932466301a384fbac0ba4daff1015e45b5e845c06

Contents?: true

Size: 736 Bytes

Versions: 20

Compression:

Stored size: 736 Bytes

Contents

module Husky
  module Ears

    def listen_to(object, listeners = [])
      klass = "#{controller_name.camelize}Responder".constantize
      default = klass.new(self)
      listeners << default
      listeners.each do |listener|
        object.add_listener(listener)
      end
    end

    def interact(interactor)
      listen_to(interactor)
      interactor.run
    end

    def deliver_entities(entities, *options)
      serve_for(entities.map(&:object), *options)
    end

    def deliver_entity(entity, *options)
      serve_for(entity.object, *options)
    end

    private

    def serve_for(target, *options)
      args = { json: target }
      options.each { |option| args.merge!(option) }
      render(args)
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
husky-0.3.2 lib/husky/ears.rb
husky-0.3.1 lib/husky/ears.rb
husky-0.3.0 lib/husky/ears.rb
husky-0.2.9 lib/husky/ears.rb
husky-0.2.8 lib/husky/ears.rb
husky-0.2.7 lib/husky/ears.rb
husky-0.2.6 lib/husky/ears.rb
husky-0.2.5 lib/husky/ears.rb
husky-0.2.4 lib/husky/ears.rb
husky-0.2.3 lib/husky/ears.rb
husky-0.2.2 lib/husky/ears.rb
husky-0.2.1 lib/husky/ears.rb
husky-0.2.0 lib/husky/ears.rb
husky-0.1.9 lib/husky/ears.rb
husky-0.1.8 lib/husky/ears.rb
husky-0.1.7 lib/husky/ears.rb
husky-0.1.6 lib/husky/ears.rb
husky-0.1.5 lib/husky/ears.rb
husky-0.1.4 lib/husky/ears.rb
husky-0.1.3 lib/husky/ears.rb