Module | Stella::Utils
In: | lib/stella/utils.rb

A motley collection of methods that Stella loves to call!

### Methods

autoload_vendor binary? bmp? cname domain ec2_ap_east_ipaddr? ec2_cname_to_ipaddr ec2_eu_west_ipaddr? ec2_ipaddr? ec2_us_east_ipaddr? ec2_us_west_ipaddr? external_ip_address gif? hosted_at_ec2? ico? image? image_ext? internal_ip_address ipaddr jpg? local_ipaddr? noindent png? private_ipaddr? require_glob require_vendor service_available? strand valid_hostname? whois write_to_file

### Included Modules

Socket::Constants

### Constants

ADDR_LOCAL | = | IPAddr.new("127.0.0.0/8")
ADDR_CLASSA | = | IPAddr.new("10.0.0.0/8")
ADDR_CLASSB | = | IPAddr.new("172.16.0.0/16")
ADDR_CLASSC | = | IPAddr.new("192.168.0.0/24")
ADDR_EC2_US_EAST | = | %w{ 216.182.224.0/20 72.44.32.0/19 67.202.0.0/18 75.101.128.0/17 174.129.0.0/16 204.236.192.0/18 184.73.0.0/16 184.72.128.0/17 184.72.64.0/18 50.16.0.0/15 }.collect { |ipr| IPAddr.new(ipr.strip) } |  | See: forums.aws.amazon.com/ann.jspa?annID=877
ADDR_EC2_US_WEST | = | %w{ 204.236.128.0/18 184.72.0.0/18 50.18.0.0/18 }.collect { |ipr| IPAddr.new(ipr.strip) }
ADDR_EC2_EU_WEST | = | %w{ 79.125.0.0/17 46.51.128.0/18 46.51.192.0/20 46.137.0.0/17 }.collect { |ipr| IPAddr.new(ipr.strip) }
ADDR_EC2_AP_EAST | = | %w{ 175.41.128.0/18 122.248.192.0/18 }.collect { |ipr| IPAddr.new(ipr.strip) }

### Public Instance methods

autoload_vendor(mod, name, version)

Same as `require_vendor`, but uses `autoload` instead.

binary?(s)

Checks if the file has more than 30% non-ASCII characters. NOTE: how to determine the difference between non-latin and binary?

bmp?(a)

Based on ptools by Daniel J. Berger raa.ruby-lang.org/project/ptools/

cname(host)

Returns a cname or nil

domain(host)
ec2_ap_east_ipaddr?(addr)
ec2_cname_to_ipaddr(cname)
ec2_eu_west_ipaddr?(addr)
ec2_ipaddr?(addr)
ec2_us_east_ipaddr?(addr)
ec2_us_west_ipaddr?(addr)
external_ip_address()

Return the external IP address (the one seen by the internet)

gif?(a)

Based on ptools by Daniel J. Berger raa.ruby-lang.org/project/ptools/

hosted_at_ec2?(hostname, region=nil)
ico?(a)
image?(s)
image_ext?(name)
internal_ip_address()

Return the local IP address which receives external traffic from: coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/ NOTE: This does not open a connection to the IP address.

ipaddr(host)

Returns an Array of ip addresses or nil

jpg?(a)

Based on ptools by Daniel J. Berger raa.ruby-lang.org/project/ptools/

local_ipaddr?(addr)
noindent(str)

Returns `str` with the leading indentation removed. Stolen from github.com/mynyml/unindent/ because it was better.

png?(a)

Based on ptools by Daniel J. Berger raa.ruby-lang.org/project/ptools/

private_ipaddr?(addr)
require_glob(*path)

`require` a glob of files.

- `path` is a list of path elements which is sent to File.join

and then to Dir.glob. The list of files found are sent to require. Nothing is returned but LoadError exceptions are caught. The message is printed to STDERR and the program exits with 7.

require_vendor(name, version)

`require` a library from the vendor directory. The vendor directory should be organized such that `name` and `version` can be used to create the path to the library.

e.g.

        vendor/httpclient-2.1.5.2/httpclient

service_available?(host, port, wait=3)

Checks whether something is listening to a socket.

- `host` A hostname
- `port` The port to check
- `wait` The number of seconds to wait for before timing out.

Returns true if `host` allows a socket connection on `port`. Returns false if one of the following exceptions is raised: Errno::EAFNOSUPPORT, Errno::ECONNREFUSED, SocketError, Timeout::Error

strand( len=8, safe=true )

Generates a string of random alphanumeric characters.

- `len` is the length, an Integer. Default: 8
- `safe` in safe-mode, ambiguous characters are removed (default: true):

          i l o 1 0

valid_hostname?(uri)
whois(host_or_ip)
write_to_file(filename, content, mode, chmod=0600)

A basic file writer

[Validate]