Sha256: 243a22b0bc7832683c62a62188974f88c9a63316ef115feab901c3105f071cd6

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

# -*- encoding : utf-8 -*-
module Dao
  class Context
    Attrs = %w(
      api path route endpoint
      params validator errors status form
      result
      data
      args
    )

    Attrs.each{|a| attr_accessor(a)}

    def Context.attrs
      Attrs
    end

    def Context.for(*args, &block)
      new(*args, &block)
    end

    def initialize(api, path, route, endpoint, params, *args)
      @api = api
      @path = path
      @route = route
      @endpoint = endpoint

      @params = Params.new
      @params.update(params)
      @params.path = @path
      @params.route = @route
      @form = @params.form

      @validator = Validator.new(@params)
      @validator.validations_search_path.unshift(@api.class)

      @validations = @validator.validations

      @params.validator = @validator
      @errors = @validator.errors
      @status = @validator.status

      @result = Result.new
      @result.path = @path
      @result.route = @route
      @result.status = @status
      @result.mode = @api.mode
      @result.params = @params
      @result.errors = @params.errors

      @data = @result.data

      @args = @endpoint.arity < 1 ? [@params, @result] : [@params, @result].slice(0, @endpoint.arity)
    end

    def call
      @api.instance_exec(*@args, &@endpoint)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dao-8.0.1 lib/dao/api/context.rb
dao-8.0.0 lib/dao/api/context.rb
dao-7.0.0 lib/dao/api/context.rb
dao-5.6.1 lib/dao/api/context.rb
dao-5.5.2 lib/dao/api/context.rb
dao-5.5.1 lib/dao/api/context.rb
dao-5.5.0 lib/dao/api/context.rb
dao-5.4.0 lib/dao/api/context.rb
dao-5.3.3 lib/dao/api/context.rb
dao-5.3.2 lib/dao/api/context.rb
dao-5.3.0 lib/dao/api/context.rb
dao-5.2.1 lib/dao/api/context.rb
dao-5.1.2 lib/dao/api/context.rb
dao-5.1.1 lib/dao/api/context.rb
dao-5.0.0 lib/dao/api/context.rb
dao-4.6.4 lib/dao/api/context.rb
dao-4.4.4 lib/dao/api/context.rb
dao-4.4.2 lib/dao/api/context.rb