0.0
No commit activity in last 3 years
No release in over 3 years
Class to parse gitattributes files.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 5.9.1
= 3.1.5
 Project Readme

gitattributes

Build Status

Classes to parse .gitattributes files.

A simple example of it's usage:

Read an existing .gitattributes

Read an existing file that looks like

README.md text eol=lf
*.jpg binary

With code that looks like

require 'reality/gitattributes'

attributes = Reality::Git::Attributes.parse('/home/user/myrepo')
attributes.attributes('README.md') # => { "text" => true, "eol" => "lf }
attributes.attributes('*.jpg') # => { "binary" => true }

Write .gitattributes

require 'reality/gitattributes'

attributes = Reality::Git::Attributes.new('/home/user/myrepo')
attributes.dos_text_rule('*.cmd')
attributes.dos_text_rule('*.rdl', :eofnl => false)
attributes.unix_text_rule('*.sh')
attributes.text_rule('*.md')
attributes.binary_rule('*.jpg')

attributes.write_to('/home/user/myrepo/.gitattributes')

produces a file that looks like

*.cmd text eol=crlf
*.rdl text eol=crlf -eofnl
*.sh text eol=lf
*.md text
*.jpg binary

You could also pass :prefix and :normalize options to write_to method like

attributes.write_to('/home/user/myrepo/.gitattributes', :normalize => true, :prefix => '# DO NOT EDIT: File is auto-generated')

to produce a file that looks like:

# DO NOT EDIT: File is auto-generated
*.cmd text eol=crlf
*.md text
*.rdl text eol=crlf -eofnl
*.sh text eol=lf