Class: Jeny::CodeBlock
- Inherits:
-
Object
- Object
- Jeny::CodeBlock
- Defined in:
- lib/jeny/code_block.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source, path, line, asset) ⇒ CodeBlock
constructor
A new instance of CodeBlock.
- #instantiate(data) ⇒ Object
- #line_index ⇒ Object
Constructor Details
#initialize(source, path, line, asset) ⇒ CodeBlock
Returns a new instance of CodeBlock.
4 5 6 7 8 9 |
# File 'lib/jeny/code_block.rb', line 4 def initialize(source, path, line, asset) @source = source @path = path @line = line @asset = asset end |
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
10 11 12 |
# File 'lib/jeny/code_block.rb', line 10 def asset @asset end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
10 11 12 |
# File 'lib/jeny/code_block.rb', line 10 def line @line end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/jeny/code_block.rb', line 10 def path @path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/jeny/code_block.rb', line 10 def source @source end |
Instance Method Details
#instantiate(data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jeny/code_block.rb', line 16 def instantiate(data) case d = data[asset] when NilClass when Hash Dialect.render(source, d) rescue source when Array d.map{|item| instantiate(asset => item) }.join("\n") else raise Error, "Unexpected block asset: `#{asset} = #{d}`" end end |
#line_index ⇒ Object
12 13 14 |
# File 'lib/jeny/code_block.rb', line 12 def line_index line - 1 end |