Sha256: fc26e6c943aa9a638e416efe1f26dc4855874b42f1bcdfcd0803ddd6551d26b4

Contents?: true

Size: 954 Bytes

Versions: 15

Compression:

Stored size: 954 Bytes

Contents

module Husky
  module Ears

    def listen_to(object)
      object.add_listener(responder_class.new(self))
    end

    def responder_class
      raise "Rails is not running" unless defined?(Rails)
      "#{controller_name.camelize}Responder".constantize
    end

    def husky_responder
      responder_class.new(self)
    end

    def interact(interactor)
      yield(interactor) if block_given?
      interactor.add_listener(husky_responder)
      interactor.run
    end

    def deliver_entities(entities, *options)
      raise "Rails is not running" unless defined?(Rails)
      serve_for(entities.map(&:object), *options)
    end

    def deliver_entity(entity, *options)
      raise "Rails is not running" unless defined?(Rails)
      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

15 entries across 15 versions & 1 rubygems

Version Path
husky-0.5.5 lib/husky/ears.rb
husky-0.5.4 lib/husky/ears.rb
husky-0.5.3 lib/husky/ears.rb
husky-0.5.1 lib/husky/ears.rb
husky-0.5.0 lib/husky/ears.rb
husky-0.4.9 lib/husky/ears.rb
husky-0.4.8 lib/husky/ears.rb
husky-0.4.7 lib/husky/ears.rb
husky-0.4.6 lib/husky/ears.rb
husky-0.4.5 lib/husky/ears.rb
husky-0.4.4 lib/husky/ears.rb
husky-0.4.3 lib/husky/ears.rb
husky-0.4.2 lib/husky/ears.rb
husky-0.4.1 lib/husky/ears.rb
husky-0.4.0 lib/husky/ears.rb