Class: Nero::BaseTag

Inherits:
Object
  • Object
show all
Includes:
Resolvable
Defined in:
lib/nero.rb

Direct Known Subclasses

EnvTag, PathRootTag

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resolvable

#deep_resolve, #gen_resolve_tryer, #resolve_nested!, #try_resolve

Instance Attribute Details

#coderObject (readonly)

Returns the value of attribute coder.

[View on GitHub]

77
78
79
# File 'lib/nero.rb', line 77

def coder
  @coder
end

#ctxObject (readonly)

Returns the value of attribute ctx.

[View on GitHub]

77
78
79
# File 'lib/nero.rb', line 77

def ctx
  @ctx
end

#optionsObject (readonly)

Returns the value of attribute options.

[View on GitHub]

77
78
79
# File 'lib/nero.rb', line 77

def options
  @options
end

Class Method Details

.[](**options) ⇒ Object

[View source] [View on GitHub]

79
80
81
# File 'lib/nero.rb', line 79

def self.[](**options)
  [self, options]
end

Instance Method Details

#argsObject

[View source] [View on GitHub]

105
106
107
108
109
110
111
112
113
114
# File 'lib/nero.rb', line 105

def args
  @args ||= begin
    resolve_nested!(coder, {})
    case coder.type
    when :map then Util.deep_symbolize_keys(coder.map)
    else
      Array(coder.public_send(coder.type))
    end
  end
end

#configObject

[View source] [View on GitHub]

116
117
118
# File 'lib/nero.rb', line 116

def config
  ctx.dig(:tags, tag_name)
end

#init(ctx:, options:) ⇒ Object

[View source] [View on GitHub]

88
89
90
91
# File 'lib/nero.rb', line 88

def init(ctx:, options:)
  init_ctx(ctx)
  init_options(**options)
end

#init_ctx(ctx) ⇒ Object

[View source] [View on GitHub]

93
94
95
# File 'lib/nero.rb', line 93

def init_ctx(ctx)
  @ctx = ctx
end

#init_options(**options) ⇒ Object

[View source] [View on GitHub]

97
98
99
# File 'lib/nero.rb', line 97

def init_options(**options)
  @options = options
end

#init_with(coder) ⇒ Object

used by YAML

[View source] [View on GitHub]

84
85
86
# File 'lib/nero.rb', line 84

def init_with(coder)
  @coder = coder
end

#resolveObject

[View source] [View on GitHub]

120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/nero.rb', line 120

def resolve(**)
  if (block = config[:block])
    if block.parameters.map(&:last).include?(:coder)
      # legacy
      block.call(coder, ctx)
    else
      block.call(self)
    end
  else
    args
  end
end

#tag_nameObject

[View source] [View on GitHub]

101
102
103
# File 'lib/nero.rb', line 101

def tag_name
  coder.tag[1..]
end