Class: Fog::Bouncer::Protocol

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/bouncer/protocols.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, source) ⇒ Protocol

Returns a new instance of Protocol.



15
16
17
18
19
# File 'lib/fog/bouncer/protocols.rb', line 15

def initialize(port, source)
  @from, @to = Protocol.range(port)
  @source = source
  validate
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



4
5
6
# File 'lib/fog/bouncer/protocols.rb', line 4

def from
  @from
end

#localObject

Returns the value of attribute local.



4
5
6
# File 'lib/fog/bouncer/protocols.rb', line 4

def local
  @local
end

#remoteObject



37
38
39
# File 'lib/fog/bouncer/protocols.rb', line 37

def remote
  @remote ||= false
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/fog/bouncer/protocols.rb', line 4

def source
  @source
end

#toObject (readonly)

Returns the value of attribute to.



4
5
6
# File 'lib/fog/bouncer/protocols.rb', line 4

def to
  @to
end

Class Method Details

.range(port) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/fog/bouncer/protocols.rb', line 7

def self.range(port)
  if port.is_a?(Range)
    [port.begin, port.end]
  else
    [port, port]
  end
end

Instance Method Details

#<=>(other) ⇒ Object



55
56
57
# File 'lib/fog/bouncer/protocols.rb', line 55

def <=>(other)
  [from, to] <=> [other.from, other.to]
end

#==(other) ⇒ Object



49
50
51
52
53
# File 'lib/fog/bouncer/protocols.rb', line 49

def ==(other)
  type == other.type &&
  from == other.from &&
  to == other.to
end

#groupObject



21
22
23
# File 'lib/fog/bouncer/protocols.rb', line 21

def group
  source.group
end

#inspectObject



59
60
61
# File 'lib/fog/bouncer/protocols.rb', line 59

def inspect
  "<#{self.class.name} @from=#{from.inspect} @to=#{to.inspect} @local=#{local} @remote=#{remote}>"
end

#local?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fog/bouncer/protocols.rb', line 29

def local?
  !!local
end

#match(type, port) ⇒ Object



33
34
35
# File 'lib/fog/bouncer/protocols.rb', line 33

def match(type, port)
  type.to_s == self.type && Protocol.range(port) == [from, to]
end

#remote?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/fog/bouncer/protocols.rb', line 41

def remote?
  !!remote
end

#to_logObject



63
64
65
# File 'lib/fog/bouncer/protocols.rb', line 63

def to_log
  { source: source.source, protocol: type, from: from, to: to }
end

#typeObject



45
46
47
# File 'lib/fog/bouncer/protocols.rb', line 45

def type
  @type ||= self.class.to_s.gsub("Fog::Bouncer::Protocols::", "").downcase
end