file_composer 1.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b20f3a6535e696278e0963870386a581303c62d227ad900dc434d6b5c48ba628
4
+ data.tar.gz: 39ed8e5cc2a575991931bbe525955af31081e82db860dc2b0e69b14d162c5d8c
5
+ SHA512:
6
+ metadata.gz: 66ef27c3b5f2c608d1ba988e095287caae3c1b3ef563d7129088bddeb01d00010943d5ed59708b2f20572fc2cc1c8b1e1a84fea11040b4573cdb73f56868ada5
7
+ data.tar.gz: ee35c5159e6020032754a4cd7067a930da1d2c7a4aa59e806c4837ffa0847206e904fa5e18b91af39027fc42f924ebdb05d989cd63e0dce245d90440323782d7
@@ -0,0 +1,8 @@
1
+ # See http://editorconfig.org/
2
+
3
+ [*]
4
+ trim_trailing_whitespace = true
5
+ indent_style = space
6
+ indent_size = 2
7
+ insert_final_newline = true
8
+ end_of_line = lf
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ *.gem
3
+ /tmp
4
+ /coverage
5
+ Gemfile.lock
6
+ /pkg
@@ -0,0 +1,32 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+
5
+ Layout/LineLength:
6
+ Max: 100
7
+ Exclude:
8
+ - file_composer.gemspec
9
+
10
+ Metrics/BlockLength:
11
+ ExcludedMethods:
12
+ - let
13
+ - it
14
+ - describe
15
+ - context
16
+ - specify
17
+ - define
18
+
19
+ Metrics/MethodLength:
20
+ Max: 30
21
+
22
+ Metrics/AbcSize:
23
+ Max: 20
24
+
25
+ Metrics/ClassLength:
26
+ Max: 125
27
+
28
+ Style/TrailingCommaInHashLiteral:
29
+ Enabled: false
30
+
31
+ Style/TrailingCommaInArrayLiteral:
32
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.6.6
@@ -0,0 +1,24 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=ed7a2023e05284b8b198724c5712a1a82aa13e754fa925f18ff9b839151a2175
4
+ language: ruby
5
+ rvm:
6
+ # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
7
+ - 2.5.8
8
+ - 2.6.6
9
+ - 2.7.1
10
+ cache: bundler
11
+ before_script:
12
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
+ - chmod +x ./cc-test-reporter
14
+ - ./cc-test-reporter before-build
15
+ script:
16
+ - bundle exec rubocop
17
+ - bundle exec rspec spec --format documentation
18
+ after_script:
19
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
20
+ addons:
21
+ # https://docs.travis-ci.com/user/uploading-artifacts/
22
+ artifacts:
23
+ paths:
24
+ - Gemfile.lock
@@ -0,0 +1,3 @@
1
+ # 1.0.0 (TBD)
2
+
3
+ Initial Release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at oss@bluemarblepayroll.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :rspec, cmd: 'DISABLE_SIMPLECOV=true bundle exec rspec --format=documentation' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Blue Marble Payroll, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,76 @@
1
+ # File Composer
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/file_composer.svg)](https://badge.fury.io/rb/file_composer) [![Build Status](https://travis-ci.org/bluemarblepayroll/file_composer.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/file_composer) [![Maintainability](https://api.codeclimate.com/v1/badges/5360d687b0e93a4c7cf5/maintainability)](https://codeclimate.com/github/bluemarblepayroll/file_composer/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/5360d687b0e93a4c7cf5/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/file_composer/test_coverage) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+
5
+ TBD
6
+
7
+ ## Installation
8
+
9
+ To install through Rubygems:
10
+
11
+ ````
12
+ gem install install file_composer
13
+ ````
14
+
15
+ You can also add this to your Gemfile:
16
+
17
+ ````
18
+ bundle add file_composer
19
+ ````
20
+
21
+ ## Examples
22
+
23
+ TBD
24
+
25
+ ## Contributing
26
+
27
+ ### Development Environment Configuration
28
+
29
+ Basic steps to take to get this repository compiling:
30
+
31
+ 1. Install [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (check file_composer.gemspec for versions supported)
32
+ 2. Install bundler (gem install bundler)
33
+ 3. Clone the repository (git clone git@github.com:bluemarblepayroll/file_composer.git)
34
+ 4. Navigate to the root folder (cd file_composer)
35
+ 5. Install dependencies (bundle)
36
+
37
+ ### Running Tests
38
+
39
+ To execute the test suite run:
40
+
41
+ ````bash
42
+ bundle exec rspec spec --format documentation
43
+ ````
44
+
45
+ Alternatively, you can have Guard watch for changes:
46
+
47
+ ````bash
48
+ bundle exec guard
49
+ ````
50
+
51
+ Also, do not forget to run Rubocop:
52
+
53
+ ````bash
54
+ bundle exec rubocop
55
+ ````
56
+
57
+ ### Publishing
58
+
59
+ Note: ensure you have proper authorization before trying to publish new versions.
60
+
61
+ After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
62
+
63
+ 1. Merge Pull Request into master
64
+ 2. Update `lib/file_composer/version.rb` using [semantic versioning](https://semver.org/)
65
+ 3. Install dependencies: `bundle`
66
+ 4. Update `CHANGELOG.md` with release notes
67
+ 5. Commit & push master to remote and ensure CI builds master successfully
68
+ 6. 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).
69
+
70
+ ## Code of Conduct
71
+
72
+ Everyone interacting in this codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bluemarblepayroll/file_composer/blob/master/CODE_OF_CONDUCT.md).
73
+
74
+ ## License
75
+
76
+ This project is MIT Licensed.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'bundler/gem_tasks'
11
+ require 'rspec/core/rake_task'
12
+ require 'rubocop/rake_task'
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+ RuboCop::RakeTask.new
16
+
17
+ task default: %i[rubocop spec]
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
6
+ #
7
+ # This source code is licensed under the MIT license found in the
8
+ # LICENSE file in the root directory of this source tree.
9
+ #
10
+
11
+ require 'bundler/setup'
12
+ require 'file_composer'
13
+
14
+ # You can add fixtures and/or initialization code here to make experimenting
15
+ # with your gem easier. You can also use a different console, if you like.
16
+
17
+ require 'pry'
18
+ Pry.start
File without changes
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/file_composer/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'file_composer'
7
+ s.version = FileComposer::VERSION
8
+ s.summary = 'High-level, pluggable and YAML-based API for creating files'
9
+
10
+ s.description = <<-DESCRIPTION
11
+ This library provides a YAML-based configuration, called a Blueprint, that allows you to specify text files and zip files and it will create them. It is pluggable so other document types and storage mediums can be added.
12
+ DESCRIPTION
13
+
14
+ s.authors = ['Matthew Ruggio']
15
+ s.email = ['mruggio@bluemarblepayroll.com']
16
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ s.bindir = 'exe'
18
+ s.executables = []
19
+ s.homepage = 'https://github.com/bluemarblepayroll/file_composer'
20
+ s.license = 'MIT'
21
+ s.metadata = {
22
+ 'bug_tracker_uri' => 'https://github.com/bluemarblepayroll/file_composer/issues',
23
+ 'changelog_uri' => 'https://github.com/bluemarblepayroll/file_composer/blob/master/CHANGELOG.md',
24
+ 'documentation_uri' => 'https://www.rubydoc.info/gems/file_composer',
25
+ 'homepage_uri' => s.homepage,
26
+ 'source_code_uri' => s.homepage
27
+ }
28
+
29
+ s.required_ruby_version = '>= 2.5'
30
+
31
+ s.add_dependency('acts_as_hashable', '~>1.2')
32
+ s.add_dependency('rubyzip', '~>1.2')
33
+
34
+ s.add_development_dependency('guard-rspec', '~>4.7')
35
+ s.add_development_dependency('pry', '~>0')
36
+ s.add_development_dependency('rake', '~> 13')
37
+ s.add_development_dependency('rspec', '~> 3.8')
38
+ s.add_development_dependency('rubocop', '~>0.88.0')
39
+ s.add_development_dependency('simplecov', '~>0.18.5')
40
+ s.add_development_dependency('simplecov-console', '~>0.7.0')
41
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'acts_as_hashable'
11
+ require 'benchmark'
12
+ require 'securerandom'
13
+ require 'time'
14
+ require 'zip'
15
+
16
+ require_relative 'file_composer/blueprint'
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'documents'
11
+ require_relative 'stores'
12
+
13
+ module FileComposer
14
+ # The main object model.
15
+ class Blueprint
16
+ acts_as_hashable
17
+
18
+ attr_reader :documents
19
+
20
+ def initialize(documents: [])
21
+ @documents = Documents.array(documents)
22
+
23
+ filenames = @documents.map { |a| a.filename.downcase }
24
+
25
+ raise ArgumentError, "not unique: #{filenames}" if filenames.uniq.length != @documents.length
26
+ end
27
+
28
+ def write!(temp_root = '', store = Stores::Null.new)
29
+ documents.flat_map { |d| d.write!(temp_root, store) }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'documents/text'
11
+ require_relative 'documents/zip'
12
+
13
+ module FileComposer
14
+ # Factory for building documents.
15
+ class Documents
16
+ acts_as_hashable_factory
17
+
18
+ register 'text', Documents::Text
19
+ register 'zip', Documents::Zip
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'result'
11
+ require_relative 'file_result'
12
+
13
+ module FileComposer
14
+ class Documents
15
+ # Parent class for all documents.
16
+ class Base
17
+ acts_as_hashable
18
+
19
+ attr_reader :filename
20
+
21
+ def initialize(filename:)
22
+ raise ArgumentError, 'filename is required' if filename.to_s.empty?
23
+
24
+ @filename = filename.to_s
25
+ end
26
+
27
+ private
28
+
29
+ def make_temp_filename(temp_root)
30
+ temp_filename = "#{SecureRandom.uuid}#{extension}"
31
+
32
+ temp_root.to_s.empty? ? temp_filename : File.join(temp_root, temp_filename)
33
+ end
34
+
35
+ def extension
36
+ File.extname(filename)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module FileComposer
11
+ class Documents
12
+ # A singular file result for a document.
13
+ class FileResult
14
+ attr_reader :logical_filename, :physical_filename
15
+
16
+ def initialize(logical_filename, physical_filename)
17
+ @logical_filename = logical_filename
18
+ @physical_filename = physical_filename
19
+
20
+ freeze
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module FileComposer
11
+ class Documents
12
+ # The production of a document.
13
+ class Result
14
+ attr_reader :file_results,
15
+ :time_in_seconds
16
+
17
+ def initialize(file_results, time_in_seconds)
18
+ @file_results = Array(file_results)
19
+ @time_in_seconds = time_in_seconds
20
+
21
+ freeze
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'base'
11
+
12
+ module FileComposer
13
+ class Documents
14
+ # Writes basic, static text file
15
+ class Text < Base
16
+ attr_reader :data
17
+
18
+ def initialize(filename:, data: '')
19
+ super(filename: filename)
20
+
21
+ @data = data
22
+ end
23
+
24
+ def write!(temp_root = '', store = Stores::Null.new)
25
+ temp_filename = make_temp_filename(temp_root)
26
+
27
+ time_in_seconds = Benchmark.measure do
28
+ # First, write out the temporary file
29
+ FileUtils.mkdir_p(File.dirname(temp_filename))
30
+ IO.write(temp_filename, data)
31
+ end.real
32
+
33
+ # Then copy the file to permanent store
34
+ physical_filename = store.move!(temp_filename)
35
+ file_result = FileResult.new(filename, physical_filename)
36
+
37
+ Result.new(file_result, time_in_seconds)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'base'
11
+
12
+ module FileComposer
13
+ class Documents
14
+ # Can compress documents together into a zip file.
15
+ class Zip < Base
16
+ attr_reader :blueprint
17
+
18
+ def initialize(filename:, blueprint: {})
19
+ super(filename: filename)
20
+
21
+ @blueprint = Blueprint.make(blueprint)
22
+ end
23
+
24
+ def write!(temp_root = '', store = Stores::Null.new)
25
+ results = blueprint.write!(temp_root)
26
+ total_time_in_seconds = results.sum(&:time_in_seconds)
27
+ physical_filename = zip!(temp_root, results)
28
+
29
+ cleanup(results)
30
+
31
+ final_filename = store.move!(physical_filename)
32
+ file_result = FileResult.new(filename, final_filename)
33
+
34
+ Result.new(file_result, total_time_in_seconds)
35
+ end
36
+
37
+ private
38
+
39
+ def zip!(temp_root, results)
40
+ make_temp_filename(temp_root).tap do |physical_filename|
41
+ ::Zip::File.open(physical_filename, ::Zip::File::CREATE) do |zipfile|
42
+ results.each do |result|
43
+ result.file_results.each do |file_result|
44
+ zipfile.add(file_result.logical_filename, file_result.physical_filename)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def cleanup(results)
52
+ results.each do |result|
53
+ result.file_results.each do |file_result|
54
+ FileUtils.rm(file_result.physical_filename, force: true)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require_relative 'stores/local'
11
+ require_relative 'stores/null'
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module FileComposer
11
+ module Stores
12
+ # File copier from local file system to the local file system.
13
+ class Local
14
+ attr_reader :date, :root
15
+
16
+ def initialize(date: Time.now.utc.to_date, root: '')
17
+ @date = date
18
+ @root = root.to_s
19
+
20
+ freeze
21
+ end
22
+
23
+ def move!(filename)
24
+ make_final_filename(filename).tap do |final_filename|
25
+ ensure_directory_exists(final_filename)
26
+ FileUtils.cp(filename, final_filename)
27
+ FileUtils.rm(filename, force: true)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def make_final_filename(filename)
34
+ parts = random_filename_parts(File.extname(filename))
35
+
36
+ File.join(*parts)
37
+ end
38
+
39
+ def random_filename_parts(extension)
40
+ [
41
+ date.year.to_s,
42
+ date.month.to_s,
43
+ date.day.to_s,
44
+ "#{SecureRandom.uuid}#{extension}"
45
+ ].tap do |parts|
46
+ parts.unshift(root) if root?
47
+ end
48
+ end
49
+
50
+ def root?
51
+ !root.empty?
52
+ end
53
+
54
+ def ensure_directory_exists(filename)
55
+ FileUtils.mkdir_p(File.dirname(filename))
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module FileComposer
11
+ module Stores
12
+ # Default store, does nothing but provide a stand-in when you do not actually
13
+ # want to transfer files.
14
+ class Null
15
+ def move!(local_filename)
16
+ local_filename
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2020-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ module FileComposer
11
+ VERSION = '1.0.0-alpha'
12
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file_composer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Ruggio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: acts_as_hashable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.88.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.88.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.18.5
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.18.5
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov-console
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.7.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.7.0
139
+ description: " This library provides a YAML-based configuration, called a Blueprint,
140
+ that allows you to specify text files and zip files and it will create them. It
141
+ is pluggable so other document types and storage mediums can be added.\n"
142
+ email:
143
+ - mruggio@bluemarblepayroll.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".editorconfig"
149
+ - ".gitignore"
150
+ - ".rubocop.yml"
151
+ - ".ruby-version"
152
+ - ".travis.yml"
153
+ - CHANGELOG.md
154
+ - CODE_OF_CONDUCT.md
155
+ - Gemfile
156
+ - Guardfile
157
+ - LICENSE
158
+ - README.md
159
+ - Rakefile
160
+ - bin/console
161
+ - exe/.gitkeep
162
+ - file_composer.gemspec
163
+ - lib/file_composer.rb
164
+ - lib/file_composer/blueprint.rb
165
+ - lib/file_composer/documents.rb
166
+ - lib/file_composer/documents/base.rb
167
+ - lib/file_composer/documents/file_result.rb
168
+ - lib/file_composer/documents/result.rb
169
+ - lib/file_composer/documents/text.rb
170
+ - lib/file_composer/documents/zip.rb
171
+ - lib/file_composer/stores.rb
172
+ - lib/file_composer/stores/local.rb
173
+ - lib/file_composer/stores/null.rb
174
+ - lib/file_composer/version.rb
175
+ homepage: https://github.com/bluemarblepayroll/file_composer
176
+ licenses:
177
+ - MIT
178
+ metadata:
179
+ bug_tracker_uri: https://github.com/bluemarblepayroll/file_composer/issues
180
+ changelog_uri: https://github.com/bluemarblepayroll/file_composer/blob/master/CHANGELOG.md
181
+ documentation_uri: https://www.rubydoc.info/gems/file_composer
182
+ homepage_uri: https://github.com/bluemarblepayroll/file_composer
183
+ source_code_uri: https://github.com/bluemarblepayroll/file_composer
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '2.5'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">"
196
+ - !ruby/object:Gem::Version
197
+ version: 1.3.1
198
+ requirements: []
199
+ rubygems_version: 3.0.3
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: High-level, pluggable and YAML-based API for creating files
203
+ test_files: []