Commit 7cd4063
Changed files (3)
lib
spec
lib/in.rb
@@ -1,5 +1,54 @@
require "in/version"
+require "pstore"
module In
- # Your code goes here...
+ class Console
+ def initialize(filename = "secrets")
+ @storage = PStore.new(File.join(Dir.home, ".#{filename}.pstore"))
+ end
+
+ def run(command)
+ arguments = command.split(' ')
+ command_name = arguments.first
+ command_for(command_name).run(arguments - [command_name])
+ end
+
+ private
+
+ def command_for(command_name)
+ if command_name == "add"
+ AddCommand.new(@storage)
+ else
+ ShowCommand.new(@storage)
+ end
+ end
+ end
+
+ class AddCommand
+ def initialize(storage)
+ @storage = storage
+ end
+
+ def run(arguments)
+ name = arguments.first
+ secret = arguments.last
+ @storage.transaction do
+ @storage[name] = secret
+ end
+ "Added... "
+ end
+ end
+
+ class ShowCommand
+ def initialize(storage)
+ @storage = storage
+ end
+
+ def run(arguments)
+ name = arguments.last
+ @storage.transaction(true) do
+ @storage[name]
+ end
+ end
+ end
end
spec/lib/console_spec.rb
@@ -0,0 +1,11 @@
+module In
+ describe Console do
+ subject { Console.new('testing') }
+ let(:secret) { SecureRandom.uuid }
+
+ it "saves a new secret" do
+ subject.run("add development #{secret}")
+ expect(subject.run("show development")).to eql(secret)
+ end
+ end
+end
spec/spec_helper.rb
@@ -14,6 +14,7 @@
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+require 'in'
RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.