class Socialinvestigator::Config::FileConfigStorage

Public Class Methods

new( dir = nil ) click to toggle source
# File lib/socialinvestigator/config.rb, line 16
def initialize( dir = nil )
  @dir = dir || "#{ENV['HOME']}/.socialinvestigator"

  FileUtils.mkdir_p @dir
end

Public Instance Methods

apps_json() click to toggle source
# File lib/socialinvestigator/config.rb, line 30
def apps_json
  read_json( "apps.json" )
end
apps_json=( data ) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# 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 ) click to toggle source
# 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() click to toggle source
# File lib/socialinvestigator/config.rb, line 22
def twitter_config
  read_yaml( "twitter.yml" )
end
twitter_config=(config) click to toggle source
# File lib/socialinvestigator/config.rb, line 26
def twitter_config= config
  save_yaml( "twitter.yml", config )
end