Class: Gitnesse::Feature
- Inherits:
-
Object
- Object
- Gitnesse::Feature
- Defined in:
- lib/gitnesse/feature.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
-
#index_page ⇒ Object
Public: Generates the path to the index page the feature would appear on.
-
#initialize(filename) ⇒ Feature
constructor
A new instance of Feature.
-
#read ⇒ Object
Public: Reads the feature’s contents.
-
#relative_link ⇒ Object
Public: Generates relative link for wiki index pages.
-
#wiki_filename ⇒ Object
Public: Converts feature filename into the filename used on the remote git-based wiki.
-
#write(content) ⇒ Object
Public: Writes updated content to the feature, or creates a new feature if it doesn’t exist.
Constructor Details
#initialize(filename) ⇒ Feature
Returns a new instance of Feature.
5 6 7 8 9 10 11 12 13 |
# File 'lib/gitnesse/feature.rb', line 5 def initialize(filename) if filename =~ /^\.\/features\/(.+)/ @filename = filename.scan(/^\.?\/?features\/(.+)/).flatten.first else @filename = filename end @config = Gitnesse::Config.instance end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
3 4 5 |
# File 'lib/gitnesse/feature.rb', line 3 def filename @filename end |
Instance Method Details
#index_page ⇒ Object
Public: Generates the path to the index page the feature would appear on. Used to group Features for creating index pages.
Returns a string indicating the index page.
51 52 53 54 |
# File 'lib/gitnesse/feature.rb', line 51 def index_page p = wiki_filename.scan(/^(features\ \>\ .+) >/).flatten[0] || 'features' p + ".md" end |
#read ⇒ Object
Public: Reads the feature’s contents. Caches result so only reads from FS first time it’s called.
Returns a string
27 28 29 |
# File 'lib/gitnesse/feature.rb', line 27 def read @content ||= File.read("#{@config.features_dir}/#{@filename}") end |
#relative_link ⇒ Object
Public: Generates relative link for wiki index pages.
Returns a string containing the relative link as markdown
59 60 61 |
# File 'lib/gitnesse/feature.rb', line 59 def relative_link "[[#{wiki_filename.gsub('.md', '')}]]" end |
#wiki_filename ⇒ Object
Public: Converts feature filename into the filename used on the remote git-based wiki
Returns the converted filename
19 20 21 |
# File 'lib/gitnesse/feature.rb', line 19 def wiki_filename "features/#{@filename}.md".gsub('/', ' > ') end |
#write(content) ⇒ Object
Public: Writes updated content to the feature, or creates a new feature if it doesn’t exist.
content - The new/updated content to write to the file
Returns the passed content
37 38 39 40 41 42 43 44 45 |
# File 'lib/gitnesse/feature.rb', line 37 def write(content) File.open("#{@config.features_dir}/#{@filename}", 'w') do |f| f.write content end @content = nil content end |