class Codestrap::Patch::File
Inherited and patched File
class
Used as an alternative to monkey patching
Public Instance Methods
has_mode_line?()
click to toggle source
Has mode line @return [true|false]
# File lib/codestrap/patch.rb, line 117 def has_mode_line? !!self.mode_line end
mode_line(limit = 10)
click to toggle source
Set and get mode line status
@param [Integer] limit
Number of lines to scan from the top
@return [truenil]
# File lib/codestrap/patch.rb, line 80 def mode_line(limit = 10) @mode_line ||= begin # Check if file read curpos = self.pos self.pos = 0 lines = self.readlines()[0 .. (limit - 1)] lines.each do |line| line =~ /(?:^|\b)(strap|stub):(erb|\S+?)(?:\b|$)/ if $1 @mode_line = line @template = $2.to_sym if $2 @template = :erb if $2.length == 0 self.options end break end self.pos = curpos @mode_line end end
options()
click to toggle source
Parse mode line options
# File lib/codestrap/patch.rb, line 103 def options @options ||= begin @mode_line.scan(/(\S+)\s*=\s*(\S+)/).each do |arr| key = arr[0] value = arr[1] @options[key] = value end @options end end
template()
click to toggle source
@return [Symbol|nil]
Template types :erb
# File lib/codestrap/patch.rb, line 67 def template @template || begin self.mode_line @template end end