Class: Arrthorizer::Context
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Arrthorizer::Context
- Defined in:
- lib/arrthorizer/context.rb
Overview
Make it possible to specify the context that Arrthorizer can evaluate from inside the controller:
class MyController
to_prepare_context do |c|
c.defaults do
{ bookcase: Cms::Bookcase.find(params[:id]) }
end
c.for_action(:some_action) do
arrthorizer_defaults.merge({ bookcase: Cms::Book.find(params[:id]).bookcase })
end
end
end
class MyController
to_prepare_context do |c|
c.defaults do
params
end
end
end
In non-Rails environments:
class MySomething
# probably include something like Arrthorizer::Config
to_prepare_context do |c|
c.defaults do
{ bookcase: Cms::Bookcase.find(params[:id]) }
end
if params[:action] == :edit
arrthorizer_defaults.merge { author: User.find(params[:author_id] }
end
end
end
Constant Summary collapse
- ConversionError =
Class.new(Arrthorizer::ArrthorizerException)
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(attrs = {}) ⇒ Context
constructor
A new instance of Context.
- #merge(hash) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Context
Returns a new instance of Context.
52 53 54 |
# File 'lib/arrthorizer/context.rb', line 52 def initialize(attrs = {}) super(attrs.to_hash || attrs.marshal_dump) end |
Class Method Details
.build(attrs = {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/arrthorizer/context.rb', line 44 def self.build(attrs = {}) if attrs.is_a? Context attrs else new(attrs) end end |
Instance Method Details
#==(other) ⇒ Object
68 69 70 |
# File 'lib/arrthorizer/context.rb', line 68 def ==(other) to_hash == other.to_hash end |
#eql?(other) ⇒ Boolean
64 65 66 |
# File 'lib/arrthorizer/context.rb', line 64 def eql?(other) self == other end |
#merge(hash) ⇒ Object
56 57 58 |
# File 'lib/arrthorizer/context.rb', line 56 def merge(hash) self.class.new(to_hash.merge(hash)) end |
#to_hash ⇒ Object
60 61 62 |
# File 'lib/arrthorizer/context.rb', line 60 def to_hash marshal_dump end |