Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pass strategy for binary files #158

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/terraspace/compiler/strategy/mod.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "open3"

module Terraspace::Compiler::Strategy
class Mod < AbstractBase
def run
Expand All @@ -9,9 +11,15 @@ def run
def strategy_class(path)
ext = File.extname(path).sub('.','')
return Mod::Pass if ext.empty? # infinite loop without this
return Mod::Pass if Terraspace.pass_file?(path)
return Mod::Pass if Terraspace.pass_file?(path) or !text_file?(path)
# Fallback to Mod::Tf for all other files. ERB useful for terraform.tfvars
"Terraspace::Compiler::Strategy::Mod::#{ext.camelize}".constantize rescue Mod::Tf
end

# Thanks: https://stackoverflow.com/questions/2355866/ruby-how-to-determine-if-file-being-read-is-binary-or-text
def text_file?(filename)
file_type, status = Open3.capture2e("file", filename)
status.success? && file_type.include?("text")
end
end
end