Permalink
Browse files

fix some loading issues

  • Loading branch information...
1 parent a82294e commit e82f732250b26c7ea53669d5a58cd8b850e4b0ea @txus committed Apr 17, 2012
Showing with 10 additions and 6 deletions.
  1. +1 −1 bin/mayl
  2. +5 −1 lib/mayl/loader.rb
  3. +2 −2 lib/mayl/repl.rb
  4. +2 −2 test/mayl/repl_test.rb
View
2 bin/mayl
@@ -2,4 +2,4 @@
$: << 'lib'
require 'mayl'
-Mayl::Repl.new(ARGV[1]).start
+Mayl::Repl.new(ARGV[0]).start
View
6 lib/mayl/loader.rb
@@ -17,9 +17,13 @@ module Loader
#
# Returns an Array of Locale objects.
def self.load(path)
- Dir[File.expand_path(path) << "/*.yml"].map { |filename|
+ locales = Dir[File.expand_path(path) << "/*.yml"].map { |filename|
Locale.new filename, YAML.load(File.read(filename))
}
+
+ abort "Error: No locales found under ./#{path}" if locales.empty?
+
+ locales
end
end
end
View
4 lib/mayl/repl.rb
@@ -8,7 +8,7 @@ class Repl
#
# path - The path to get the locales from (defaults to 'config/locales').
def initialize(path)
- path ||= 'config/locales'
+ path ||= 'config/locales'
@env = Env.new(path)
@parser = Parser.new(@env)
end
@@ -20,7 +20,7 @@ def start
locales = @env.locales.map(&:name)
prompt = "> "
puts "Detected locales: #{locales.join(', ')}"
- while (print prompt; input = gets)
+ while (print prompt; input = $stdin.gets)
begin
value = @parser.parse(input.chomp).execute
@env.last_value = value
View
4 test/mayl/repl_test.rb
@@ -3,7 +3,7 @@
module Mayl
describe Repl do
before do
- @repl = Mayl::Repl.new('some/path.yml')
+ @repl = Mayl::Repl.new('test/support')
end
it 'parses and executes commands' do
@@ -12,7 +12,7 @@ module Mayl
@baz = stub
@baz.expects(:execute)
- @repl.expects(:gets).times(3).returns("foo bar\n", "baz lol\n", nil)
+ $stdin.expects(:gets).times(3).returns("foo bar\n", "baz lol\n", nil)
@repl.parser.expects(:parse).with('foo bar').returns @foo
@repl.parser.expects(:parse).with('baz lol').returns @baz

0 comments on commit e82f732

Please sign in to comment.