Sha256: cb3b12c650be0add924b328aa7da4d9b7d8bcb4a28b442c0e4c16c59057792c5

Contents?: true

Size: 1.27 KB

Versions: 18

Compression:

Stored size: 1.27 KB

Contents

# -*- encoding : utf-8 -*-
module Dao
  class Result < ::Map
    def initialize(*args, &block)
      options = Dao.options_for!(args)

      self.path = args.shift || options[:path] || Path.default
      self.route = options[:route] || Route.default
      self.mode = options[:mode] || Mode.default
      self.status = options[:status] || Status.default
      self.params = options[:params] || Params.new
      self.errors = options[:errors] || Errors.new
      self.data = options[:data] || Data.new
    end

=begin
    %w(
      path
      route
      mode
      status
      params
      errors
      data
    ).each do |attr|

      module_eval <<-__, __FILE__, __LINE__
        def #{ attr }(*value)
          unless value.empty?
            self["#{ attr }"] = value.first
          end
          self["#{ attr }"]
        end

        def #{ attr }=(value)
          self["#{ attr }"] = value
        end
      __

    end

    def name
      path
    end

    def attributes
      params
    end
=end


    def form
      @form ||= (
        Form.new.tap do |f|
          f.object = self
          f.attributes = params
          f.errors = errors
          f.status = status
          f.name = path
        end
      )
    end

    def inspect
      Dao.json_for(self)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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