Class: RCFile
Constant Summary collapse
- FILE_NAME =
'.trc'
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #[](username) ⇒ Object
- #[]=(username, profile) ⇒ Object
- #configuration ⇒ Object
- #default_consumer_key ⇒ Object
- #default_consumer_secret ⇒ Object
- #default_profile ⇒ Object
- #default_profile=(profile) ⇒ Object
- #default_secret ⇒ Object
- #default_token ⇒ Object
- #delete ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ RCFile
constructor
A new instance of RCFile.
- #load ⇒ Object
- #profiles ⇒ Object
- #reset ⇒ Object
Constructor Details
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/t/rcfile.rb', line 6 def path @path end |
Instance Method Details
#[](username) ⇒ Object
15 16 17 |
# File 'lib/t/rcfile.rb', line 15 def [](username) profiles[username] end |
#[]=(username, profile) ⇒ Object
19 20 21 22 23 |
# File 'lib/t/rcfile.rb', line 19 def []=(username, profile) profiles[username] ||= {} profiles[username].merge!(profile) write end |
#configuration ⇒ Object
25 26 27 |
# File 'lib/t/rcfile.rb', line 25 def configuration @data['configuration'] end |
#default_consumer_key ⇒ Object
29 30 31 |
# File 'lib/t/rcfile.rb', line 29 def default_consumer_key profiles[default_profile[0]][default_profile[1]]['consumer_key'] if default_profile && profiles[default_profile[0]] && profiles[default_profile[0]][default_profile[1]] end |
#default_consumer_secret ⇒ Object
33 34 35 |
# File 'lib/t/rcfile.rb', line 33 def default_consumer_secret profiles[default_profile[0]][default_profile[1]]['consumer_secret'] if default_profile && profiles[default_profile[0]] && profiles[default_profile[0]][default_profile[1]] end |
#default_profile ⇒ Object
37 38 39 |
# File 'lib/t/rcfile.rb', line 37 def default_profile configuration['default_profile'] end |
#default_profile=(profile) ⇒ Object
41 42 43 44 |
# File 'lib/t/rcfile.rb', line 41 def default_profile=(profile) configuration['default_profile'] = [profile['username'], profile['consumer_key']] write end |
#default_secret ⇒ Object
46 47 48 |
# File 'lib/t/rcfile.rb', line 46 def default_secret profiles[default_profile[0]][default_profile[1]]['secret'] if default_profile && profiles[default_profile[0]] && profiles[default_profile[0]][default_profile[1]] end |
#default_token ⇒ Object
50 51 52 |
# File 'lib/t/rcfile.rb', line 50 def default_token profiles[default_profile[0]][default_profile[1]]['token'] if default_profile && profiles[default_profile[0]] && profiles[default_profile[0]][default_profile[1]] end |
#delete ⇒ Object
54 55 56 |
# File 'lib/t/rcfile.rb', line 54 def delete File.delete(@path) if File.exist?(@path) end |
#empty? ⇒ Boolean
58 59 60 |
# File 'lib/t/rcfile.rb', line 58 def empty? @data == default_structure end |
#load ⇒ Object
62 63 64 65 66 |
# File 'lib/t/rcfile.rb', line 62 def load YAML.load_file(@path) rescue Errno::ENOENT default_structure end |
#profiles ⇒ Object
74 75 76 |
# File 'lib/t/rcfile.rb', line 74 def profiles @data['profiles'] end |
#reset ⇒ Object
78 79 80 |
# File 'lib/t/rcfile.rb', line 78 def reset self.send(:initialize) end |