thecore_ftp_helpers 1.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +36 -0
- data/app/assets/config/thecore_ftp_helpers_manifest.js +0 -0
- data/config/initializers/thecore_ftp_helpers_after_initialize.rb +6 -0
- data/config/routes.rb +2 -0
- data/lib/abilities_thecore_ftp_helpers_concern.rb +23 -0
- data/lib/tasks/thecore_ftp_helpers_tasks.rake +4 -0
- data/lib/thecore_ftp_helpers/engine.rb +15 -0
- data/lib/thecore_ftp_helpers/version.rb +3 -0
- data/lib/thecore_ftp_helpers.rb +49 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b82f64f09f258cb58e9e40523c40f3deaaedb8f5
|
4
|
+
data.tar.gz: 9ad5ae0673d36a64640c42b03525b036430f3191
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e94c2b290c00bd8fc0f180da72060e7c6270e764d46547b646da049ed75e338118bbd98b9ebb5a1532b953d1c99302e28195ae7b36a9d604aca48ec8e7ba282
|
7
|
+
data.tar.gz: 1b7ad392d249f0dee55ec5fb24bc62814913aa737c3e071280380f63d476846ca8a182cebe6deeaaaa13644fa19fb7afe1492338d966087f60990ac9a084b9c5
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Gabriele Tassoni
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# ThecoreFtpHelpers
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'thecore_ftp_helpers'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install thecore_ftp_helpers
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ThecoreFtpHelpers'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task default: :test
|
File without changes
|
data/config/routes.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
module ThecoreFtpHelperAbilitiesConcern
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
def thecore_ftp_helpers_abilities user
|
8
|
+
if user
|
9
|
+
# if the user is logged in, it can do certain tasks regardless his role
|
10
|
+
if user.admin?
|
11
|
+
# if the user is an admin, it can do a lot of things, usually
|
12
|
+
end
|
13
|
+
|
14
|
+
if user.has_role? :role
|
15
|
+
# a specific role, brings specific powers
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# include the extension
|
23
|
+
TheCoreAbilities.send(:include, ThecoreFtpHelperAbilitiesConcern)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'thecore'
|
2
|
+
module ThecoreFtpHelpers
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
|
5
|
+
initializer 'thecore_ftp_helpers.add_to_migrations' do |app|
|
6
|
+
unless app.root.to_s == root.to_s
|
7
|
+
# APPEND TO MAIN APP MIGRATIONS FROM THIS GEM
|
8
|
+
config.paths['db/migrate'].expanded.each do |expanded_path|
|
9
|
+
app.config.paths['db/migrate'] << expanded_path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
require 'thecore'
|
3
|
+
require 'net/ftp'
|
4
|
+
require 'thecore_servers'
|
5
|
+
require "thecore_ftp_helpers/engine"
|
6
|
+
|
7
|
+
module ThecoreFtpHelpers
|
8
|
+
class Methods
|
9
|
+
# Your code goes here...
|
10
|
+
def self.list_most_recent_file address, username, password, directory, pattern, close = true, from = nil
|
11
|
+
puts "Connecting to FTP"
|
12
|
+
ftp = Net::FTP.open address, username, password
|
13
|
+
ftp.passive = false
|
14
|
+
puts "Entering directory: #{directory}"
|
15
|
+
ftp.chdir(directory)
|
16
|
+
puts "Listing all files which respond to this pattern: #{pattern}"
|
17
|
+
files = ftp.list(pattern)
|
18
|
+
puts "Last import time: #{from.strftime('%Y-%m-%d %H:%M:%S.%N')}"
|
19
|
+
files = files.select {|f|
|
20
|
+
puts "For file: #{f}"
|
21
|
+
puts "Filetime: #{ftp.mtime(f).strftime('%Y-%m-%d %H:%M:%S.%N')}"
|
22
|
+
puts "File chosen? #{ftp.mtime(f).to_f > from.to_f}"
|
23
|
+
ftp.mtime(f).to_f > from.to_f
|
24
|
+
} unless from.blank?
|
25
|
+
puts "Chosen files: #{files.inspect}"
|
26
|
+
most_recent = files.sort_by{|f| ftp.mtime(f).to_f}.last
|
27
|
+
puts "Opening File: #{most_recent || "No file has been chosen."}"
|
28
|
+
ftp.close if close
|
29
|
+
[most_recent, ftp]
|
30
|
+
end
|
31
|
+
|
32
|
+
# If destination is nil, the file will just be downloaded to RAM
|
33
|
+
def self.download_most_recent_file address, username, password, directory, pattern, destination = nil, from = nil
|
34
|
+
most_recent, ftp = list_most_recent_file address, username, password, directory, pattern, false, from
|
35
|
+
file_content = ftp.gettextfile(most_recent, destination).force_encoding('ISO-8859-1').encode('UTF-8') unless most_recent.nil?
|
36
|
+
|
37
|
+
#.encode!('UTF-8', 'binary', :invalid => :replace) unless most_recent.nil?
|
38
|
+
ftp.close
|
39
|
+
file_content
|
40
|
+
end
|
41
|
+
|
42
|
+
# ThecoreFtpHelpers::Methods.get_and_parse_most_recent_file '31.196.71.18', 'ideabagno', 'idea2017', 'FTP', 'AQUA*', /^[-;]+$/
|
43
|
+
def self.get_and_parse_most_recent_file address, username, password, directory, pattern, skip_lines = nil, quote_char = "\x0C", col_sep = ";", from = nil
|
44
|
+
file_content = download_most_recent_file address, username, password, directory, pattern, nil, from
|
45
|
+
# , converters: lambda { |h| h.titlecase.strip unless h.nil? }, header_converters: lambda { |h| h.downcase.strip.gsub(' ', '_') unless h.nil? }
|
46
|
+
CSV.parse(file_content, col_sep: col_sep, headers: true, skip_blanks: true, force_quotes: true, quote_char: quote_char, skip_lines: skip_lines, converters: lambda { |h| h.titlecase.strip.gsub(",", " ").split.join(" ") unless h.nil? }, header_converters: lambda { |h| h.downcase.strip.gsub(' ', '_').split("_").reject{|c| c.blank? }.uniq.join("_") unless h.nil? }) unless file_content.blank?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thecore_ftp_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.24
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriele Tassoni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thecore_servers
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: Thecorized thecore_ftp_helpers full description.
|
28
|
+
email:
|
29
|
+
- gabriele.tassoni@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/assets/config/thecore_ftp_helpers_manifest.js
|
38
|
+
- config/initializers/thecore_ftp_helpers_after_initialize.rb
|
39
|
+
- config/routes.rb
|
40
|
+
- lib/abilities_thecore_ftp_helpers_concern.rb
|
41
|
+
- lib/tasks/thecore_ftp_helpers_tasks.rake
|
42
|
+
- lib/thecore_ftp_helpers.rb
|
43
|
+
- lib/thecore_ftp_helpers/engine.rb
|
44
|
+
- lib/thecore_ftp_helpers/version.rb
|
45
|
+
homepage: https://www.taris.it
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.6.14
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Thecorized thecore_ftp_helpers
|
69
|
+
test_files: []
|