Skip to content

Commit

Permalink
fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Jun 4, 2017
1 parent c3e4314 commit 90ddfa4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
13 changes: 7 additions & 6 deletions lib/react_on_rails/assets_precompile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ReactOnRails
class AssetsPrecompile
class SymlinkTargetDoesNotExistException < StandardError;
class SymlinkTargetDoesNotExistException < StandardError
end

# Used by the rake task
Expand All @@ -19,8 +19,9 @@ def initialize(assets_path: nil,
@assets_path = ReactOnRails::Utils.truthy_presence(assets_path) || default_asset_path
@symlink_non_digested_assets_regex =
ReactOnRails::Utils.truthy_presence(symlink_non_digested_assets_regex) ||
ReactOnRails.configuration.symlink_non_digested_assets_regex
@generated_assets_dir = ReactOnRails::Utils.truthy_presence(generated_assets_dir) || ReactOnRails.configuration.generated_assets_dir
ReactOnRails.configuration.symlink_non_digested_assets_regex
@generated_assets_dir = ReactOnRails::Utils.truthy_presence(generated_assets_dir) ||
ReactOnRails.configuration.generated_assets_dir
end

# target and symlink are relative to the assets directory
Expand Down Expand Up @@ -64,8 +65,8 @@ def symlink_non_digested_assets
# file back to the original digested name, and make a similar symlink for the gz version.
return unless @symlink_non_digested_assets_regex
manifest_glob = Dir.glob(@assets_path.join(".sprockets-manifest-*.json")) +
Dir.glob(@assets_path.join("manifest-*.json")) +
Dir.glob(@assets_path.join("manifest.yml"))
Dir.glob(@assets_path.join("manifest-*.json")) +
Dir.glob(@assets_path.join("manifest.yml"))
if manifest_glob.empty?
puts "Warning: React On Rails: expected to find .sprockets-manifest-*.json, manifest-*.json "\
"or manifest.yml at #{@assets_path}, but found none. Canceling symlinking tasks."
Expand Down Expand Up @@ -103,7 +104,7 @@ def delete_broken_symlinks
target = File.readlink(filename)
rescue
puts "React on Rails: Warning: your platform doesn't support File::readlink method." /
"Skipping broken link check."
"Skipping broken link check."
break
end
path = Pathname.new(File.dirname(filename))
Expand Down
3 changes: 2 additions & 1 deletion lib/react_on_rails/locales_to_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def locale_files
Dir["#{i18n_yml_dir}/**/*.yml"]
else
ReactOnRails::Utils.truthy_presence(
Rails.application && Rails.application.config.i18n.load_path).presence
Rails.application && Rails.application.config.i18n.load_path
).presence
end
end
end
Expand Down
19 changes: 9 additions & 10 deletions lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

module ReactOnRails
module Utils

# https://forum.shakacode.com/t/yak-of-the-week-ruby-2-4-pathname-empty-changed-to-look-at-file-size/901
# return object if truthy, else return nil
def self.truthy_presence(obj)
Expand All @@ -30,15 +29,15 @@ def self.server_rendering_is_enabled?
def self.invoke_and_exit_if_failed(cmd, failure_message)
stdout, stderr, status = Open3.capture3(cmd)
unless status.success?
msg = <<-MSG.strip_heredoc
#{'Z' * 80}
React on Rails FATAL ERROR!
#{failure_message}
cmd: #{cmd}"
stdout: #{stdout.strip}
stderr: #{stderr.strip}
exitstatus: #{status.exitstatus}
#{'Z' * 80}
msg = <<~MSG.strip_heredoc
#{'Z' * 80}
React on Rails FATAL ERROR!
#{failure_message}
cmd: #{cmd}"
stdout: #{stdout.strip}
stderr: #{stderr.strip}
exitstatus: #{status.exitstatus}
#{'Z' * 80}
MSG
puts Rainbow(msg).red
exit(1)
Expand Down
7 changes: 4 additions & 3 deletions spec/react_on_rails/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ module ReactOnRails

context "With pathname pointing to empty file" do
let(:empty_dir) { Pathname.new(Dir.mktmpdir) }
subject(:empty_file) { File.basename(Tempfile.new("tempfile",
empty_dir)) }
subject(:empty_file) do
File.basename(Tempfile.new("tempfile",
empty_dir))
end
it "returns Pathname object" do
expect(Utils.truthy_presence(empty_file)).to eq(empty_file)
end
Expand All @@ -53,7 +55,6 @@ module ReactOnRails
describe ".rails_version_less_than" do
subject { Utils.rails_version_less_than("4") }


describe ".rails_version_less_than" do
before(:each) { Utils.instance_variable_set :@rails_version_less_than, nil }

Expand Down

0 comments on commit 90ddfa4

Please sign in to comment.