Class: WebHookPublisher::Acl
- Inherits:
-
Object
- Object
- WebHookPublisher::Acl
show all
- Defined in:
- lib/webhook-publisher/acl.rb
Defined Under Namespace
Classes: AllowRecord, DenyRecord, RecordBase
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Acl
Returns a new instance of Acl.
5
6
7
|
# File 'lib/webhook-publisher/acl.rb', line 5
def initialize
@records = []
end
|
Class Method Details
.with(&block) ⇒ Object
9
10
11
|
# File 'lib/webhook-publisher/acl.rb', line 9
def self.with(&block)
return self.new.with(&block)
end
|
Instance Method Details
#add_allow(ipaddr) ⇒ Object
17
18
19
20
|
# File 'lib/webhook-publisher/acl.rb', line 17
def add_allow(ipaddr)
@records << AllowRecord.new(ipaddr)
return self
end
|
#add_deny(ipaddr) ⇒ Object
22
23
24
25
|
# File 'lib/webhook-publisher/acl.rb', line 22
def add_deny(ipaddr)
@records << DenyRecord.new(ipaddr)
return self
end
|
#allow?(ipaddr) ⇒ Boolean
44
45
46
47
48
49
|
# File 'lib/webhook-publisher/acl.rb', line 44
def allow?(ipaddr)
return @records.inject(true) { |result, record|
result = record.value if record.include?(ipaddr)
result
}
end
|
#deny?(ipaddr) ⇒ Boolean
51
52
53
|
# File 'lib/webhook-publisher/acl.rb', line 51
def deny?(ipaddr)
return !self.allow?(ipaddr)
end
|
#size ⇒ Object
13
14
15
|
# File 'lib/webhook-publisher/acl.rb', line 13
def size
return @records.size
end
|
#with(&block) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/webhook-publisher/acl.rb', line 27
def with(&block)
raise(ArgumentError) unless block_given?
obj = Object.new
this = self
(class << obj; self; end).class_eval {
define_method(:allow) { |ipaddr| this.add_allow(ipaddr) }
define_method(:deny) { |ipaddr| this.add_deny(ipaddr) }
private :allow, :deny
}
obj.instance_eval(&block)
return self
end
|