Skip to content

Commit

Permalink
Add constructor to FileParamStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Jul 18, 2018
1 parent 5535356 commit 76fd80e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/fabricio/authorization/file_param_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ module Fabricio
module Authorization
# Stores default params as organization, app, etc.
class FileParamStorage < AbstractParamStorage
def initialize(path = PARAM_FILE_PATH)
@path = path
end

# Returns all stored variable
#
# @return [Hash]
def obtain
return nil unless File.exist?(PARAM_FILE_PATH)
params = YAML.load_file(PARAM_FILE_PATH)
return nil unless File.exist?(@path)
params = YAML.load_file(@path)
return {} unless params
return params
end
Expand All @@ -29,7 +32,7 @@ def store(hash)

# Resets current state and deletes all saved params
def reset
FileUtils.remove_file(PARAM_FILE_PATH)
FileUtils.remove_file(@path)
end

def organization_id
Expand Down Expand Up @@ -58,7 +61,7 @@ def store_app_id(app_id)

def save_to_file(hash)
FileUtils.mkdir_p(FABRICIO_DIRECTORY_PATH)
File.open(PARAM_FILE_PATH,'w') do |f|
File.open(@path, 'w') do |f|
f.write hash.to_yaml
end
end
Expand Down

0 comments on commit 76fd80e

Please sign in to comment.