class Cog::EmbedContext

Describes the environment of an embed statement including the file in which it was found, the line number, the language, an more.

Attributes

body[R]

@return [String] for expanded embed statements, the body of text which occurs between the curly braces @example

// cog: my-hook {
this is
the
body
// cog: }
count[R]

@return [Fixnum] if multiple embeds with the same {#hook} occurred more than once in the same file, this value indicates the total number of occurrences

hook[R]

@return [String] hook name used in the embed statement @example

// cog: this-is-the-hook-name
index[R]

@return [Fixnum] if multiple embeds with the same {#hook} occurred more than once in the same file, this value indicates to which occurrence this context belongs. 0 for the first, 1 for the second, and so on…

keep_body[RW]

@api developer

lineno[R]

@return [Fixnum] line number at which the embed statement was found, with 1 being the first line in the file

path[R]

@return [String] full file system path to the file

Public Class Methods

new(hook, path, count) click to toggle source

@api developer @param hook [String] hook name used in the embed statement @param path [String] path to the file in which the cog directive was found @param count [Fixnum] total occurrences in file

# File lib/cog/embed_context.rb, line 36
def initialize(hook, path, count)
  @hook = hook.to_s
  @path = path.to_s
  @count = count
  @eaten = 0
  @index = 0
end

Public Instance Methods

actual_index() click to toggle source

@api developer @return [Fixnum] takes into account the number of once statements that have been eaten

# File lib/cog/embed_context.rb, line 119
def actual_index
  @index - @eaten
end
args() click to toggle source

@return [Array<String>] arguments provided with the embed statement @example

// cog: my-hook (these are the args)
# File lib/cog/embed_context.rb, line 47
def args
  @args
end
args=(value) click to toggle source

@api developer @param value [Array<String>] arguments used with the directive

# File lib/cog/embed_context.rb, line 101
def args=(value)
  @args = value
end
body=(value) click to toggle source

@api developer @param value [String, nil] set the body to this value

# File lib/cog/embed_context.rb, line 83
def body=(value)
  @body = value
end
eaten=(value) click to toggle source

@api developer @param value [Fixnum] the number of once statements before this one that were eaten. Used to adjust the actual_index so that the file_scanner looks for the right statement

# File lib/cog/embed_context.rb, line 113
def eaten=(value)
  @eaten = value
end
extension() click to toggle source

@return [String] the filename extension (without the period)

# File lib/cog/embed_context.rb, line 52
def extension
  @ext ||= File.extname(filename).slice(1..-1)
end
filename() click to toggle source

@return [String] basename of the file in which the embed statement was found

# File lib/cog/embed_context.rb, line 57
def filename
  @filename ||= File.basename @path
end
first?() click to toggle source

@return [Boolean] whether or not this was the first occurrence of the embed {#hook} in the file

# File lib/cog/embed_context.rb, line 62
def first?
  @index == 0
end
index=(index) click to toggle source

@api developer @param index [Fixnum] occurrence in file, 0 for first

# File lib/cog/embed_context.rb, line 107
def index=(index)
  @index = index
end
last?() click to toggle source

@return [Boolean] whether or not this was the last occurrence of the embed {#hook} in the file

# File lib/cog/embed_context.rb, line 67
def last?
  @index == @count - 1
end
lineno=(value) click to toggle source

@api developer @param value [Fixnum] set the line number

# File lib/cog/embed_context.rb, line 89
def lineno=(value)
  @lineno = value
end
once=(value) click to toggle source

@api developer @param value [Boolean] was the once switch used?

# File lib/cog/embed_context.rb, line 95
def once=(value)
  @once = !!value
end
once?() click to toggle source

@return [Boolean] was the 'once' switch used? Embed statements using this switch will be removed after the statement is expanded @example

// cog: my-hook once
# File lib/cog/embed_context.rb, line 74
def once?
  @once
end
to_statement(type='cog') click to toggle source

@api developer @return [String]

# File lib/cog/embed_context.rb, line 125
def to_statement(type='cog')
  x = "#{type}: #{hook}"
  x += "(#{args.join ' '})" if args
  x += " once" if once?
  x
end