class TheFox::OSP::Host
Attributes
created_at[RW]
hashes[R]
name[R]
osp[R]
password[W]
updated_at[RW]
Public Class Methods
from_h(host)
click to toggle source
# File lib/osp/host.rb, line 107 def self.from_h(host) h = self.new host.each do |k, v| h.method("#{k}=").call(v) end h end
new(osp = nil)
click to toggle source
# File lib/osp/host.rb, line 16 def initialize(osp = nil) @osp = osp @version = 1 @created_at = DateTime.now @updated_at = DateTime.now @name = nil @generation = 1 @length = 16 @symbols = 1 @hashes = @osp.nil? ? nil : @osp.hashes @password = nil end
Public Instance Methods
generate_password(regenerate = false)
click to toggle source
# File lib/osp/host.rb, line 79 def generate_password(regenerate = false) if @password.nil? && !@osp.nil? || regenerate @password = @osp.password(@name, @length, @generation, @symbols) end end
generation()
click to toggle source
# File lib/osp/host.rb, line 55 def generation @generation.to_i end
generation=(v)
click to toggle source
# File lib/osp/host.rb, line 51 def generation=(v) @generation = v.to_i end
has_generated_password?()
click to toggle source
# File lib/osp/host.rb, line 90 def has_generated_password? !@password.nil? end
hashes=(v)
click to toggle source
# File lib/osp/host.rb, line 75 def hashes=(v) @hashes = v end
length()
click to toggle source
# File lib/osp/host.rb, line 63 def length @length.to_i end
length=(v)
click to toggle source
# File lib/osp/host.rb, line 59 def length=(v) @length = v.to_i end
name=(v)
click to toggle source
# File lib/osp/host.rb, line 47 def name=(v) @name = v == '' ? nil : v end
osp=(v)
click to toggle source
# File lib/osp/host.rb, line 31 def osp=(v) if !v.is_a?(OSP) raise ArgumentError, "Wrong type -- #{v.class}" end @osp = v end
password()
click to toggle source
# File lib/osp/host.rb, line 85 def password generate_password @password end
symbols()
click to toggle source
# File lib/osp/host.rb, line 71 def symbols @symbols.to_i end
symbols=(v)
click to toggle source
# File lib/osp/host.rb, line 67 def symbols=(v) @symbols = v.to_i end
to_h()
click to toggle source
# File lib/osp/host.rb, line 94 def to_h { 'version' => @version, 'created_at' => @created_at.to_s, 'name' => @name, 'generation' => @generation, 'length' => @length, 'symbols' => @symbols, 'hashes' => @hashes, } end
version()
click to toggle source
# File lib/osp/host.rb, line 43 def version @version.to_i end
version=(v)
click to toggle source
# File lib/osp/host.rb, line 39 def version=(v) @version = v.to_i end