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