Sha256: 4069c2a3a7b154b84a2c8ffe759229951f77e09d8a47ba0e39f591df2c9b48a5

Contents?: true

Size: 840 Bytes

Versions: 11

Compression:

Stored size: 840 Bytes

Contents

# Here's an example of how you might use this in rails.

# First, be guarded against changes in third-party libraries
module Awareness
  def self.included(base)
    base.class_eval {
      include Surrounded
      include Casting::Client
      delegate_missing_methods
    }
  end
end

class User
  include Awareness
end

class ApplicationController
  include Awareness
end

class SomeUseCase
  extend Surrounded::Context

  initialize(:admin, :other_user, :listener)

  trigger :do_something do
    admin.something
  end

  module Admin
    def something
      puts "Hello, #{other_user}"
      listener.redirect_to('/')
    end
  end
end

class SomethingController < ApplicationController
  def create
    surround(current_user, User.last).do_something
  end

  def surround(admin, other)
    SomeUseCase.new(admin, other, self)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
surrounded-0.9.0 examples/rails.rb
surrounded-0.8.4 examples/rails.rb
surrounded-0.8.3 examples/rails.rb
surrounded-0.8.2 examples/rails.rb
surrounded-0.8.1 examples/rails.rb
surrounded-0.8.0 examples/rails.rb
surrounded-0.7.3 examples/rails.rb
surrounded-0.7.2 examples/rails.rb
surrounded-0.7.1 examples/rails.rb
surrounded-0.7.0 examples/rails.rb
surrounded-0.6.0 examples/rails.rb