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 = 100
end

Instance Attribute Details

#localDbPathObject (readonly)

Returns the value of attribute localDbPath.



102
103
104
# File 'lib/pastehub/config.rb', line 102

def localDbPath
  @localDbPath
end

#localSyncPathObject (readonly)

Returns the value of attribute localSyncPath.



102
103
104
# File 'lib/pastehub/config.rb', line 102

def localSyncPath
  @localSyncPath
end

#notifyMessageMaxObject (readonly)

Returns the value of attribute notifyMessageMax.



102
103
104
# File 'lib/pastehub/config.rb', line 102

def notifyMessageMax
  @notifyMessageMax
end

#publicPathObject (readonly)

Returns the value of attribute publicPath.



102
103
104
# File 'lib/pastehub/config.rb', line 102

def publicPath
  @publicPath
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



55
56
57
58
59
60
61
# File 'lib/pastehub/config.rb', line 55

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

#getVerboseObject



67
68
69
# File 'lib/pastehub/config.rb', line 67

def getVerbose( )
  @verbose_flag
end

#loadClientObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/pastehub/config.rb', line 90

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

#reinitializeObject



51
52
53
# File 'lib/pastehub/config.rb', line 51

def reinitialize()
  initialize()
end

#setupClient(hash) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/pastehub/config.rb', line 71

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
  @publicPath       = if hash[ :publicPath ]
                        hash[ :publicPath ]
                      else
                        File.expand_path( sprintf( "%s/Dropbox/Public/", getHomeDirectory() )) + "/"
                      end
end

#setVerbose(verbose_flag) ⇒ Object



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

def setVerbose( verbose_flag )
  @verbose_flag = verbose_flag
end