-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josep M. Bach
committed
Apr 16, 2012
1 parent
483d946
commit a8369f1
Showing
6 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Mayl | ||
# Public: The Commands module is a namespace for all the commands that Mayl | ||
# uses. | ||
module Commands | ||
end | ||
end | ||
|
||
require 'mayl/commands/set' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Mayl | ||
module Commands | ||
# Public: The Set command accepts a key and asks the user to type in the | ||
# translations for that key in each of the locales. | ||
# | ||
# Example | ||
# | ||
# command = Set.new(env, 'activerecord.models.post') | ||
# command.execute | ||
# ca: <type something> | ||
# en: <type something> | ||
# # Now locales have those values set. | ||
# | ||
class Set | ||
attr_reader :key | ||
|
||
# Public: Initializes a new Set command. | ||
# | ||
# env - the global environment | ||
# key - the String key to be set | ||
def initialize(env, key) | ||
@env = env | ||
@key = key | ||
end | ||
|
||
# Public: Executes the command, iterating over each locale, asking the | ||
# user for a value, and setting it. | ||
# | ||
# Returns nothing. | ||
def execute | ||
locales.each do |locale| | ||
print " #{locale}: " | ||
locale.set qualified_key, gets.chomp | ||
end | ||
end | ||
|
||
####### | ||
private | ||
####### | ||
|
||
# Public: Returns an Array with the locales of the environment. | ||
def locales | ||
@env.locales | ||
end | ||
|
||
# Public: Returns the given String key according to the qualified | ||
# namespace we are in. | ||
def qualified_key | ||
[@env.namespace.to_s, @key].join('.') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'test_helper' | ||
|
||
module Mayl | ||
module Commands | ||
describe Set do | ||
before do | ||
@locales = [stub(to_s: 'ca'), stub(to_s: 'en')] | ||
@env = stub locales: @locales, namespace: 'activerecord' | ||
@command = Set.new @env, 'models.post' | ||
end | ||
|
||
it 'lets the user enter a value for the key in each of the locales' do | ||
@command.expects(:gets).twice.returns('Article', 'Post') # User interaction | ||
|
||
@locales.first.expects(:set).with('activerecord.models.post', 'Article') | ||
@locales.last.expects(:set).with('activerecord.models.post', 'Post') | ||
|
||
@command.execute | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
gem 'minitest' | ||
require 'minitest/spec' | ||
require 'minitest/autorun' | ||
require 'mocha' | ||
require 'mayl' |