Class: Serf::Middleware::PolicyChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/serf/middleware/policy_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, *args) ⇒ PolicyChecker

Returns a new instance of PolicyChecker.



10
11
12
13
14
# File 'lib/serf/middleware/policy_checker.rb', line 10

def initialize(app, *args)
  opts = Optser.extract_options! args
  @app = app
  @policy_chain = opts.get :policy_chain, []
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/serf/middleware/policy_checker.rb', line 7

def app
  @app
end

#policy_chainObject (readonly)

Returns the value of attribute policy_chain.



8
9
10
# File 'lib/serf/middleware/policy_checker.rb', line 8

def policy_chain
  @policy_chain
end

Instance Method Details

#call(parcel) ⇒ Object

Iterates the policy chain and does a check for each policy. Assumes that policies will raise errors on any policy failure.



19
20
21
22
23
24
# File 'lib/serf/middleware/policy_checker.rb', line 19

def call(parcel)
  policy_chain.each do |policy|
    policy.check! parcel
  end
  app.call parcel
end