Skip to content

Commit

Permalink
Basic config w/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JBlackN committed Sep 10, 2015
1 parent 0ee7153 commit d8b9ec6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
14 changes: 7 additions & 7 deletions lib/budik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
require 'yaml'
#require 'youtube_addy'

require 'budik/command'
require 'budik/config'
#require 'budik/devices'
#require 'budik/player'
#require 'budik/rng'
#require 'budik/sources'
#require 'budik/version'
require './lib/budik/command'
require './lib/budik/config'
#require './budik/devices.rb'
#require './budik/player.rb'
#require './budik/rng.rb'
#require './budik/sources.rb'
require './lib/budik/version'

module Budik
program :name, 'Budík'
Expand Down
12 changes: 6 additions & 6 deletions lib/budik/command.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module Budik
def command_config(_args, opts)
def self.command_config(_args, opts)
_config = Config.instance.load(opts)
end

def command_run(_args, opts)
def self.command_run(_args, opts)
config.load(opts)
end

def command_set(_args, opts)
def self.command_set(_args, opts)
end

def command_sources(_args, opts)
def self.command_sources(_args, opts)
end

def command_translate(_args, opts)
def self.command_translate(_args, opts)
end

def command_unset(_args, opts)
def self.command_unset(_args, opts)
end
end
15 changes: 13 additions & 2 deletions lib/budik/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class Config
include Singleton

def initialize
R18n.default_places = './lib/budik/config/lang/'

@lang = nil
@options = nil
@sources = nil
Expand All @@ -13,14 +15,23 @@ def initialize
attr_accessor :sources

def edit(opts)
# TODO
end

def load(opts)
#@lang = opts.language ? opts.language : './config/lang.yml'
#@lang = YAML.load_file(@lang)
locale = opts.has_key?(:language) ? opts[:language] : 'en'
options_path = opts.has_key?(:options) ? opts[:options] : './lib/budik/config/options.yml'
sources_path = opts.has_key?(:sources) ? opts[:sources] : './lib/budik/config/sources.yml'

R18n.set(locale)
@lang = R18n.t
@options = YAML.load_file(options_path)
@sources = YAML.load_file(sources_path)

end

def reset
# TODO
end
end
end
8 changes: 3 additions & 5 deletions lib/budik/config/lang/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---
lang: en
strings:
- config:
- example: "This is an example string."
lang: "en" # Do not remove this line.
config:
example: "This is an example string."
34 changes: 34 additions & 0 deletions spec/lib/budik/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'r18n-core'
require 'singleton'
require 'spec_helper'
require 'yaml'

require 'budik/config'

describe Budik::Config, '#load' do
context 'with default values' do
it 'loads configuration files' do
opts = {}
config = Budik::Config.instance
config.load(opts)

expect(config.lang.lang.class).to eq R18n::TranslatedString
expect(config.options).to eq YAML.load_file('./lib/budik/config/options.yml')
expect(config.sources).to eq YAML.load_file('./lib/budik/config/sources.yml')
end
end

context 'with file overrides' do
it 'loads configuration files' do
opts = { language: 'en',
options: './lib/budik/config/options.yml',
sources: './lib/budik/config/sources.yml' }
config = Budik::Config.instance
config.load(opts)

expect(config.lang.lang.class).to eq R18n::TranslatedString
expect(config.options).to eq YAML.load_file('./lib/budik/config/options.yml')
expect(config.sources).to eq YAML.load_file('./lib/budik/config/sources.yml')
end
end
end
4 changes: 0 additions & 4 deletions spec/budik_spec.rb → spec/lib/budik_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
it 'has a version number' do
expect(Budik::VERSION).not_to be nil
end

it 'does something useful' do
expect(false).to eq(true)
end
end

0 comments on commit d8b9ec6

Please sign in to comment.