Sha256: b4da303912ce4b5dfd384928f81b0549271db1ad080780acf7f9ea3bc537465b

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  def run(operation, params=self.params, *dependencies)
    if operation < Trailblazer::Operation
      super
    else
      result = operation.({params: _run_params(self.params) }.merge(*_run_runtime_options(*dependencies)))

      @model = result[:model]
      @form  = Rails::Form.new( result[ "contract.default" ], @model.class )

      yield(result) if result.success? && block_given?

      @_result = result
    end
  end

  private

  def _run_options(options)
    options.merge("current_user" => "user_name" )
  end

  class Rails::Form < SimpleDelegator
    def initialize(delegated, model_class)
      super(delegated)
      @model_class = model_class
    end

    def self.name
      # for whatever reason, validations climb up the inheritance tree and require _every_ class to have a name (4.1).
      "Reform::Form"
    end

    def model_name
      ::ActiveModel::Name.new(self, nil, @model_class.to_s.camelize)
    end

    def to_model
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-future-2.1.0.rc1 test/rails5.0/app/controllers/application_controller.rb