Sha256: 592e42c77fa16a336f7244e326fdc7de628faac7c6eb99debad8e25e05e0b10b

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module RailsOps
  class Context < ActiveType::Object
    attribute :user
    attribute :ability
    attribute :op_chain, default: []
    attribute :session
    attribute :called_via_hook
    attribute :url_options

    # For compatibility with rails < 4
    if defined?(attr_accessible)
      attr_accessible :user
      attr_accessible :ability
      attr_accessible :op_chain
      attr_accessible :session
      attr_accessible :called_via_hook
      attr_accessible :url_options
    end

    # Returns a copy of the context with the given operation added to the
    # contexts operation chain.
    def spawn(op)
      return Context.new(
        user:            user,
        ability:         ability,
        session:         session,
        op_chain:        op_chain + [op],
        called_via_hook: false,
        url_options:     url_options
      )
    end

    # Runs the given operation in this particular context with the given args
    # using the non-bang `run` method.
    def run(op, *args)
      op.run(self, *args)
    end

    # Runs the given operation in this particular context with the given args
    # using the bang `run!` method.
    def run!(op, *args)
      op.run!(self, *args)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_ops-1.0.2 lib/rails_ops/context.rb