Class: Dscli::Storage

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

Instance Method Summary collapse

Constructor Details

#initializeStorage

Returns a new instance of Storage.



6
7
8
9
10
11
12
13
# File 'lib/dscli/storage.rb', line 6

def initialize
  if !File.exist?(File.expand_path('~') + '/.datasiftcli')
    @configfile = File.new(File.expand_path('~') + '/.datasiftcli', 'w')
    @configfile.close
  else
    @configfile = File.expand_path('~') + '/.datasiftcli'
  end
end

Instance Method Details

#get_authObject



24
25
26
# File 'lib/dscli/storage.rb', line 24

def get_auth
  config = YAML.load(File.read(@configfile))
end

#set_auth(auth) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/dscli/storage.rb', line 15

def set_auth(auth)
  config = File.read(@configfile)
  if config == ""
    File.open(@configfile, "w") { |f|
      f.write(Yajl::Encoder.encode(auth) + "\n")
    }
  end
end