Class: GoogleDirectory::YamlTokenStore
- Inherits:
-
Object
- Object
- GoogleDirectory::YamlTokenStore
- Defined in:
- lib/google-directory/config.rb
Instance Method Summary collapse
-
#initialize(yaml_file) ⇒ YamlTokenStore
constructor
A new instance of YamlTokenStore.
- #load(scope_name) ⇒ Object
- #save(scope_name, token_hash) ⇒ Object
Constructor Details
#initialize(yaml_file) ⇒ YamlTokenStore
Returns a new instance of YamlTokenStore.
122 123 124 125 126 127 |
# File 'lib/google-directory/config.rb', line 122 def initialize(yaml_file) @yaml_file = yaml_file @yaml_data = YAML::load( yaml_file.open ) @yaml_data = {} unless @yaml_data.is_a?(Hash) # @yaml_data[Rails.env.to_s] ||= {} end |
Instance Method Details
#load(scope_name) ⇒ Object
135 136 137 |
# File 'lib/google-directory/config.rb', line 135 def load( scope_name ) data = @yaml_data[Rails.env.to_s] and data = data[scope_name.to_s] and data.slice('token_type', 'issued_at', 'access_token', 'expires_in') end |
#save(scope_name, token_hash) ⇒ Object
129 130 131 132 133 |
# File 'lib/google-directory/config.rb', line 129 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 |