Class: RSimpy::ProfileStorageService
- Inherits:
-
Object
- Object
- RSimpy::ProfileStorageService
- Defined in:
- lib/profile_storage_service.rb
Instance Method Summary collapse
- #default_location ⇒ Object
- #get ⇒ Object
-
#initialize(location = nil) ⇒ ProfileStorageService
constructor
A new instance of ProfileStorageService.
- #save(user) ⇒ Object
- #stored? ⇒ Boolean
Constructor Details
#initialize(location = nil) ⇒ ProfileStorageService
Returns a new instance of ProfileStorageService.
3 4 5 |
# File 'lib/profile_storage_service.rb', line 3 def initialize location=nil @location = location || default_location end |
Instance Method Details
#default_location ⇒ Object
7 8 9 |
# File 'lib/profile_storage_service.rb', line 7 def default_location File.(File.join(['~','.rsimpy'])) end |
#get ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/profile_storage_service.rb', line 32 def get file = File.read(@location) data = {} require 'khayyam' login, pass = nil topic = Khayyam::Topic.import file topic.regarding "user" do |items| login = items["login"] pass = items["pass"] end return RSimpy::User.new(login, pass) end |
#save(user) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/profile_storage_service.rb', line 15 def save user require 'khayyam' topic = Khayyam::Topic.new "rsimpy" topic.regarding "user" do |items| login, pass = user.credentials items["login"] = login items["pass"] = pass end output = topic.export file = File.open(@location, 'w+') file.write(output) file.close end |
#stored? ⇒ Boolean
11 12 13 |
# File 'lib/profile_storage_service.rb', line 11 def stored? File.exists? @location end |