Class: Lilac::Directives::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/directives/value.rb

Overview

The right-hand side of a directive that takes a reactive value. Two kinds exist, both single-identifier (no dot / no path / no expression):

- `@ivar`     — a host Signal/Computed. Resolves via
              `Evaluator#lookup_ivar` and feeds into
              `bind ref, prop: signal` directly.
- bare ident  — a field of the current iteration item.
              `Evaluator#read` reads `item[name]` (Hash key
              first, then String fallback, then public_send).
              Only meaningful inside a `data-each` body;
              value-binding dispatch silent-skips when
              `item.nil?` (= scanning the host root).

Duplicate pair (build-time / runtime). See decisions §17.

Value.parse returns Ivar, BareIdent, or nil for invalid input — callers raise their own error with directive context. Match precedence: @ivar first (unambiguous prefix), then bare ident (everything else that looks like a Ruby identifier).

Defined Under Namespace

Classes: BareIdent, Ivar

Constant Summary collapse

IVAR =

Anchors use ^/$ not \A/\z — see Grammar for the mruby-regexp-compat compatibility note.

/^@[a-zA-Z_]\w*\??$/
BARE_IDENT =
/^[a-zA-Z_]\w*\??$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Value

Returns a new instance of Value.



40
41
42
# File 'lib/lilac/directives/value.rb', line 40

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



38
39
40
# File 'lib/lilac/directives/value.rb', line 38

def raw
  @raw
end

Class Method Details

.parse(raw) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/lilac/directives/value.rb', line 29

def self.parse(raw)
  s = raw.to_s.strip
  if IVAR.match?(s)
    Ivar.new(s)
  elsif BARE_IDENT.match?(s)
    BareIdent.new(s)
  end
end

Instance Method Details

#bare_ident?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/lilac/directives/value.rb', line 56

def bare_ident?
  false
end

#inspectObject



48
49
50
# File 'lib/lilac/directives/value.rb', line 48

def inspect
  @raw.inspect
end

#ivar?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/lilac/directives/value.rb', line 52

def ivar?
  false
end

#to_sObject



44
45
46
# File 'lib/lilac/directives/value.rb', line 44

def to_s
  @raw
end