Module: PasteHub
- Defined in:
- lib/pastehub/plugin.rb,
lib/pastehub/util.rb,
lib/pastehub/client.rb,
lib/pastehub/config.rb,
lib/pastehub/clipboard.rb,
lib/pastehub/syncentry.rb,
lib/pastehub/clientsync.rb,
lib/pastehub/plugin_base.rb,
lib/pastehub/plugin/sample.rb,
lib/pastehub/plugin/sendmail.rb,
lib/pastehub/plugin/dropbox_todo.rb,
lib/pastehub/plugin/notification_center.rb
Overview
plugin_base.rb - Base class for plugin implementation.
Copyright (c) 2014-2014 Kiyoka Nishiyama <[email protected]>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Defined Under Namespace
Classes: AbstractClipboard, ClientSync, Config, DropboxTodo, Entry, EntryBase, MailSetting, NotificationCenter, PluginBase, PluginClass, PluginSample, SendMail, Status, Util
Constant Summary collapse
- Plugin =
PluginClass.new
Class Method Summary collapse
- .hostname ⇒ Object
- .loadPid ⇒ Object
- .savePid(pid) ⇒ Object
-
.setupDirectory ⇒ Object
setup user’s directory and sync directory result: true …
Class Method Details
.hostname ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pastehub/client.rb', line 67 def self.hostname( ) hostname = open( "|hostname" ) { |f| f.read.chomp } if 0 < hostname.size() hostname else raise RuntimeError, "Can't resolve hostname" end end |
.loadPid ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/pastehub/client.rb', line 85 def self.loadPid pidFile = PasteHub::Config.instance.localDbPath + "pid" pid = 0 begin pid = open( pidFile ) {|f| f.readline.chomp.to_i } rescue Exception => e STDERR.puts( "Warning: can't load #{pidFile}: #{e.to_s}" ) pid = 0 end return pid end |
.savePid(pid) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/pastehub/client.rb', line 78 def self.savePid( pid ) pidFile = PasteHub::Config.instance.localDbPath + "pid" open( pidFile, "w" ) {|f| f.puts pid } end |
.setupDirectory ⇒ Object
setup user’s directory and sync directory
result: true ... success / false ... fail
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pastehub/client.rb', line 45 def self.setupDirectory localdb_path = PasteHub::Config.instance.localDbPath localsync_path = PasteHub::Config.instance.localSyncPath public_path = PasteHub::Config.instance.publicPath # Create directory if not File.exist?( localdb_path ) FileUtils.mkdir_p( localdb_path, { :mode => 0700 } ) end # Create directory for Sync if not File.exist?( localsync_path ) FileUtils.mkdir_p( localsync_path, { :mode => 0700 } ) end # Create Dropbox/Public directory if not File.exist?( public_path ) FileUtils.mkdir_p( public_path, { :mode => 0700 } ) end return true end |