Class: Codestrap::Patch::File
- Inherits:
-
File
- Object
- File
- Codestrap::Patch::File
- Defined in:
- lib/codestrap/patch.rb
Overview
Inherited and patched File class
Used as an alternative to monkey patching
Instance Method Summary collapse
-
#has_mode_line? ⇒ true|false
Has mode line.
-
#mode_line(limit = 10) ⇒ true\nil
Set and get mode line status.
-
#options ⇒ Object
Parse mode line options.
-
#template ⇒ Symbol|nil
Template types :erb.
Instance Method Details
#has_mode_line? ⇒ true|false
Has mode line
117 118 119 |
# File 'lib/codestrap/patch.rb', line 117 def has_mode_line? !!self.mode_line end |
#mode_line(limit = 10) ⇒ true\nil
Set and get mode line status
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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. end break end self.pos = curpos @mode_line end end |
#options ⇒ Object
Parse mode line options
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/codestrap/patch.rb', line 103 def ||= begin @mode_line.scan(/(\S+)\s*=\s*(\S+)/).each do |arr| key = arr[0] value = arr[1] [key] = value end end end |
#template ⇒ Symbol|nil
Returns Template types :erb.
67 68 69 70 71 72 |
# File 'lib/codestrap/patch.rb', line 67 def template @template || begin self.mode_line @template end end |