Class: PasteHub::Config
- Inherits:
-
Object
- Object
- PasteHub::Config
- Includes:
- Singleton
- Defined in:
- lib/pastehub/config.rb
Instance Attribute Summary collapse
-
#localDbPath ⇒ Object
readonly
Returns the value of attribute localDbPath.
-
#localSyncPath ⇒ Object
readonly
Returns the value of attribute localSyncPath.
-
#notifyMessageMax ⇒ Object
readonly
Returns the value of attribute notifyMessageMax.
Class Method Summary collapse
Instance Method Summary collapse
- #getHomeDirectory ⇒ Object
- #getVerbose ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #loadClient ⇒ Object
- #setupClient(hash) ⇒ Object
- #setVerbose(verbose_flag) ⇒ Object
Constructor Details
#initialize ⇒ Config
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
#localDbPath ⇒ Object (readonly)
Returns the value of attribute localDbPath.
93 94 95 |
# File 'lib/pastehub/config.rb', line 93 def localDbPath @localDbPath end |
#localSyncPath ⇒ Object (readonly)
Returns the value of attribute localSyncPath.
93 94 95 |
# File 'lib/pastehub/config.rb', line 93 def localSyncPath @localSyncPath end |
#notifyMessageMax ⇒ Object (readonly)
Returns the value of attribute notifyMessageMax.
93 94 95 |
# File 'lib/pastehub/config.rb', line 93 def notifyMessageMax @notifyMessageMax end |
Class Method Details
.instance ⇒ Object
41 42 43 |
# File 'lib/pastehub/config.rb', line 41 def self.instance @@instance ||= new end |
Instance Method Details
#getHomeDirectory ⇒ Object
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 |
#getVerbose ⇒ Object
63 64 65 |
# File 'lib/pastehub/config.rb', line 63 def getVerbose( ) @verbose_flag end |
#loadClient ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pastehub/config.rb', line 81 def loadClient() name = File.( "~/.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.( sprintf( "%s/.pastehub/", getHomeDirectory() )) + "/" end @localSyncPath = if hash[ :localSyncPath ] hash[ :localSyncPath ] else File.( 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 |