Created
September 21, 2014 00:55
-
-
Save bfitch/39d6f60377ed0122a7f5 to your computer and use it in GitHub Desktop.
open related spec file in vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! OpenSpecFile() | |
ruby <<EOF | |
class FileWrapper | |
def initialize(path) | |
@path = path | |
end | |
def absolute_path | |
File.expand_path(@path) | |
end | |
def name | |
name = File.basename(@path, extension) | |
if name.include? '.js' | |
name.split('.').first | |
else | |
name | |
end | |
end | |
def extension | |
File.extname(@path) | |
end | |
def ==(object) | |
comparison_string == object.comparison_string | |
end | |
alias_method :eql?, :== | |
def comparison_string | |
common_path.gsub('_', '').gsub('.','').downcase | |
end | |
private | |
def common_path | |
common_directories + filename + extension | |
end | |
def common_directories | |
path = (File.dirname(absolute_path).clone.split('/') - Dir.pwd.split('/') - blacklisted_directories) | |
path.join('/') | |
end | |
def blacklisted_directories | |
["app", "assets", "spec", "konacha", "javascripts", "coffee"] | |
end | |
def filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment