simple_hot_folder 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05e7b7d67883721f6abb99ccdfaa0374635e0c98
4
+ data.tar.gz: b6bbeee6846d832154e3114b2c96b500e1a790de
5
+ SHA512:
6
+ metadata.gz: cd5779b777f4cb7b898d6d0a6210fc6bc36008f525259ae341aa9944e64922e2c1f91757c10b3590321c4b15fb6d1138b5c280b8fa2a09254549f361a53d41d1
7
+ data.tar.gz: 173cb9a61b5ef6f924b362bc17de3ee7492e86a95c047d06c6b9e5134163e002a4a7442bf1101ff427c33dab692f05527936bc7e16ea0850b87349c4e7d5210d
data/.gitignore ADDED
@@ -0,0 +1,66 @@
1
+ # Test hot folders
2
+ /test-data/hot-folder/input/*
3
+ !/test-data/hot-folder/input/.keep
4
+
5
+ /test-data/hot-folder/output/*
6
+ !/test-data/hot-folder/output/.keep
7
+
8
+ /test-data/hot-folder/error/*
9
+ !/test-data/hot-folder/error/.keep
10
+
11
+ # Specific environment configuration
12
+ /config/environments/*
13
+ !/config/environments/.keep
14
+
15
+ # Custom
16
+ *.gem
17
+
18
+ # Ensure empty folders
19
+ /doc/*
20
+ !/doc/.keep
21
+
22
+ /pkg/*
23
+ !/pkg/.keep
24
+
25
+ /tmp/*
26
+ !/tmp/.keep
27
+
28
+ # Generated by gem bundle
29
+ /.bundle/
30
+ /.yardoc
31
+ /Gemfile.lock
32
+ /_yardoc/
33
+ /coverage/
34
+ # /doc
35
+ # /pkg
36
+ # /tmp
37
+ /spec/reports/
38
+
39
+ # Assets generators
40
+ .sass-cache
41
+
42
+ # Mac finder artifacts
43
+ .com.apple.timemachine.supported
44
+ .DS_Store
45
+ .DS_Store?
46
+ ._*
47
+ .Spotlight-V100
48
+ .Trashes
49
+ ehthumbs.db
50
+ Thumbs.db
51
+
52
+ # Linux artifacts
53
+ *~
54
+
55
+ # Netbeans project directory
56
+ /nbproject/
57
+
58
+ # Intellij files
59
+ .idea
60
+
61
+ # Textmate project files
62
+ /*.tmproj
63
+
64
+ # vim artifacts
65
+ **.swp
66
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2018-07-10
4
+
5
+ * First version.
6
+
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gtemplate.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'minitest-reporters'
8
+ end
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Gtemplate
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gtemplate`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gtemplate'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gtemplate
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gtemplate.
36
+
37
+ ## Ficheros cambiados
38
+
39
+ Cambios
40
+
41
+ 1. test_helper y resto de tests.
42
+ 1. Rakefile entero
43
+ 1. CHANGELOG y README
44
+
45
+ Nombre fichero/carpeta:
46
+
47
+ 1. lib/simple_hot_folder
48
+ 1. lib/simple_hot_folder.rb
49
+ 1. test/test_helper.rb
50
+
51
+ Contenido del fichero (nombres de la gema)
52
+
53
+ 1. lib/simple_hot_folder.rb
54
+ 1. lib/simple_hot_folder/*
55
+ 1. test/*
56
+ 1. simple_hot_folder.gemspec
57
+
58
+ Contenido del fichero (otros casos)
59
+
60
+ 1. lib/simple_hot_folder/version.rb (poner 0.0.1)
61
+
data/Rakefile ADDED
@@ -0,0 +1,120 @@
1
+ require "rake/testtask"
2
+ require_relative "lib/simple_hot_folder/version"
3
+
4
+ def name
5
+ SimpleHotFolder::NAME
6
+ end
7
+
8
+ def version
9
+ SimpleHotFolder::VERSION
10
+ end
11
+
12
+ def gemspec_file
13
+ "#{name}.gemspec"
14
+ end
15
+
16
+ def gem_file
17
+ "#{name}-#{version}.gem"
18
+ end
19
+
20
+ def show_text(text)
21
+ puts ''
22
+ puts '================================================='
23
+ puts text
24
+ puts '================================================='
25
+ puts ''
26
+ end
27
+
28
+ def show_error_and_exit!(text)
29
+ show_text("ERROR: #{text}.")
30
+ exit!
31
+ end
32
+
33
+ def show_release
34
+ show_text("#{gem_file} released.")
35
+ end
36
+
37
+ def read_changelog
38
+ `head -20 CHANGELOG.md`.to_s
39
+ end
40
+
41
+ def current_branch
42
+ r = `git branch`.to_s.strip
43
+ if r.include? "master"
44
+ 'master'
45
+ else
46
+ 'other'
47
+ end
48
+ end
49
+
50
+ def git_status
51
+ r = `git status`.to_s
52
+ if r.include? "nothing to commit"
53
+ 'clean'
54
+ else
55
+ 'not_clean'
56
+ end
57
+ end
58
+
59
+ def ask_for_confirmation
60
+ puts "Are you sure you want to release version #{version}? [yN]"
61
+ STDIN.gets.chomp.upcase
62
+ end
63
+
64
+ Rake::TestTask.new do |t|
65
+ t.libs << 'test'
66
+ t.pattern = 'test/**/*_test.rb'
67
+ t.warning = false
68
+ t.verbose = false
69
+ end
70
+
71
+ task :default => :test
72
+
73
+ desc "Release #{gem_file}"
74
+ task :release => :build do
75
+ show_text ">> Releasing #{gem_file}"
76
+ if current_branch != 'master'
77
+ msg = "You must be on the master branch to release!"
78
+ show_error_and_exit! msg
79
+ end
80
+ if git_status != 'clean'
81
+ msg = "There are still files left to commit"
82
+ show_error_and_exit! msg
83
+ end
84
+ show_text ">> Changelog file"
85
+ puts read_changelog
86
+ show_text ">> Confirmation"
87
+ if ask_for_confirmation != 'Y'
88
+ show_error_and_exit! "Aborting release"
89
+ end
90
+ sh "git commit --allow-empty -m 'Release #{version}'"
91
+ sh "git tag v#{version}"
92
+ sh "git push origin master"
93
+ show_release
94
+ end
95
+
96
+ desc "Build #{name} v#{version} into pkg folder"
97
+ task :build do
98
+ show_text ">> Creating #{gem_file}"
99
+ mkdir_p "pkg"
100
+ sh "gem build #{gemspec_file}"
101
+ sh "mv #{gem_file} pkg"
102
+ puts ""
103
+ end
104
+
105
+ desc "Deploy #{name} v#{version} to RubyGems"
106
+ task :deploy do
107
+ show_text ">> Deploying #{gem_file}"
108
+ sh "gem push pkg/#{gemspec_file}"
109
+ puts ""
110
+ end
111
+
112
+ desc "Show current #{name} version"
113
+ task :version do
114
+ show_text("Version #{version}")
115
+ end
116
+
117
+
118
+
119
+
120
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gtemplate"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../../lib/gtemplate'
4
+
5
+ v = Gtemplate::VERSION
6
+
7
+ puts ''
8
+ puts 'Add files to git:'
9
+ puts '================='
10
+ puts ''
11
+ system('git add -A; git status')
12
+
13
+ puts ''
14
+ puts 'Build and install gem'
15
+ puts '====================='
16
+ puts ''
17
+ system('gem uninstall -aIx gtemplate')
18
+ system('gem build gtemplate.gemspec')
19
+ system('gem install gtemplate-' + v + '.gem')
20
+
21
+
22
+
@@ -0,0 +1,77 @@
1
+ module SimpleHotFolder
2
+ class HotFolder
3
+
4
+ IGNORE_FOLDERS = [
5
+ '.',
6
+ '..',
7
+ ]
8
+
9
+ def initialize(input_path, error_path, output_path)
10
+ @input_path = input_path
11
+ @error_path = error_path
12
+ @output_path = output_path
13
+ @validate_file = default_validate_file_function
14
+ end
15
+
16
+ def process_input!
17
+ entries = read_input(@input_path)
18
+ entries.each do |entry|
19
+ begin
20
+ yield entry
21
+ FileUtils.mv(entry.path, @output_path) if File.exist?(entry.path)
22
+ rescue Exception => e
23
+ move_file_to_error!(entry, e)
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def move_file_to_error!(entry, exception)
31
+ FileUtils.mv(entry.path, @error_path) if File.exist?(entry.path)
32
+ write_error_file(entry, exception.message)
33
+ end
34
+
35
+ def write_error_file(entry, text)
36
+ path = "#{@error_path}/#{entry.name}.txt"
37
+ File.open(path, 'w') { |file| file.write(text) }
38
+ end
39
+
40
+ def read_input(path)
41
+ Dir.entries(path)
42
+ .map { |name| Entry.new(name, "#{path}/#{name}") }
43
+ .keep_if { |entry| processable?(entry) }
44
+ # .each { |entry| p entry.path }
45
+ # .keep_if { |entry| @validate_file.(entry) }
46
+ end
47
+
48
+ def validate_entry(entry)
49
+ entry
50
+ end
51
+
52
+ def processable?(entry)
53
+ return false if !File.file?(entry.path)
54
+ return false if IGNORE_FOLDERS.include?(entry.name)
55
+ return false if entry.name.start_with?('.')
56
+ true
57
+ end
58
+
59
+ def default_validate_file_function
60
+ ->(file) {
61
+ true
62
+ }
63
+ end
64
+
65
+ end
66
+
67
+ class HotFolder::Entry
68
+ attr_reader :name
69
+ attr_reader :path
70
+ def initialize(name, path)
71
+ @name = name
72
+ @path = path
73
+ end
74
+ end
75
+
76
+ end
77
+
@@ -0,0 +1,4 @@
1
+ module SimpleHotFolder
2
+ VERSION = '0.1.0'.freeze
3
+ NAME = 'simple_hot_folder'.freeze
4
+ end
@@ -0,0 +1,26 @@
1
+ def require_all(path)
2
+ glob = File.join(__dir__, path, "*.rb")
3
+ Dir[glob].sort.each do |f|
4
+ require f
5
+ end
6
+ end
7
+
8
+ # stdlib
9
+ require "fileutils"
10
+ require "ostruct"
11
+ # simple_hot_folder lib
12
+ require_all "simple_hot_folder"
13
+
14
+ module SimpleHotFolder
15
+
16
+ # Create hot folder that listens for files.
17
+ #
18
+ # @param [String] input_path Input folder path
19
+ # @param [String] error_path Error folder path
20
+ # @param [String] output_path Error folder path
21
+ # @return [HotFolder]
22
+ def self.for_files(input_path, error_path, output_path = nil)
23
+ HotFolder.new(input_path, error_path, output_path)
24
+ end
25
+
26
+ end
data/notes.md ADDED
@@ -0,0 +1,61 @@
1
+ # Notes
2
+
3
+ ## Executed commands
4
+
5
+ Build a new version of the gem:
6
+
7
+ 1. git add -A
8
+ 1. gem build gtemplate.gemspec
9
+ 1. gem install gtemplate-0.0.0.gem
10
+
11
+ Run IRB loading gtemplate gem:
12
+
13
+ * irb -rgtemplate
14
+
15
+ List installed gems:
16
+
17
+ * gem list
18
+ * gem list gtemplate
19
+ * gem list | grep gtemplate
20
+
21
+ Uninstall gem:
22
+
23
+ * gem uninstall -aIx
24
+
25
+ ## Dudes
26
+
27
+ * ¿Minitest?
28
+
29
+ ## Testing
30
+
31
+ rake test
32
+
33
+ ## Gemspec
34
+
35
+ Gemspec file add .rb files dinamically using `git ls-files` command.
36
+
37
+ ```
38
+ all_files = `git ls-files -z`.split("\x0")
39
+ ```
40
+
41
+ That's why you need to add every file to git before building the gem.
42
+
43
+ ## Info
44
+
45
+ * http://www.alexedwards.net/blog/how-to-make-a-rubygem
46
+ * http://www.alexedwards.net/blog/how-to-make-a-rubygem-part-two
47
+ * http://jamespmcgrath.com/how-to-uninstall-all-ruby-gems-in-one-line/
48
+
49
+ ## TODO
50
+
51
+ Issues:
52
+
53
+ * documentation
54
+ * script renombrar gem del estilo de cmd-app-template
55
+
56
+
57
+
58
+
59
+
60
+
61
+
@@ -0,0 +1,69 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_hot_folder/version'
5
+
6
+ Gem::Specification.new do |s|
7
+
8
+ s.name = SimpleHotFolder::NAME
9
+ s.version = SimpleHotFolder::VERSION
10
+ s.authors = ["Manu"]
11
+ s.email = ["galfus@gmail.com"]
12
+ s.date = Time.now.strftime('%Y-%m-%d')
13
+ s.summary = %q{Write a short summary, because Rubygems requires one.}
14
+ s.description = %q{Write a longer description or delete this line.}
15
+ s.license = "Nonstandard"
16
+ s.homepage = "http://www.galfus.com"
17
+
18
+ # s.required_ruby_version = '>= 2.1.0'
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ # if spec.respond_to?(:metadata)
23
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
26
+ # end
27
+
28
+ # Jekyll
29
+ # s.files = all_files.grep(%r!^(exe|lib)/|^.rubocop.yml$!)
30
+ # s.executables = all_files.grep(%r!^exe/!) { |f| File.basename(f) }
31
+
32
+ # Colorize
33
+ # s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ # s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+
36
+ # Custom
37
+ all_files = `git ls-files -z`.split("\x0")
38
+ s.files = all_files
39
+ .reject { |f| f.match(%r{^(test|spec|features|doc|tmp|pkg)/}) }
40
+ s.executables = all_files.grep(%r{^exe/}) { |f| File.basename(f) }
41
+
42
+ # spec.test_files = [
43
+ # 'test/bla-bla.rb'
44
+ # ]
45
+
46
+ s.bindir = "exe"
47
+ s.require_paths = ["lib"]
48
+
49
+ # s.add_runtime_dependency("addressable", "~> 2.4")
50
+ # s.add_runtime_dependency("dry-struct")
51
+
52
+ s.add_development_dependency "bundler", "~> 1.12"
53
+ s.add_development_dependency "rake", "~> 10.0"
54
+ s.add_development_dependency 'minitest', '~> 5.0'
55
+
56
+ # puts ''
57
+ # puts '------------ Configurando gem'
58
+ # puts ''
59
+ # puts 'All:'
60
+ # p all_files
61
+ # puts ''
62
+ # puts 'Files:'
63
+ # p s.files
64
+ # puts ''
65
+ # puts 'Execuables:'
66
+ # p s.executables
67
+ # puts '------------'
68
+ # puts ''
69
+ end
data/test-data/.keep ADDED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_hot_folder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Write a longer description or delete this line.
56
+ email:
57
+ - galfus@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - bin/support/build-and-install-gem
70
+ - lib/simple_hot_folder.rb
71
+ - lib/simple_hot_folder/hot_folder.rb
72
+ - lib/simple_hot_folder/version.rb
73
+ - notes.md
74
+ - simple_hot_folder.gemspec
75
+ - test-data/.keep
76
+ - test-data/hot-folder/error/.keep
77
+ - test-data/hot-folder/initial-data/.keep
78
+ - test-data/hot-folder/initial-data/file1.jpg
79
+ - test-data/hot-folder/initial-data/file2.jpg
80
+ - test-data/hot-folder/input/.keep
81
+ - test-data/hot-folder/output/.keep
82
+ homepage: http://www.galfus.com
83
+ licenses:
84
+ - Nonstandard
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.6.11
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Write a short summary, because Rubygems requires one.
106
+ test_files: []