Class: Lanes::API::CoffeeScriptProcessor::CoffeeClass
- Inherits:
-
Object
- Object
- Lanes::API::CoffeeScriptProcessor::CoffeeClass
- Defined in:
- lib/lanes/api/coffeescript_processor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#extends ⇒ Object
readonly
Returns the value of attribute extends.
-
#file_contents ⇒ Object
readonly
Returns the value of attribute file_contents.
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #ensure_property(property_name, definition) ⇒ Object
-
#initialize(name, extends, file_contents) ⇒ CoffeeClass
constructor
A new instance of CoffeeClass.
- #save ⇒ Object
- #setup_properties ⇒ Object
Constructor Details
#initialize(name, extends, file_contents) ⇒ CoffeeClass
Returns a new instance of CoffeeClass.
18 19 20 21 22 23 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 18 def initialize(name, extends, file_contents) @name=name; @extends=extends; @file_contents=file_contents file_contents.gsub!(/class\s+#{name}\s+.*?\n/,"class #{name}\n") @contents = @file_contents[/(class #{name}\n.*?)(\n\w|\Z)/m,1] @indent = @contents[/\n(\s+)(\w+):/,1] || ' ' end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
17 18 19 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 17 def contents @contents end |
#extends ⇒ Object (readonly)
Returns the value of attribute extends.
17 18 19 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 17 def extends @extends end |
#file_contents ⇒ Object (readonly)
Returns the value of attribute file_contents.
17 18 19 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 17 def file_contents @file_contents end |
#indent ⇒ Object (readonly)
Returns the value of attribute indent.
17 18 19 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 17 def indent @indent end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 17 def name @name end |
Instance Method Details
#ensure_property(property_name, definition) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 25 def ensure_property(property_name, definition) if contents !~ /^\s+#{property_name}\s*:/ # figure out how much to indent, sigh. file_contents.gsub!(/class #{name}\n/, "\\0#{indent}#{property_name}: #{definition}\n") end end |
#save ⇒ Object
38 39 40 41 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 38 def save file_contents.gsub!(/^(\s*class #{name}\n.*?)(\n\w|\Z)/m, "\\1\n#{extends}.extend(#{name})\n\\2") end |
#setup_properties ⇒ Object
33 34 35 36 |
# File 'lib/lanes/api/coffeescript_processor.rb', line 33 def setup_properties ensure_property("constructor", "-> super") ensure_property("FILE", "FILE") end |