Class: Azure::Directory::YamlTokenStore

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/directory/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(yaml_file) ⇒ YamlTokenStore

Returns a new instance of YamlTokenStore.



127
128
129
130
131
# File 'lib/azure/directory/config.rb', line 127

def initialize(yaml_file)
	@yaml_file = yaml_file
	@yaml_data = YAML::load( yaml_file.open )
	@yaml_data = {} unless @yaml_data.is_a?(Hash)
end

Instance Method Details

#load(scope_name) ⇒ Object



139
140
141
# File 'lib/azure/directory/config.rb', line 139

def load( scope_name )
	data = @yaml_data[Rails.env.to_s] and data = data[scope_name.to_s] and data.slice('access_token', 'token_type', 'expires_at')
end

#save(scope_name, token_hash) ⇒ Object



133
134
135
136
137
# File 'lib/azure/directory/config.rb', line 133

def save( scope_name, token_hash )
	data = (@yaml_data[Rails.env.to_s] ||= {})
	data[scope_name.to_s] = token_hash
	File.open(@yaml_file, 'w') { |file| file.write( YAML::dump(@yaml_data) ) }
end