Permalink
Browse files

some stuff working

  • Loading branch information...
1 parent c633f39 commit 8f3cdd53439fc4e73de6ec0b3093b32d35cd84bf @txus committed Apr 17, 2012
Showing with 31 additions and 10 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 bin/mayl
  3. +7 −2 lib/mayl/commands/get.rb
  4. +1 −1 lib/mayl/commands/set.rb
  5. +5 −0 lib/mayl/env.rb
  6. +9 −4 lib/mayl/locale.rb
  7. +2 −1 lib/mayl/repl.rb
  8. +4 −0 test/mayl/locale_test.rb
  9. +1 −1 test/mayl/repl_test.rb
View
@@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
+config/locales
View
@@ -2,4 +2,4 @@
$: << 'lib'
require 'mayl'
-Mayl::Repl.new.start ARGV[1]
+Mayl::Repl.new(ARGV[1]).start
View
@@ -30,7 +30,12 @@ def initialize(env, key)
# Returns nothing.
def execute
locales.each do |locale|
- print " #{locale}: #{locale.get qualified_key}\n"
+ result = locale.get qualified_key
+ if result.is_a? String
+ print " #{locale.to_s}: #{result}\n"
+ else
+ print " #{locale.to_s}: (empty)\n"
+ end
end
end
@@ -46,7 +51,7 @@ def locales
# Public: Returns the given String key according to the qualified
# namespace we are in.
def qualified_key
- [@env.namespace.to_s, @key].join('.')
+ [@env.namespace.to_s, @key].reject(&:empty?).compact.join('.')
end
end
end
View
@@ -46,7 +46,7 @@ def locales
# Public: Returns the given String key according to the qualified
# namespace we are in.
def qualified_key
- [@env.namespace.to_s, @key].join('.')
+ [@env.namespace.to_s, @key].reject(&:empty?).compact.join('.')
end
end
end
View
@@ -13,5 +13,10 @@ def initialize(path)
def commit
@locales.each(&:commit)
end
+
+ # Public: The current namespace. For now it's just an empty slime.
+ def namespace
+ ""
+ end
end
end
View
@@ -35,13 +35,13 @@ def set(key, value)
qualifier = ary[0..-2]
name = ary.last
- path = qualifier.inject(@data) do |acc, name|
- acc[name] ||= {}
+ _data = @data
+ qualifier.each do |path|
+ _data = _data[path]
end
+ _data[name] = value
@dirty = true
-
- path[name] = value
end
# Public: Gets the value for a given key.
@@ -65,5 +65,10 @@ def commit
f.write YAML.dump({ @name.to_s => @data })
end
end
+
+ # Public: Returns a String representation of the Locale.
+ def to_s
+ @name
+ end
end
end
View
@@ -7,7 +7,8 @@ class Repl
# Public: Initializes a new REPL from a given path.
#
# path - The path to get the locales from (defaults to 'config/locales').
- def initialize(path='config/locales')
+ def initialize(path)
+ path ||= 'config/locales'
@env = Env.new(path)
@parser = Parser.new(@env)
end
View
@@ -7,6 +7,10 @@ module Mayl
@locale = Locale.new('some/ca.yml', hash)
end
+ it 'gets a key' do
+ @locale.get('activerecord.models.post').must_equal 'Article'
+ end
+
it 'sets and retrieves a given key' do
@locale.set('activerecord.models.comment', 'Comentari')
@locale.get('activerecord.models.comment').must_equal 'Comentari'
View
@@ -3,7 +3,7 @@
module Mayl
describe Repl do
before do
- @repl = Mayl::Repl.new
+ @repl = Mayl::Repl.new('some/path.yml')
end
it 'parses and executes commands' do

0 comments on commit 8f3cdd5

Please sign in to comment.