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.



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

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.



12
13
14
# File 'lib/shopify_api/auth/file_session_storage.rb', line 12

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



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

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

#delete_session(id) ⇒ Object



43
44
45
46
47
# File 'lib/shopify_api/auth/file_session_storage.rb', line 43

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

#eql?Object



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

alias_method :eql?, :==

#load_session(id) ⇒ Object



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

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



24
25
26
# File 'lib/shopify_api/auth/file_session_storage.rb', line 24

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