arcanus 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arcanus/chest.rb +75 -1
- data/lib/arcanus/command/help.rb +1 -1
- data/lib/arcanus/command/setup.rb +6 -0
- data/lib/arcanus/configuration.rb +3 -1
- data/lib/arcanus/constants.rb +8 -6
- data/lib/arcanus/ui.rb +4 -4
- data/lib/arcanus/version.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66036810d6ca7fa05522b32afeb91c36dfe96f4a
|
4
|
+
data.tar.gz: b38269a7f63c805c89c3da2824bbe81f773dac86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a778447c3785bf38d80a6473edbe60833e665a990d9e1df5aa81727e49d73bcbed5bbe1fc227126c3fba0442fa64fa5e7700843f53ec2078a4ef55c559f7a538
|
7
|
+
data.tar.gz: 6de23a00c31b5b4bf63f163204f8152b746309f13db35783e72af7972624102b5ce465e67f6934b56733609a8cbcba1cba1856be6c0f0db9ecf8be1147b7e657
|
data/lib/arcanus/chest.rb
CHANGED
@@ -34,6 +34,24 @@ module Arcanus
|
|
34
34
|
@hash
|
35
35
|
end
|
36
36
|
|
37
|
+
# Provides access to chest items using regular method calls instead of hash
|
38
|
+
# accesses.
|
39
|
+
def method_missing(method_sym, *)
|
40
|
+
method_name = method_sym.to_s
|
41
|
+
if @hash.key?(method_name)
|
42
|
+
value = @hash[method_name]
|
43
|
+
if value.is_a?(Hash)
|
44
|
+
Item.new(value, [method_name])
|
45
|
+
else
|
46
|
+
value
|
47
|
+
end
|
48
|
+
else
|
49
|
+
raise KeyError,
|
50
|
+
"Key '#{method_name}' does not exist in this Arcanus chest",
|
51
|
+
caller
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
37
55
|
# Set value for the specified key path.
|
38
56
|
#
|
39
57
|
# @param key_path [String]
|
@@ -71,7 +89,10 @@ module Arcanus
|
|
71
89
|
modified_hash =
|
72
90
|
process_hash_changes(@original_encrypted_hash, @original_decrypted_hash, @hash)
|
73
91
|
|
74
|
-
File.open(@chest_file_path, 'w')
|
92
|
+
File.open(@chest_file_path, 'w') do |f|
|
93
|
+
f.puts('# Do not edit this file directly! Run `arcanus edit`')
|
94
|
+
f.write(modified_hash.to_yaml)
|
95
|
+
end
|
75
96
|
end
|
76
97
|
|
77
98
|
private
|
@@ -160,5 +181,58 @@ module Arcanus
|
|
160
181
|
|
161
182
|
Marshal.load(dumped_value)
|
162
183
|
end
|
184
|
+
|
185
|
+
# Helper class for returning contents nested hashes, exposing helpers to
|
186
|
+
# access them via method calls.
|
187
|
+
class Item
|
188
|
+
def initialize(hash, prefix = [])
|
189
|
+
@hash = hash
|
190
|
+
@prefix = prefix
|
191
|
+
end
|
192
|
+
|
193
|
+
def method_missing(method_sym, *)
|
194
|
+
method_name = method_sym.to_s
|
195
|
+
if @hash.key?(method_name)
|
196
|
+
value = @hash[method_name]
|
197
|
+
if value.is_a?(Hash)
|
198
|
+
Item.new(value, @prefix + [method_name])
|
199
|
+
else
|
200
|
+
value
|
201
|
+
end
|
202
|
+
else
|
203
|
+
key_name = "#{@prefix.join('.')}.#{method_name}"
|
204
|
+
raise KeyError,
|
205
|
+
"Key '#{key_name}' does not exist in this Arcanus chest",
|
206
|
+
caller
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# Access the item as if it were a hash.
|
211
|
+
#
|
212
|
+
# @param key [String]
|
213
|
+
# @return [Object]
|
214
|
+
def [](key)
|
215
|
+
@hash[key]
|
216
|
+
end
|
217
|
+
|
218
|
+
# Fetch key from the chest as if it were a hash.
|
219
|
+
def fetch(*args)
|
220
|
+
@hash.fetch(*args)
|
221
|
+
end
|
222
|
+
|
223
|
+
def to_s
|
224
|
+
@hash.to_s
|
225
|
+
end
|
226
|
+
|
227
|
+
def inspect
|
228
|
+
@hash.inspect
|
229
|
+
end
|
230
|
+
|
231
|
+
# Implicit conversion to array. Needs to be defined so we can `puts` this
|
232
|
+
# value.
|
233
|
+
def to_ary
|
234
|
+
[@hash]
|
235
|
+
end
|
236
|
+
end
|
163
237
|
end
|
164
238
|
end
|
data/lib/arcanus/command/help.rb
CHANGED
@@ -24,7 +24,7 @@ module Arcanus::Command
|
|
24
24
|
def command_classes
|
25
25
|
command_files =
|
26
26
|
Dir[File.join(File.dirname(__FILE__), '*.rb')]
|
27
|
-
|
27
|
+
.select { |path| File.basename(path, '.rb') != 'base' }
|
28
28
|
|
29
29
|
command_files.map do |file|
|
30
30
|
require file
|
@@ -94,7 +94,13 @@ module Arcanus::Command
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def create_chest
|
97
|
+
# Create a dummy file to start so that we can initialize an empty chest,
|
98
|
+
# but then use that chest's #save implementation to save the file
|
97
99
|
File.open(repo.chest_file_path, 'w') { |f| f.write({}.to_yaml) }
|
100
|
+
|
101
|
+
chest = Arcanus::Chest.new(key_file_path: repo.unlocked_key_path,
|
102
|
+
chest_file_path: repo.chest_file_path)
|
103
|
+
chest.save
|
98
104
|
end
|
99
105
|
|
100
106
|
def create_gitignore
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require 'yaml'
|
3
5
|
|
@@ -8,7 +10,7 @@ module Arcanus
|
|
8
10
|
# this logic can be shared amongst the various components of the system.
|
9
11
|
class Configuration
|
10
12
|
# Name of the configuration file.
|
11
|
-
FILE_NAME = 'config.yaml'
|
13
|
+
FILE_NAME = 'config.yaml'.freeze
|
12
14
|
|
13
15
|
class << self
|
14
16
|
# Loads appropriate configuration file given the current working
|
data/lib/arcanus/constants.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Global application constants.
|
2
4
|
module Arcanus
|
3
|
-
EXECUTABLE_NAME = 'arcanus'
|
5
|
+
EXECUTABLE_NAME = 'arcanus'.freeze
|
4
6
|
|
5
|
-
CHEST_FILE_PATH = File.join('.arcanus', 'chest.yaml')
|
6
|
-
LOCKED_KEY_PATH = File.join('.arcanus', 'protected.key')
|
7
|
-
UNLOCKED_KEY_PATH = File.join('.arcanus', 'unprotected.key')
|
7
|
+
CHEST_FILE_PATH = File.join('.arcanus', 'chest.yaml').freeze
|
8
|
+
LOCKED_KEY_PATH = File.join('.arcanus', 'protected.key').freeze
|
9
|
+
UNLOCKED_KEY_PATH = File.join('.arcanus', 'unprotected.key').freeze
|
8
10
|
|
9
|
-
REPO_URL = 'https://github.com/sds/arcanus'
|
10
|
-
BUG_REPORT_URL = "#{REPO_URL}/issues"
|
11
|
+
REPO_URL = 'https://github.com/sds/arcanus'.freeze
|
12
|
+
BUG_REPORT_URL = "#{REPO_URL}/issues".freeze
|
11
13
|
end
|
data/lib/arcanus/ui.rb
CHANGED
@@ -104,7 +104,7 @@ module Arcanus
|
|
104
104
|
end
|
105
105
|
|
106
106
|
# Execute a command with a spinner animation until it completes.
|
107
|
-
def spinner(*args
|
107
|
+
def spinner(*args)
|
108
108
|
spinner = TTY::Spinner.new(*args)
|
109
109
|
spinner_thread = Thread.new do
|
110
110
|
loop do
|
@@ -113,7 +113,7 @@ module Arcanus
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
|
116
|
+
yield
|
117
117
|
ensure
|
118
118
|
spinner_thread.kill
|
119
119
|
newline # Ensure next line of ouptut on separate line from spinner
|
@@ -123,9 +123,9 @@ module Arcanus
|
|
123
123
|
#
|
124
124
|
# Customize the table by passing a block and operating on the table object
|
125
125
|
# passed to that block to add rows and customize its appearance.
|
126
|
-
def table(options = {}
|
126
|
+
def table(options = {})
|
127
127
|
t = TTY::Table.new(options)
|
128
|
-
|
128
|
+
yield t
|
129
129
|
print(t.render(:unicode, options))
|
130
130
|
end
|
131
131
|
end
|
data/lib/arcanus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arcanus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|