Class: Seekrit::Interactor
- Inherits:
-
Object
- Object
- Seekrit::Interactor
- Defined in:
- lib/seekrit/interactor.rb
Constant Summary collapse
- EDITOR =
ENV['EDITOR'] || 'vi'
- RANDOM_SOURCE =
'/dev/urandom'
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #delete(names) ⇒ Object
- #edit(names) ⇒ Object
- #export(filename) ⇒ Object
- #import(filename) ⇒ Object
-
#initialize(store) ⇒ Interactor
constructor
A new instance of Interactor.
- #list(patterns) ⇒ Object
- #rename(old_name, new_name) ⇒ Object
- #show(names) ⇒ Object
Constructor Details
#initialize(store) ⇒ Interactor
Returns a new instance of Interactor.
10 11 12 |
# File 'lib/seekrit/interactor.rb', line 10 def initialize(store) @store = store end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
8 9 10 |
# File 'lib/seekrit/interactor.rb', line 8 def store @store end |
Instance Method Details
#delete(names) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/seekrit/interactor.rb', line 30 def delete(names) names.each do |name| store.delete(name) end store.save end |
#edit(names) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/seekrit/interactor.rb', line 18 def edit(names) names.each do |name| comment = "\# #{name}\n" data = comment + (store[name] || '') external_editor(data) do |data| data.sub!(/\A#{Regexp.escape(comment)}/, '') store[name] = data store.save end end end |
#export(filename) ⇒ Object
53 54 55 56 57 |
# File 'lib/seekrit/interactor.rb', line 53 def export(filename) File.open(filename, 'w') do |io| store.export io end end |
#import(filename) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/seekrit/interactor.rb', line 59 def import(filename) File.open(filename, 'r') do |io| store.import io store.save end end |
#list(patterns) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/seekrit/interactor.rb', line 37 def list(patterns) if patterns.empty? regexp = /.*/ else regexp = /#{ patterns.map{ |p| Regexp.escape(p) }.join('|') }/ end store.keys.sort_by{ |a| a.upcase }.each do |name| puts name if name =~ regexp end end |
#rename(old_name, new_name) ⇒ Object
48 49 50 51 |
# File 'lib/seekrit/interactor.rb', line 48 def rename(old_name, new_name) store.rename(old_name, new_name) store.save end |
#show(names) ⇒ Object
14 15 16 |
# File 'lib/seekrit/interactor.rb', line 14 def show(names) puts *names.map{ |n| [n, store[n] || "(None)", ""].compact }.flatten end |