class RailsOpenapiGen::AstNodes::PartialNode
Represents a partial node in Jbuilder template (json.partial!)
def accept(visitor)
-
(Object)
- Result from visitor
Parameters:
-
visitor
(Object
) -- Visitor object
def accept(visitor) visitor.visit_partial(self) end
def add_parsed_properties(properties)
-
(Array
- Added properties)
Parameters:
-
properties
(Array
) -- Properties from parsed partial
def add_parsed_properties(properties) properties.each { |prop| add_child(prop) } properties end
def description
-
(String, nil)
- Partial description
def description @comment_data.description end
def has_locals?
-
(Boolean)
- True if partial has local variables
def has_locals? !@local_variables.empty? end
def initialize(
def initialize( partial_path:, property_name: nil, comment_data: nil, is_conditional: false, local_variables: {}, parent: nil, metadata: {} ) super(parent: parent, metadata: metadata) @partial_path = partial_path @property_name = property_name @comment_data = comment_data || CommentData.new @is_conditional = is_conditional @local_variables = local_variables end
def local_names
-
(Array
- Local variable names)
def local_names @local_variables.keys end
def local_value(name)
-
(Object)
- Local variable value
Parameters:
-
name
(String
) -- Local variable name
def local_value(name) @local_variables[name] end
def optional?
-
(Boolean)
- True if partial is optional
def optional? !required? end
def properties
-
(Array
- Properties from partial)
def properties @children end
def required?
-
(Boolean)
- True if partial is required
def required? @comment_data.required? && !@is_conditional end
def resolve_path(base_path = nil)
-
(String)
- Resolved partial path
Parameters:
-
base_path
(String
) -- Base path for resolution
def resolve_path(base_path = nil) return @partial_path if @partial_path.start_with?('/') if base_path File.join(File.dirname(base_path), "#{@partial_path}.json.jbuilder") else "#{@partial_path}.json.jbuilder" end end
def to_h
-
(Hash)
- Hash representation
def to_h super.merge( partial_path: @partial_path, property_name: @property_name, comment_data: @comment_data&.to_h, is_conditional: @is_conditional, required: required?, description: description, local_variables: @local_variables, properties: properties.map { |prop| prop.respond_to?(:to_h) ? prop.to_h : prop } ).compact end