class SecondStep::Config

Public Class Methods

new(&block) click to toggle source
# File lib/second_step/config.rb, line 23
def initialize(&block)
  self.instance_eval(&block)
end

Private Class Methods

config_option(name, default_value=nil, setter: nil, before_set: nil, after_set: nil, getter: nil, &default) click to toggle source

A dry way of specifing config options.

# File lib/second_step/config.rb, line 30
def config_option(name, default_value=nil, setter: nil, before_set: nil,
                  after_set: nil, getter: nil, &default)
  instance_eval { define_method name do |new_value=nil|
    var = "@#{name}"
    value = if new_value
      new_value = instance_exec(new_value, &setter) if setter
      instance_exec new_value, &before_set if before_set
      new_value = instance_variable_set var, new_value
      instance_exec new_value, &after_set if after_set
      new_value
    else
      instance_variable_get var
    end
    value ||= default ? instance_eval(&default) : instance_variable_set(var, default_value)  # For some reason, removing instance_eval on Ruby 2.3.0 causes a segfault when api_path is accessed.
    (value && getter) ? getter.call(value) : value
  end }
end

Public Instance Methods

base_path() click to toggle source
# File lib/second_step/config.rb, line 104
def base_path
  (@base_path ||= (secondstep_path + api_path).save!).new
end
path(*args) click to toggle source
# File lib/second_step/config.rb, line 49
def path(*args)
  PathBuilder.new(*args)
end
phrase_entropy() click to toggle source
# File lib/second_step/config.rb, line 98
def phrase_entropy
  @phrase_entropy ||= Math.log2 phrase_possibility_count
end
phrase_possibility_count() click to toggle source
# File lib/second_step/config.rb, line 95
def phrase_possibility_count
  @phrase_possibility_count ||= (word_list_count ** phrase_generator_length) * phrase_delimiters.length
end
public_key() click to toggle source
# File lib/second_step/config.rb, line 107
def public_key
  rsa_key.public_key
end
secondstep_path() click to toggle source
# File lib/second_step/config.rb, line 101
def secondstep_path
  path self.secondstep_uri
end
word_list_count() click to toggle source
# File lib/second_step/config.rb, line 92
def word_list_count
  @word_list_count ||= `sed -n '$=' #{word_list_path}`.chomp.to_i
end