Class: DIY::Builder
- Inherits:
-
Object
- Object
- DIY::Builder
- Defined in:
- lib/diy/builder.rb
Instance Method Summary collapse
- #before_send(arg = nil, &block) ⇒ Object
- #client(ip_or_iport) ⇒ Object
- #error_on_stop ⇒ Object
- #filter(reg) ⇒ Object
- #find_worker_keepers ⇒ Object
-
#initialize(server = false, &block) ⇒ Builder
constructor
A new instance of Builder.
- #ip2druby(ip) ⇒ Object
- #ip_or_iport_with_default(ip_or_iport, default_port) ⇒ Object
- #me(ip_or_iport) ⇒ Object (also: #controller)
- #pcapfile(pcaps) ⇒ Object (also: #pcapfiles)
- #run ⇒ Object
- #server(ip_or_iport) ⇒ Object
- #set_filter ⇒ Object
- #timeout(timeout) ⇒ Object
- #use(what) ⇒ Object
Constructor Details
#initialize(server = false, &block) ⇒ Builder
Returns a new instance of Builder.
4 5 6 7 8 |
# File 'lib/diy/builder.rb', line 4 def initialize(server = false, &block) @strategies = [] instance_eval(&block) @server = server end |
Instance Method Details
#before_send(arg = nil, &block) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/diy/builder.rb', line 14 def before_send(arg= nil, &block) if arg @before_send_hook = arg else @before_send_hook = block end end |
#client(ip_or_iport) ⇒ Object
41 42 43 |
# File 'lib/diy/builder.rb', line 41 def client(ip_or_iport) @curi = ip_or_iport_with_default(ip_or_iport, 7878) end |
#error_on_stop ⇒ Object
37 38 39 |
# File 'lib/diy/builder.rb', line 37 def error_on_stop(*) @error_on_stop = true end |
#filter(reg) ⇒ Object
77 78 79 |
# File 'lib/diy/builder.rb', line 77 def filter(reg) @filter = reg end |
#find_worker_keepers ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/diy/builder.rb', line 22 def find_worker_keepers @curi ||= "druby://localhost:7878" @suri ||= "druby://localhost:7879" @me ||= "druby://localhost:7880" # controller drb server DRb.start_service(@me) # client and server drb server @client = DRbObject.new_with_uri(@curi) @server = DRbObject.new_with_uri(@suri) end |
#ip2druby(ip) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/diy/builder.rb', line 64 def ip2druby(ip) if ! ip.include?('://') return "druby://" + ip end return ip end |
#ip_or_iport_with_default(ip_or_iport, default_port) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/diy/builder.rb', line 54 def ip_or_iport_with_default(ip_or_iport, default_port) default_port = default_port.to_s if ! ip_or_iport.include?(':') iport = ip_or_iport + ':' + default_port else iport = ip_or_iport end ip2druby(iport) end |
#me(ip_or_iport) ⇒ Object Also known as: controller
49 50 51 |
# File 'lib/diy/builder.rb', line 49 def me(ip_or_iport) @me = ip_or_iport_with_default(ip_or_iport, 7880) end |
#pcapfile(pcaps) ⇒ Object Also known as: pcapfiles
71 72 73 74 |
# File 'lib/diy/builder.rb', line 71 def pcapfile(pcaps) DIY::Logger.info( "Initialize Offline: #{pcaps.to_a.join(', ')}" ) @offline = DIY::Offline.new(pcaps) end |
#run ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/diy/builder.rb', line 91 def run @offline ||= DIY::Offline.new('pcaps/example.pcap') @strategy_builder = DIY::StrategyBuilder.new @strategies.each { |builder| @strategy_builder.add(builder) } find_worker_keepers set_filter @controller = Controller.new( @client, @server, @offline, @strategy_builder ) @controller.before_send(&@before_send_hook) @controller.timeout(@timeout) if @timeout @controller.error_on_stop if @error_on_stop @controller.run end |
#server(ip_or_iport) ⇒ Object
45 46 47 |
# File 'lib/diy/builder.rb', line 45 def server(ip_or_iport) @suri = ip_or_iport_with_default(ip_or_iport, 7879) end |
#set_filter ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/diy/builder.rb', line 81 def set_filter if @filter @client.filter(@filter) @server.filter(@filter) else @client.filter("") @server.filter("") end end |
#timeout(timeout) ⇒ Object
33 34 35 |
# File 'lib/diy/builder.rb', line 33 def timeout(timeout) @timeout = timeout end |
#use(what) ⇒ Object
10 11 12 |
# File 'lib/diy/builder.rb', line 10 def use(what) @strategies << what end |