Class: Meshchat::Configuration::AppConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/meshchat/configuration/app_config.rb

Constant Summary collapse

DEFAULTS =
{
  display: Ui::Display::Base,
  client_name: Meshchat.name,
  client_version: Meshchat::VERSION,
  input: Ui::CLI::KeyboardLineInput,
  notifier: Ui::Notifier::Base
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AppConfig

Returns a new instance of AppConfig.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/meshchat/configuration/app_config.rb', line 15

def initialize(options)
  @_options = DEFAULTS.merge(options)
  @_options[:user] = Configuration::Settings.new

  locale_path = 'locale/'
  # I18n.load_path = Dir[locale_path + '*.yml']
  # puts File.read(locale_path)
  root_path = File.dirname(__FILE__)
  full_path = "#{root_path}/../#{locale_path}"
  I18n.backend.store_translations(:en,
    YAML.load(File.read(full_path + 'en.yml')))

  if notifier = options[:notifier]
    notifier_instance = notifier.new
    Meshchat.const_set(:Notify, notifier_instance)
  end

  # The display has to be created right away so that
  # we can start outputting to it
  manager = Ui::Display::Manager.new(options[:display])
  Meshchat.const_set(:Display, manager)
  Meshchat.const_set(:APP_CONFIG, self)

  Meshchat::Display.start
end

Instance Attribute Details

#_optionsObject (readonly)

Returns the value of attribute _options.



13
14
15
# File 'lib/meshchat/configuration/app_config.rb', line 13

def _options
  @_options
end

Instance Method Details

#[](key) ⇒ Object



56
57
58
# File 'lib/meshchat/configuration/app_config.rb', line 56

def [](key)
  _options[key]
end

#[]=(key, value) ⇒ Object



60
61
62
# File 'lib/meshchat/configuration/app_config.rb', line 60

def []=(key, value)
  _options[key] = value
end

#userObject



64
65
66
# File 'lib/meshchat/configuration/app_config.rb', line 64

def user
  _options[:user]
end

#validateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/meshchat/configuration/app_config.rb', line 41

def validate
  # Check user config, go through initial setup if we haven't done so already.
  # This should only need to be done once per user.
  #
  # This will also generate a whatever-alias-you-choose.json that the user
  # can pass around to someone gain access to the network.
  #
  # Personal settings are stored in settings.json. This should never be
  # shared with anyone.
  Identity.check_or_create

  # setup the storage - for keeping track of nodes on the network
  Database.setup_storage
end