Class: ShopifyAPI::Auth::FileSessionStorage

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Includes:
SessionStorage
Defined in:
lib/shopify_api/auth/file_session_storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: "/tmp/shopify_api_sessions") ⇒ FileSessionStorage

Returns a new instance of FileSessionStorage.



17
18
19
20
# File 'lib/shopify_api/auth/file_session_storage.rb', line 17

def initialize(path: "/tmp/shopify_api_sessions")
  @path = path
  FileUtils.mkdir_p(path) unless Dir.exist?(path)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



14
15
16
# File 'lib/shopify_api/auth/file_session_storage.rb', line 14

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/shopify_api/auth/file_session_storage.rb', line 53

def ==(other)
  if other
    @path == other.path
  else
    false
  end
end

#delete_session(id) ⇒ Object



45
46
47
48
49
# File 'lib/shopify_api/auth/file_session_storage.rb', line 45

def delete_session(id)
  session_path = session_file_path(id)
  File.delete(session_path) if File.exist?(session_path)
  true
end

#eql?Object



51
# File 'lib/shopify_api/auth/file_session_storage.rb', line 51

alias_method :eql?, :==

#load_session(id) ⇒ Object



34
35
36
37
38
39
# File 'lib/shopify_api/auth/file_session_storage.rb', line 34

def load_session(id)
  session_path = session_file_path(id)
  if File.exist?(session_path)
    ShopifyAPI::Auth::Session.deserialize(File.read(session_path))
  end
end

#store_session(session) ⇒ Object



26
27
28
# File 'lib/shopify_api/auth/file_session_storage.rb', line 26

def store_session(session)
  File.write(session_file_path(session.id), session.serialize) > 0
end