class Twurl::RCFile

Constants

FILE

Attributes

data[R]

Public Class Methods

default_rcfile_structure() click to toggle source
   # File lib/twurl/rcfile.rb
23 def default_rcfile_structure
24   {'profiles' => {}, 'configuration' => {}}
25 end
directory() click to toggle source
  # File lib/twurl/rcfile.rb
5 def directory
6   @@directory ||= File.expand_path('~')
7 end
directory=(dir) click to toggle source
   # File lib/twurl/rcfile.rb
 9 def directory=(dir)
10   @@directory = dir
11 end
file_path() click to toggle source
   # File lib/twurl/rcfile.rb
13 def file_path
14   File.join(directory, FILE)
15 end
load() click to toggle source
   # File lib/twurl/rcfile.rb
17 def load
18   YAML.load_file(file_path)
19 rescue Errno::ENOENT
20   default_rcfile_structure
21 end
new() click to toggle source
   # File lib/twurl/rcfile.rb
29 def initialize
30   @data = self.class.load
31 end

Public Instance Methods

<<(oauth_client) click to toggle source
    # File lib/twurl/rcfile.rb
109 def <<(oauth_client)
110   client_from_file = self[oauth_client.username] || {}
111   client_from_file[oauth_client.consumer_key] = oauth_client.to_hash
112   (profiles[oauth_client.username] ||= {}).update(client_from_file)
113   self.default_profile = oauth_client unless default_profile
114   save
115 end
[](username) click to toggle source
   # File lib/twurl/rcfile.rb
43 def [](username)
44   profiles[username]
45 end
alias(name, path) click to toggle source
   # File lib/twurl/rcfile.rb
68 def alias(name, path)
69   data['aliases'] ||= {}
70   data['aliases'][name] = path
71   save
72 end
alias_from_name(name) click to toggle source
   # File lib/twurl/rcfile.rb
96 def alias_from_name(name)
97   aliases[name]
98 end
alias_from_options(options) click to toggle source
   # File lib/twurl/rcfile.rb
88 def alias_from_options(options)
89   options.subcommands.each do |potential_alias|
90     if path = alias_from_name(potential_alias)
91       break path
92     end
93   end
94 end
aliases() click to toggle source
   # File lib/twurl/rcfile.rb
74 def aliases
75   data['aliases'] ||= {}
76 end
bearer_token(consumer_key, bearer_token) click to toggle source
   # File lib/twurl/rcfile.rb
78 def bearer_token(consumer_key, bearer_token)
79   data['bearer_tokens'] ||= {}
80   data['bearer_tokens'][consumer_key] = bearer_token
81   save
82 end
bearer_tokens() click to toggle source
   # File lib/twurl/rcfile.rb
84 def bearer_tokens
85   data['bearer_tokens']
86 end
configuration() click to toggle source
   # File lib/twurl/rcfile.rb
64 def configuration
65   data['configuration']
66 end
default_profile() click to toggle source
   # File lib/twurl/rcfile.rb
51 def default_profile
52   configuration['default_profile']
53 end
default_profile=(profile) click to toggle source
   # File lib/twurl/rcfile.rb
60 def default_profile=(profile)
61   configuration['default_profile'] = [profile.username, profile.consumer_key]
62 end
default_profile_consumer_key() click to toggle source
   # File lib/twurl/rcfile.rb
55 def default_profile_consumer_key
56   username, consumer_key = configuration['default_profile']
57   consumer_key
58 end
empty?() click to toggle source
   # File lib/twurl/rcfile.rb
33 def empty?
34   data == self.class.default_rcfile_structure
35 end
has_bearer_token_for_consumer_key?(consumer_key) click to toggle source
    # File lib/twurl/rcfile.rb
105 def has_bearer_token_for_consumer_key?(consumer_key)
106   bearer_tokens.nil? ? false : bearer_tokens.to_hash.has_key?(consumer_key)
107 end
has_oauth_profile_for_username_with_consumer_key?(username, consumer_key) click to toggle source
    # File lib/twurl/rcfile.rb
100 def has_oauth_profile_for_username_with_consumer_key?(username, consumer_key)
101   user_profiles = self[username]
102   !user_profiles.nil? && !user_profiles[consumer_key].nil?
103 end
profiles() click to toggle source
   # File lib/twurl/rcfile.rb
47 def profiles
48   data['profiles']
49 end
save() click to toggle source
   # File lib/twurl/rcfile.rb
37 def save
38   File.open(self.class.file_path, File::RDWR|File::CREAT|File::TRUNC, 0600) do |rcfile|
39     rcfile.write data.to_yaml
40   end
41 end