Module: Smartdict

Extended by:
ActiveSupport::Autoload, Smartdict
Includes:
Core
Included in:
Smartdict
Defined in:
lib/smartdict/translator/base.rb,
lib/smartdict.rb,
lib/smartdict/info.rb,
lib/smartdict/errors.rb,
lib/smartdict/models.rb,
lib/smartdict/version.rb,
lib/smartdict/translator.rb

Overview

The very basic translator middleware.

Defined Under Namespace

Modules: Commands, Core, Drivers, Formats, Models, Storage Classes: Error, Info, Log, MissingOption, Plugin, Translation, TranslationNotFound, Translator

Constant Summary collapse

ENVIRONMENTS =
[:user, :test, :cucumber]
VERSION =
File.read(File.join(Smartdict.root_dir, "VERSION"))

Instance Method Summary collapse

Instance Method Details

#envObject



83
84
85
# File 'lib/smartdict.rb', line 83

def env
  @env || raise("No env setted for Smartdict")
end

#env=(environment) ⇒ Object



78
79
80
81
# File 'lib/smartdict.rb', line 78

def env=(environment)
  @env = environment.to_sym
  raise "env must be one of #{ENVIRONMENTS.inspect}" unless ENVIRONMENTS.include?(@env)
end

#home_dirObject



74
75
76
# File 'lib/smartdict.rb', line 74

def home_dir
  ENV['HOME']
end

#infoObject



99
100
101
# File 'lib/smartdict.rb', line 99

def info
  Info.instance
end

#init_configObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/smartdict.rb', line 53

def init_config
  default_config_file = File.join(root_dir, 'config', 'default_config.yml')
  configatron.configure_from_hash YAML.load_file(default_config_file)

  config_file = File.join(user_dir, 'configuration.yml')
  if File.exists?(config_file)
    configatron.configure_from_hash YAML.load_file(config_file)
  else
    FileUtils.cp default_config_file, config_file
  end
end

#load_pluginsObject



43
44
45
# File 'lib/smartdict.rb', line 43

def load_plugins
  Core::PluginManager.load_plugins
end

#log_pathObject



87
88
89
# File 'lib/smartdict.rb', line 87

def log_path
  File.join(user_dir, 'smartdict.log')
end

#plugins_dirObject



95
96
97
# File 'lib/smartdict.rb', line 95

def plugins_dir
  ENV['SMARTDICT_PLUGINS_DIR'] or File.join(root_dir, 'plugins')
end

#root_dirObject



91
92
93
# File 'lib/smartdict.rb', line 91

def root_dir
  File.join(File.dirname(__FILE__), '..')
end

#runObject



47
48
49
50
51
# File 'lib/smartdict.rb', line 47

def run
  Dir.mkdir user_dir unless File.exists?(user_dir)
  init_config
  Storage.prepare!
end

#user_dirObject



66
67
68
69
70
71
72
# File 'lib/smartdict.rb', line 66

def user_dir
  dirname = {
    :user     => '.smartdict',
    :test     => '.smartdict_test',
    :cucumber => '.smartdict_test' }[env]
  File.join(home_dir, dirname)
end