Class: Lookbook::ParamTag

Inherits:
YardTag
  • Object
show all
Defined in:
lib/lookbook/tags/param_tag.rb

Constant Summary collapse

VALUE_TYPE_MATCHER =
/^(\[\s?([A-Z]{1}\w+)\s?\])/
DESCRIPTION_MATCHER =
/(?<=\s|^)"(.*?[^\\])"(?:\s|$)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from YardTag

#options, supports_options, supports_options?, #text, #to_s

Constructor Details

#initialize(text) ⇒ ParamTag

Returns a new instance of ParamTag.



10
11
12
13
14
# File 'lib/lookbook/tags/param_tag.rb', line 10

def initialize(text)
  @name, text_without_name = extract_name(text)
  @tag_args = parse_tag_body(text_without_name)
  super("param", tag_args[:rest], nil, @name)
end

Instance Attribute Details

#tag_argsObject (readonly)



8
9
10
# File 'lib/lookbook/tags/param_tag.rb', line 8

def tag_args
  @tag_args
end

Instance Method Details

#descriptionObject



20
21
22
# File 'lib/lookbook/tags/param_tag.rb', line 20

def description
  tag_args[:description]
end

#inputObject



16
17
18
# File 'lib/lookbook/tags/param_tag.rb', line 16

def input
  tag_args[:input]&.downcase&.tr("_", "-")
end

#value_defaultObject



28
29
30
31
32
33
34
35
# File 'lib/lookbook/tags/param_tag.rb', line 28

def value_default
  default_value_parts = object.parameters.find { |parts| parts[0].chomp(":") == name }
  if default_value_parts
    host_class_instance.instance_eval(default_value_parts[1])
  else
    raise ParserError.new "Unknown method parameter '#{name}'"
  end
end

#value_typeObject



24
25
26
# File 'lib/lookbook/tags/param_tag.rb', line 24

def value_type
  tag_args[:value_type]&.downcase
end