Method: Cog::Embeds#update

Defined in:
lib/cog/embeds.rb

#update(c, opt = {}) {|context| ... } ⇒ Boolean?

Returns true if the statement was expanded or updated, false if the statement was found, but not changed, nil if it could not be found.

Parameters:

  • c (EmbedContext)

    describes the context in which the embed statement was found

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :type (String) — default: 'cog'

    one of 'cog' or 'keep'

Yield Parameters:

  • context (EmbedContext)

    describes the context in which the embed statement was found

Yield Returns:

  • (String)

    the value to substitute into the embed expansion

Returns:

  • (Boolean, nil)

    true if the statement was expanded or updated, false if the statement was found, but not changed, nil if it could not be found.



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cog/embeds.rb', line 91

def update(c, opt={}, &block)
  type = opt[:type] || 'cog'
  Helpers::FileScanner.scan(c.path, statement(type, c.hook), :occurrence => c.actual_index) do |s|
    c.lineno = s.marked_line_number
    c.args = s.match[2].split if s.match[2]
    c.once = !s.match[3].nil?
    if s.match[4] == '{'
      update_body c, s, opt, &block
    else
      expand_body c, s, opt, &block
    end
  end
end