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
33 34 35 36 37 38 |
# File 'lib/seekrit/interactor.rb', line 33 def delete(names) names.each do |name| store.delete(name) end store.save end |
#edit(names) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/seekrit/interactor.rb', line 21 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
56 57 58 59 60 |
# File 'lib/seekrit/interactor.rb', line 56 def export(filename) File.open(filename, 'w') do |io| store.export io end end |
#import(filename) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/seekrit/interactor.rb', line 62 def import(filename) File.open(filename, 'r') do |io| store.import io store.save end end |
#list(patterns) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/seekrit/interactor.rb', line 40 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
51 52 53 54 |
# File 'lib/seekrit/interactor.rb', line 51 def rename(old_name, new_name) store.rename(old_name, new_name) store.save end |
#show(names) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/seekrit/interactor.rb', line 14 def show(names) names.each do |name| data = store[name] puts(name, data, '') end end |