Class: PasteHub::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/pastehub/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



45
46
47
48
49
# File 'lib/pastehub/config.rb', line 45

def initialize( )
  self.setupClient( {} )
  @verbose_flag = false
  @notifyMessageMax = 80
end

Instance Attribute Details

#localDbPathObject (readonly)

Returns the value of attribute localDbPath.



93
94
95
# File 'lib/pastehub/config.rb', line 93

def localDbPath
  @localDbPath
end

#localSyncPathObject (readonly)

Returns the value of attribute localSyncPath.



93
94
95
# File 'lib/pastehub/config.rb', line 93

def localSyncPath
  @localSyncPath
end

#notifyMessageMaxObject (readonly)

Returns the value of attribute notifyMessageMax.



93
94
95
# File 'lib/pastehub/config.rb', line 93

def notifyMessageMax
  @notifyMessageMax
end

Class Method Details

.instanceObject



41
42
43
# File 'lib/pastehub/config.rb', line 41

def self.instance
  @@instance ||= new
end

Instance Method Details

#getHomeDirectoryObject



51
52
53
54
55
56
57
# File 'lib/pastehub/config.rb', line 51

def getHomeDirectory( )
  if ENV[ 'HOME' ]
    return ENV[ 'HOME' ]
  else
    return "~/"
  end
end

#getVerboseObject



63
64
65
# File 'lib/pastehub/config.rb', line 63

def getVerbose( )
  @verbose_flag
end

#loadClientObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/pastehub/config.rb', line 81

def loadClient()
  name = File.expand_path( "~/.pastehub.conf" )
  if File.exist?( name )
    open( name ) { |f|
      json = JSON.parse( f.read )
      self.setupClient( { :localDbPath        => json[ 'localDbPath' ],
                          :localSyncPath      => json[ 'localSyncPath' ],
                        } )
    }
  end
end

#setupClient(hash) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pastehub/config.rb', line 67

def setupClient( hash )

  @localDbPath         = if hash[ :localDbPath ]
                           hash[ :localDbPath ]
                         else
                           File.expand_path( sprintf( "%s/.pastehub/", getHomeDirectory() ))  + "/"
                         end
  @localSyncPath       = if hash[ :localSyncPath ]
                           hash[ :localSyncPath ]
                         else
                           File.expand_path( sprintf( "%s/Dropbox/pastehub/", getHomeDirectory() )) + "/"
                         end
end

#setVerbose(verbose_flag) ⇒ Object



59
60
61
# File 'lib/pastehub/config.rb', line 59

def setVerbose( verbose_flag )
  @verbose_flag = verbose_flag
end