Class: PostPolicy::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/postpolicy/rule.rb

Overview

rule do

sender { format.value "[email protected]" }
recipient { format.regex /lomnicki.com.pl$/ }
action "REJECT"

end

Defined Under Namespace

Classes: Format

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Rule

Returns a new instance of Rule.



38
39
40
# File 'lib/postpolicy/rule.rb', line 38

def initialize( &block )
  instance_eval &block
end

Class Method Details

.rule(&block) ⇒ Object



42
43
44
# File 'lib/postpolicy/rule.rb', line 42

def self.rule( &block )
  AccessManager << new( &block ).to_access
end

Instance Method Details

#action(value) ⇒ Object



54
55
56
# File 'lib/postpolicy/rule.rb', line 54

def action( value )
  @rule_action = value
end

#recipient(&block) ⇒ Object



50
51
52
# File 'lib/postpolicy/rule.rb', line 50

def recipient( &block )
  @rule_recipient = ACL::Recipient.new( Format.class_eval( &block ) )
end

#sender(&block) ⇒ Object



46
47
48
# File 'lib/postpolicy/rule.rb', line 46

def sender( &block )
  @rule_sender = ACL::Sender.new( Format.class_eval( &block ) )
end

#to_accessObject



58
59
60
# File 'lib/postpolicy/rule.rb', line 58

def to_access
  Access.new( [@rule_sender, @rule_recipient].compact, @rule_action )
end