Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: txus/mayl
base: 0af8e34279
...
head fork: txus/mayl
compare: 553845a9b0
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
7 Rakefile
@@ -14,5 +14,12 @@ Rake::TestTask.new do |t|
t.test_files = FileList['./test/**/*_test.rb']
end
+require 'reek/rake/task'
+Reek::Rake::Task.new do |t|
+ t.fail_on_error = true
+ t.verbose = false
+ t.source_files = 'lib/**/*.rb'
+end
+
task :doc => :yard
task :default => :test
View
1  lib/mayl.rb
@@ -4,6 +4,7 @@
require "mayl/loader"
require "mayl/env"
require "mayl/parser"
+require "mayl/colors"
require "mayl/repl"
# Public: Mayl is an anagram of YAML, and also a console to create, edit and
View
19 lib/mayl/colors.rb
@@ -0,0 +1,19 @@
+module Mayl
+ module Colors
+ def color(name, str)
+ code = case name
+ when :black then "\033[30m"
+ when :red then "\033[31m"
+ when :green then "\033[32m"
+ when :brown then "\033[33m"
+ when :blue then "\033[34m"
+ when :magenta then "\033[35m"
+ when :cyan then "\033[36m"
+ when :gray then "\033[37m"
+ end
+ endcode = "\033[0m"
+
+ [code,str,endcode].join
+ end
+ end
+end
View
12 lib/mayl/commands/cd.rb
@@ -22,9 +22,11 @@ def initialize(env, path)
#
# Returns nil.
def execute
+ namespace = @env.namespace
+
case @path
when ".."
- ns = @env.namespace.split('.')
+ ns = namespace.split('.')
ns.pop
@env.namespace = ns.join('.')
when "."
@@ -32,7 +34,7 @@ def execute
else
check_namespace!
- if @env.namespace.empty?
+ if namespace.empty?
@env.namespace = @path
else
@env.namespace += '.' << @path
@@ -41,7 +43,11 @@ def execute
nil
end
- # Public: Checks that you're not trying to enter a leaf.
+ #######
+ private
+ #######
+
+ # Internal: Checks that you're not trying to enter a leaf.
#
# Raises an ArgumentError if you are.
def check_namespace!
View
6 lib/mayl/commands/edit.rb
@@ -28,11 +28,13 @@ def initialize(env, locale, value)
#
# Returns the key.
def execute
+ key = qualified_key
locale = locales.detect do |locale|
locale.name.to_s == @locale.to_s
end
- locale.set @key, @value
- @key
+
+ locale.set key, @value
+ key
end
#######
View
5 lib/mayl/commands/get.rb
@@ -31,10 +31,11 @@ def initialize(env, key)
def execute
locales.each do |locale|
result = locale.get qualified_key
+ name = locale.to_s
if result.is_a? String
- print " #{locale.to_s}: #{result}\n"
+ print " #{name}: #{result}\n"
else
- print " #{locale.to_s}: (empty)\n"
+ print " #{name}: (empty)\n"
end
end
@key
View
8 lib/mayl/repl.rb
@@ -4,6 +4,7 @@ module Mayl
# Public: The class responsible for reading user input, interpreting it and
# executing associated commands.
class Repl
+ include Colors
attr_reader :parser
# Public: Initializes a new REPL from a given path.
@@ -21,13 +22,12 @@ def initialize(path)
def start
locales = @env.locales.map(&:name)
stty_save = `stty -g`.chomp
- prompt = "> "
- puts "Detected locales: #{locales.join(', ')}"
+ prompt = color(:red, "> ")
+ puts color(:green, "Detected locales: #{locales.join(', ')}")
env = @env
Readline.completion_proc = proc { |s| Commands.autocomplete(s, env) }
Readline.completion_append_character = ''
- # Readline.completer_word_break_characters = 23.chr
begin
while input = Readline.readline(prompt, true)
@@ -35,7 +35,7 @@ def start
value = @parser.parse(input.chomp).execute
@env.last_value = value
@env.commit
- prompt = [@env.namespace, '> '].reject(&:empty?).join ' '
+ prompt = color(:red, [@env.namespace, '> '].reject(&:empty?).join(' '))
rescue => e
print "Error: #{e.message}"
ensure
View
2  lib/mayl/version.rb
@@ -1,4 +1,4 @@
module Mayl
# The version of the Mayl gem.
- VERSION = "0.2.0"
+ VERSION = "0.2.1"
end
View
2  mayl.gemspec
@@ -19,6 +19,8 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'yard-tomdoc'
gem.add_development_dependency 'redcarpet'
+ gem.add_development_dependency 'reek'
+
gem.add_development_dependency 'minitest'
gem.add_development_dependency 'mocha'
end

No commit comments for this range

Something went wrong with that request. Please try again.