lib/azeroth/request_handler.rb in azeroth-0.6.5 vs lib/azeroth/request_handler.rb in azeroth-0.7.0

- old
+ new

@@ -16,13 +16,14 @@ autoload :Show, 'azeroth/request_handler/show' autoload :Update, 'azeroth/request_handler/update' # @param controller [ApplicationController] # @param model [Azeroth::Model] - def initialize(controller, model) + def initialize(controller, model, options) @controller = controller @model = model + @options = options end # process the request # # No action is performd when format is HTML @@ -42,11 +43,11 @@ end end private - attr_reader :controller, :model + attr_reader :controller, :model, :options # @method controller # @api private # @private # # Controller to receive the message @@ -59,10 +60,18 @@ # # Model interface # # @return [Azeroth::Model] + # @method options + # @api private + # @private + # + # Handling options + # + # @return [Azeroth::Options] + delegate :params, to: :controller # @method params # @api private # @private # @@ -101,8 +110,36 @@ # status differently # # @return [Symbol] def status :ok + end + + # @private + # + # Run a block triggering the event + # + # @return [Object] Result of given block + def trigger_event(event, &block) + options.event_dispatcher(event) + .dispatch(controller, &block) + end + + # @private + # + # Attributes to be used on resource creating + # + # @return [Hash] + def attributes + @attributes ||= controller.send("#{model.name}_params") + end + + # @private + # + # Collection scope of the resource + # + # @return [ActiveRecord::Relation] + def collection + @collection = controller.send(model.plural) end end end