Class: RSimpy::ProfileStorageService

Inherits:
Object
  • Object
show all
Defined in:
lib/profile_storage_service.rb

Instance Method Summary collapse

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_locationObject



7
8
9
# File 'lib/profile_storage_service.rb', line 7

def default_location
  File.expand_path(File.join(['~','.rsimpy']))
end

#getObject



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'
  , pass = nil

  topic = Khayyam::Topic.import file
  topic.regarding "user" do |items|
     = items["login"]
    pass = items["pass"]
  end

  return RSimpy::User.new(, 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|
    , pass = user.credentials
    items["login"] = 
    items["pass"] = pass
  end

  output = topic.export

  file = File.open(@location, 'w+')
  file.write(output)
  file.close
end

#stored?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/profile_storage_service.rb', line 11

def stored?
  File.exists? @location
end