yard-sftp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0bd955f7b7c987b198f861beac206f61462d4aa
4
+ data.tar.gz: 767e6b2a0a990733ae2a3525e72eda395894bb31
5
+ SHA512:
6
+ metadata.gz: 74336a21fa830857f6f7a32aee44db1b212b3c340a74546d5a4567ed1d7f69b2b9fa619f4de72b25e216223b9fe2744e26948d2629df53bcb5353f5cbbcdc658
7
+ data.tar.gz: 324fa2a117abaa1483c33627988162aa740557ae95bf2d1b7475b0bf3c010010a5bf333a51d3e243dfa97e9f21b292f0db609a2c1d92a5df81c3b46a2bf55e84
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ Gemfile.lock
16
+ report.html
17
+
18
+ # YARD artifacts
19
+ .yardoc
20
+ _yardoc
21
+ .yardsftp
22
+ doc/
File without changes
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'bundler', '~> 1.3.4'
4
+ gem "coveralls", "~> 0.6.7", require: false
5
+
6
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Jonathan Chrisp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # yard-sftp
2
+
3
+ Move your new shiny yard documentation to a remote location with SFTP!
4
+
5
+ ## Getting Started
6
+
7
+ In order to move your yard documentation to a remote location using SFTP you need to setup a local `.yardsftp` config file in your projects base directory. Please see the example below:
8
+
9
+ --- !ruby/hash:SymbolHash
10
+ :yard-sftp:
11
+ host: 'example.com'
12
+ base_path: '/home/public_html'
13
+ base_folder: 'project_one/'
14
+ username: 'username'
15
+ password: 'password'
16
+
17
+ Once this is all setup hit `yard` at your command line as you normally would and each file will uploaded via SFTP as they are created. Please note that both the `.yardopts` and `doc` directories are uploaded!
18
+
19
+ ### `.yardsftp` config file? Why?
20
+ I've added a new `.yardsftp` so different projects can be uploaded to custom remote locations. I did attempt to add these to the global `.yard/config` file but there was no way to distinguish custom remote file paths between different projects! Please email if you have a good suggestion!
21
+
22
+ ## Tests
23
+ There are a no tests at present, this project was a proof of concept but these will be done at some point.
24
+
25
+ ## Feedback
26
+ I would be more than happy to recieve feedback, please email me at: jonathan.chrisp@gmail.com
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/yard/core_ext/file.rb"
@@ -0,0 +1,3 @@
1
+ module YARDSFTP
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,122 @@
1
+ require 'fileutils'
2
+ require 'pry'
3
+ require 'colored'
4
+ require 'yaml'
5
+ require 'net/sftp'
6
+ YAML::ENGINE.yamler = 'psych'
7
+
8
+ class File
9
+
10
+ # @group Reading Files
11
+ # Forces opening a file (for writing) by first creating the file's directory
12
+ # @param [String] file the filename to open
13
+ # @since 0.5.2
14
+ def self.open!(file, *args, &block)
15
+ dir = dirname(file)
16
+ FileUtils.mkdir_p(dir) unless directory?(dir)
17
+ open(file, *args, &block)
18
+
19
+ # Create base directory, file directories and upload file via sftp
20
+ sftp_create_base_directory
21
+ sftp_file(file)
22
+ end
23
+
24
+ # Sets config from local .yardsftp file
25
+ #
26
+ # @return [Hash] opts Hash
27
+ def self.sftp_config
28
+ begin
29
+ opts = YAML.load_file('.yardsftp')
30
+ rescue Psych::SyntaxError
31
+ abort 'Your .yardsftp file did not parse as expected!'.red.underline
32
+ rescue Errno::ENOENT
33
+ abort 'Your .yardsftp file is missing!'.red.underline
34
+ end
35
+
36
+ return opts
37
+ end
38
+
39
+ # Creates or returns sftp instance
40
+ #
41
+ # @return [Object] sftp instance
42
+ def self.sftp
43
+ sftp ||= Net::SFTP.start(HOST, USER, :password => PWD)
44
+ end
45
+
46
+ # Uploads file
47
+ def self.sftp_file(file_path)
48
+ directories = sftp_split_all(file_path)
49
+ directories.pop #removes actual file from array
50
+
51
+ unless directories.empty?
52
+ sftp_build_directories(directories)
53
+ end
54
+
55
+ sftp.upload!(file_path, "#{BASE_PATH}/#{BASE_FOLDER}/#{file_path}")
56
+ end
57
+
58
+ # Creates directories
59
+ #
60
+ # @param opts [Array] directories Array of directory names
61
+ def self.sftp_build_directories(directories)
62
+ directories.each.with_index do |dir, i|
63
+ if i == 0
64
+ path = "#{BASE_PATH}/#{BASE_FOLDER}/#{dir}"
65
+ elsif i == 1
66
+ path = "#{BASE_PATH}/#{BASE_FOLDER}/#{directories[0]}/#{dir}"
67
+ else
68
+ path = "#{BASE_PATH}/#{BASE_FOLDER}/#{directories.take(i-1).join('/')}/#{dir}"
69
+ end
70
+
71
+ sftp_create_directory(path)
72
+ end
73
+ end
74
+
75
+ # Creates base directory
76
+ def self.sftp_create_base_directory
77
+ unless sftp_directory_exists?("#{BASE_PATH}/#{BASE_FOLDER}")
78
+ sftp_create_directory("#{BASE_PATH}/#{BASE_FOLDER}")
79
+ end
80
+ end
81
+
82
+ # Creates base directory
83
+ #
84
+ # @param opts [String] path the path of directory
85
+ def self.sftp_create_directory(path)
86
+ unless sftp_directory_exists?(path)
87
+ sftp.mkdir(path).wait
88
+ end
89
+ end
90
+
91
+ # Checks if the directory exists
92
+ #
93
+ # @param opts [String] path the path of directory
94
+ def self.sftp_directory_exists?(path)
95
+ begin
96
+ sftp.stat!(path)
97
+ rescue
98
+ return false
99
+ else
100
+ return true
101
+ end
102
+ end
103
+
104
+ # Splits file path
105
+ #
106
+ # @param opts [String] path the path of directory
107
+ # @return [Array] returns array of directories
108
+ def self.sftp_split_all(path)
109
+ head, tail = File.split(path)
110
+ return [tail] if head == '.' || tail == '/'
111
+ return [head, tail] if head == '/'
112
+ return sftp_split_all(head) + [tail]
113
+ end
114
+
115
+ # Set configuration options
116
+ OPTS = sftp_config
117
+ HOST = OPTS['yard-sftp']['host']
118
+ USER = OPTS['yard-sftp']['username']
119
+ PWD = OPTS['yard-sftp']['password']
120
+ BASE_PATH = OPTS['yard-sftp']['base_path']
121
+ BASE_FOLDER = OPTS['yard-sftp']['base_folder']
122
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + "/lib/yard-sftp/version"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'yard-sftp'
5
+ s.version = YARDSFTP::VERSION
6
+ s.date = '2013-07-15'
7
+ s.summary = 'yard-sftp - securely transfer your yard documentation'
8
+ s.description = 'Move you new shiny documentation to a remote location with SFTP'
9
+ s.author = 'Jonathan Chrisp'
10
+ s.email = 'jonathan.chrisp@gmail.com'
11
+ s.license = 'MIT'
12
+ s.homepage = 'https://github.com/jonathanchrisp/yard-sftp'
13
+ s.required_ruby_version = ">= 1.9.2"
14
+
15
+ s.add_development_dependency 'rspec', '~> 2.13.0'
16
+ s.add_development_dependency 'pry', '~> 0.9.12.2'
17
+
18
+ s.add_runtime_dependency 'colored', '~> 1.2'
19
+ s.add_runtime_dependency 'yard', '~> 0.8.6.2'
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.test_files = `git ls-files -- spec/*`.split("\n")
24
+ s.require_paths = ['lib']
25
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-sftp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Chrisp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.13.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.13.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.12.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.12.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: colored
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.6.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.6.2
69
+ description: Move you new shiny documentation to a remote location with SFTP
70
+ email: jonathan.chrisp@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .gitignore
76
+ - .travis.yml
77
+ - Gemfile
78
+ - LICENCE.md
79
+ - README.md
80
+ - lib/yard-sftp.rb
81
+ - lib/yard-sftp/version.rb
82
+ - lib/yard/core_ext/file.rb
83
+ - yard-sftp.gemspec
84
+ homepage: https://github.com/jonathanchrisp/yard-sftp
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.9.2
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.0.5
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: yard-sftp - securely transfer your yard documentation
108
+ test_files: []
109
+ has_rdoc: