Class: RuneBlog::Publishing
- Inherits:
-
Object
- Object
- RuneBlog::Publishing
- Defined in:
- lib/global.rb,
lib/publish.rb
Constant Summary collapse
- BadRemoteLogin =
Exception.new("Can't login remotely")
- BadRemotePerms =
Exception.new("Bad remote permissions")
Instance Attribute Summary collapse
-
#docroot ⇒ Object
readonly
Returns the value of attribute docroot.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(*params) ⇒ Publishing
constructor
A new instance of Publishing.
- #publish(files) ⇒ Object
- #remote_login? ⇒ Boolean
- #remote_permissions? ⇒ Boolean
- #to_h ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(*params) ⇒ Publishing
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/publish.rb', line 10 def initialize(*params) @blog = RuneBlog.blog # Clunky... if params.size == 1 && params[0].is_a?(OpenStruct) obj = params[0] array = obj.to_h.values_at(:user, :server, :docroot, :path, :proto) @user, @server, @docroot, @path, @proto = *array else @user, @server, @docroot, @path, @proto = *obj end end |
Instance Attribute Details
#docroot ⇒ Object (readonly)
Returns the value of attribute docroot.
5 6 7 |
# File 'lib/publish.rb', line 5 def docroot @docroot end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/publish.rb', line 5 def path @path end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
5 6 7 |
# File 'lib/publish.rb', line 5 def server @server end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
5 6 7 |
# File 'lib/publish.rb', line 5 def user @user end |
Instance Method Details
#publish(files) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/publish.rb', line 32 def publish(files) debug "files = #{files.inspect}" reset_output dir = "#@docroot/#@path" result = system("ssh #@user@#@server -x mkdir -p #{dir}") list = files.join(' ') cmd = "scp -r #{list} #@user@#@server:#{dir} >/dev/null 2>/tmp/wtf" output! "Publishing #{files.size} files...\n" debug "cmd = #{cmd.inspect} - see /tmp/wtf" result = system(cmd) raise PublishError unless result dump(files, "#{@blog.view.dir}/last_published") output! "...finished.\n" @out end |
#remote_login? ⇒ Boolean
49 50 51 52 53 54 |
# File 'lib/publish.rb', line 49 def remote_login? cmd = "ssh -o BatchMode=yes #@user@#@server -x date >/dev/null 2>&1" result = system(cmd) return nil unless result true end |
#remote_permissions? ⇒ Boolean
56 57 58 59 60 61 62 63 64 |
# File 'lib/publish.rb', line 56 def dir = "#@docroot/#@path" temp = "#@path/__only_testing" try1 = system("ssh -o BatchMode=yes -o ConnectTimeout=1 #@user@#@server -x mkdir -p #{temp} >/dev/null 2>&1") return nil unless try1 try2 = system("ssh -o BatchMode=yes -o ConnectTimeout=1 #@user@#@server -x rmdir #{temp} >/dev/null 2>&1") return nil unless try2 true end |
#to_h ⇒ Object
23 24 25 26 |
# File 'lib/publish.rb', line 23 def to_h {user: @user, server: @server, docroot: @docroot, path: @path, proto: @proto} end |
#url ⇒ Object
28 29 30 |
# File 'lib/publish.rb', line 28 def url url = "#@proto://#@server/#@path" end |