Class: Socialinvestigator::Config::FileConfigStorage
- Inherits:
-
AbstractConfigStorage
- Object
- AbstractConfigStorage
- Socialinvestigator::Config::FileConfigStorage
- Defined in:
- lib/socialinvestigator/config.rb
Instance Method Summary collapse
- #apps_json ⇒ Object
- #apps_json=(data) ⇒ Object
-
#initialize(dir = nil) ⇒ FileConfigStorage
constructor
A new instance of FileConfigStorage.
- #read_json(name) ⇒ Object
- #read_yaml(name) ⇒ Object
- #save_yaml(name, obj) ⇒ Object
- #twitter_config ⇒ Object
- #twitter_config=(config) ⇒ Object
Constructor Details
#initialize(dir = nil) ⇒ FileConfigStorage
Returns a new instance of FileConfigStorage.
16 17 18 19 20 |
# File 'lib/socialinvestigator/config.rb', line 16 def initialize( dir = nil ) @dir = dir || "#{ENV['HOME']}/.socialinvestigator" FileUtils.mkdir_p @dir end |
Instance Method Details
#apps_json ⇒ Object
30 31 32 |
# File 'lib/socialinvestigator/config.rb', line 30 def apps_json read_json( "apps.json" ) end |
#apps_json=(data) ⇒ Object
34 35 36 37 38 |
# File 'lib/socialinvestigator/config.rb', line 34 def apps_json=( data ) File.open( "#{@dir}/apps.json", "w" ) do |out| out << data end end |
#read_json(name) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/socialinvestigator/config.rb', line 56 def read_json( name ) file = "#{@dir}/#{name}" if File.exists? file return JSON.parse( File.read( file ) ) end nil end |
#read_yaml(name) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/socialinvestigator/config.rb', line 40 def read_yaml( name ) file = "#{@dir}/#{name}" if File.exists? file return YAML::load_file( file ) end nil end |
#save_yaml(name, obj) ⇒ Object
50 51 52 53 54 |
# File 'lib/socialinvestigator/config.rb', line 50 def save_yaml( name, obj ) File.open( "#{@dir}/#{name}", "w" ) do |out| out.write obj.to_yaml end end |
#twitter_config ⇒ Object
22 23 24 |
# File 'lib/socialinvestigator/config.rb', line 22 def twitter_config read_yaml( "twitter.yml" ) end |
#twitter_config=(config) ⇒ Object
26 27 28 |
# File 'lib/socialinvestigator/config.rb', line 26 def twitter_config= config save_yaml( "twitter.yml", config ) end |