Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
FilesToInstall now accepts absolute paths for files or directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
moonmaster9000 committed Dec 28, 2013
1 parent a1985e3 commit be739e1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/mine_prefs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
source_location = File.join(File.dirname(File.expand_path(__FILE__)), "..", "RubyMineXX")
target_location = ENV['TARGET_DIR'] || Dir[File.expand_path(File.join("~", "Library", "Preferences", "RubyMine*"))].last

files_to_install = Dir[File.join(source_location, "options", "**", "*")].map { |file| file.gsub %r{.*/(options.*)}, '\1' }
directories_to_install = ["keymaps", "codestyles", "templates"]
files = Dir[File.join(source_location, "options", "**", "*")]
directories = ["keymaps", "codestyles", "templates"]

files_to_install = MinePrefs::FilesToInstall.new(
target_location: target_location,
source_location: source_location,
files_or_directories_to_install: directories_to_install + files_to_install,
files_or_directories_to_install: directories + files,
)

feature = ARGV.first
Expand Down
6 changes: 4 additions & 2 deletions lib/mine_prefs/files_to_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def each(&block)
private
def installable_files
files_or_directories_to_install.map do |file_to_install|
file_to_install_relative_path_to_source = file_to_install.gsub(source_location, '')

InstallableFile.new(
source: File.expand_path(File.join(source_location, file_to_install)),
target: File.expand_path(File.join(target_location, file_to_install)),
source: File.expand_path(File.join(source_location, file_to_install_relative_path_to_source)),
target: File.expand_path(File.join(target_location, file_to_install_relative_path_to_source)),
)
end
end
Expand Down
37 changes: 28 additions & 9 deletions spec/lib/mine_prefs/files_to_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,35 @@

module MinePrefs
describe FilesToInstall do
describe "#each" do
it "returns the source and destination files for installation" do
installation_pair = FilesToInstall.new(
target_location: "/target",
source_location: "/source",
files_or_directories_to_install: ["/install_file"]
).first
subject(:file_to_install) do
FilesToInstall.new(
target_location: "/target",
source_location: "/source",
files_or_directories_to_install: [file]
).first
end

context "files or directories to install are relative to source" do
let(:file) { "install_file" }

it "calculates the target location of a file by combining the target path with the relative file path" do
file_to_install.target.should == "/target/install_file"
end

it "calculates the source location by combining the source path with the relative file path" do
file_to_install.source.should == "/source/install_file"
end
end

context "files or directories to install are absolute paths" do
let(:file) { "/source/install_file" }

it "calculates the target location of a file by combining the target path with the file path relative to the source" do
file_to_install.target.should == "/target/install_file"
end

installation_pair.target.should == "/target/install_file"
installation_pair.source.should == "/source/install_file"
it "calculates the source location by combining the source path with the file path relative to the source" do
file_to_install.source.should == "/source/install_file"
end
end
end
Expand Down

0 comments on commit be739e1

Please sign in to comment.