monster_remote 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright [2011] [Ricardo Valeriano ricardo.valeriano@gmail.com | yo@ricardovaleriano.com]
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
data/README.md ADDED
File without changes
@@ -0,0 +1,51 @@
1
+ module Monster
2
+ module Remote
3
+
4
+ class ContentNameBasedFilter
5
+
6
+ def reject(reject_logic)
7
+ @rejecting ||= []
8
+ rejections = []
9
+ if reject_logic.respond_to? :call
10
+ rejections << reject_logic
11
+ else
12
+ rejections = become_block(reject_logic)
13
+ end
14
+ @rejecting += rejections
15
+ self
16
+ end
17
+
18
+ def filter(directory)
19
+ return [] if directory.nil?
20
+ allowed = become_array(directory)
21
+ @rejecting.each do |logic|
22
+ allowed = logic.call(allowed)
23
+ end
24
+ allowed
25
+ end
26
+
27
+ private
28
+
29
+ def become_block(reject)
30
+ rejection_blocks = []
31
+ reject = [reject] unless reject.respond_to? :each
32
+ reject.each do |to_reject|
33
+ rejection_blocks << lambda { |entries|
34
+ entries.reject { |entry| to_reject == entry }
35
+ }
36
+ end
37
+ rejection_blocks
38
+ end
39
+
40
+ def become_array(to_reject)
41
+ to_reject_array = []
42
+ if(to_reject.respond_to?(:each))
43
+ to_reject.each {|entry| to_reject_array << entry}
44
+ else
45
+ to_reject_array = Dir.entries(to_reject)
46
+ end
47
+ to_reject_array
48
+ end
49
+ end # ContentNameBasedFilter
50
+ end
51
+ end
@@ -0,0 +1,57 @@
1
+ module Monster
2
+ module Remote
3
+
4
+ class Sync
5
+
6
+ def self.with
7
+ Sync.new
8
+ end
9
+
10
+ def start
11
+ @provider.open(@host, @port || 21, @user, @pass) do |con|
12
+ con.copy_dir(@local_dir || "./_site", @remote_dir || ".")
13
+ end
14
+ end
15
+
16
+ def add_filter(filter)
17
+ @provider.add_filter(filter)
18
+ end
19
+
20
+ def local_dir(local_dir)
21
+ @local_dir = local_dir
22
+ self
23
+ end
24
+
25
+ def remote_dir(remote_dir)
26
+ @remote_dir = remote_dir
27
+ self
28
+ end
29
+
30
+ def remote_connection_provider(provider)
31
+ @provider = provider
32
+ self
33
+ end
34
+
35
+ def host(host)
36
+ @host = host
37
+ self
38
+ end
39
+
40
+ def port(port)
41
+ @port = port
42
+ self
43
+ end
44
+
45
+ def user(user)
46
+ @user = user
47
+ self
48
+ end
49
+
50
+ def pass(pass)
51
+ @pass = pass
52
+ self
53
+ end
54
+ end # Sync
55
+
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ module Monster
2
+ module Remote
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,87 @@
1
+ require 'net/ftp'
2
+
3
+ module Monster
4
+ module Remote
5
+ module Wrappers
6
+
7
+ class MonsterRemoteNetFTPWrapper < StandardError; end
8
+ class NetFTPPermissionDenied < MonsterRemoteNetFTPWrapper; end
9
+
10
+ class NetFTP
11
+
12
+ def initialize(provider = Net::FTP)
13
+ @provider = provider
14
+ @filters = []
15
+ @nslt = {}
16
+ end
17
+
18
+ def open(host, port, user, pass)
19
+ @provider.open(host) do |ftp|
20
+ @ftp = ftp
21
+ @ftp.connect(host, port)
22
+ @ftp.login(user, pass)
23
+ yield(self, ftp)
24
+ end
25
+ end
26
+
27
+ def copy_dir(local_dir, remote_dir)
28
+ create_if_not_exists(remote_dir)
29
+ local_structure = filter(Dir.entries(local_dir))
30
+ local_structure.each do |entry|
31
+ local_path = File.join(local_dir, entry)
32
+ remote_path = File.join(remote_dir, entry)
33
+ copy(local_path, remote_path)
34
+ end
35
+ end
36
+
37
+ def add_filter(filter)
38
+ @filters ||= []
39
+ @filters << filter
40
+ end
41
+
42
+ private
43
+ def copy(from, to)
44
+ if(Dir.exists?(from))
45
+ copy_dir(from, to)
46
+ else
47
+ copy_file(from, to)
48
+ end
49
+ end
50
+
51
+ def copy_file(from, to)
52
+ @ftp.putbinaryfile(from, to)
53
+ end
54
+
55
+ def filter(dir_structure)
56
+ if(@filters.empty?)
57
+ @filters << ContentNameBasedFilter.new.reject([".", ".."])
58
+ end
59
+
60
+ allowed = dir_structure
61
+ @filters.each do |f|
62
+ allowed = f.filter(allowed)
63
+ end
64
+ allowed
65
+ end
66
+
67
+ def create_remote_dir(dir)
68
+ dirname = File.dirname(dir)
69
+ dir_content = @nslt[dirname] || @ftp.nlst(dirname)
70
+ dir_exists = dir_content.include? dir
71
+ @ftp.mkdir(dir) unless dir_exists
72
+ end
73
+
74
+ def create_if_not_exists(dir)
75
+ begin
76
+ create_remote_dir(dir)
77
+ rescue Net::FTPPermError => e
78
+ denied = NetFTPPermissionDenied.new(e)
79
+ raise denied, e.message
80
+ end
81
+ end
82
+
83
+ end # NetFTP
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ require 'monster/remote/sync'
2
+ require 'monster/remote/wrappers/net_ftp'
3
+ require 'monster/remote/content_name_based_filter'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monster_remote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ricardo Valeriano
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70198510250960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70198510250960
25
+ - !ruby/object:Gem::Dependency
26
+ name: fakefs
27
+ requirement: &70198510250500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70198510250500
36
+ description: This gem allow you publish your jekyll static site via FTP, easy as pie.
37
+ email:
38
+ - ricardovaleriano.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - lib/monster/remote/content_name_based_filter.rb
44
+ - lib/monster/remote/sync.rb
45
+ - lib/monster/remote/version.rb
46
+ - lib/monster/remote/wrappers/net_ftp.rb
47
+ - lib/monster/remote.rb
48
+ - LICENSE
49
+ - README.md
50
+ homepage: http://github.com/ricardovaleriano/monster_remote
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 1.8.10
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.10
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Publish your jekyll blog via ftp easy as pie
74
+ test_files: []