Module: FIDIUS::Common

Defined in:
lib/fidius-common.rb,
lib/fidius-common/yamldb.rb,
lib/fidius-common/version.rb,
lib/fidius-common/ip-helper.rb

Overview

Common used methods and libraries. You might use these also in a non-FIDIUS context, since there are no other FIDIUS-related dependencies.

Defined Under Namespace

Modules: Db

Constant Summary collapse

VERSION =

Current version number

"0.0.6"

Class Method Summary collapse

Class Method Details

.get_my_ip(iprange) ⇒ String

Returns the IP address of that interface, which would connect to an address of the given iprange.

Thanks to Coderrr (coderrr.wordpress.com) for this implementation.

Parameters:

  • iprange (String)

    The target IP range, e.g. 127.0.0.0/8 or 127.0.0.1.

Returns:

  • (String)

    Your (local) IP address.

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fidius-common/ip-helper.rb', line 18

def self.get_my_ip(iprange)
  # backup setting
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
  UDPSocket.open do |s|
    # udp is stateless, so there is no real connect
    s.connect IPAddr.new(iprange).to_s, 1
    s.addr.last
  end
ensure
  # restore backup
  Socket.do_not_reverse_lookup = orig
end

.install_json_symbol_addonBoolean

Since this addon changes behaviour of to_json, you have to require it explicitly either with this helper method or manually with

require 'fidius-common/json_symbol_addon'

Important note: Both variants will also load and require active_support.

Returns:

  • (Boolean)

    true if the addon was loaded successfully or false if the addon is already loaded.



25
26
27
# File 'lib/fidius-common.rb', line 25

def self.install_json_symbol_addon
  require 'fidius-common/json_symbol_addon'
end