Class: RailsOpenapiGen::AstNodes::PartialNode
- Defined in:
- lib/rails-openapi-gen/ast_nodes/partial_node.rb
Overview
Represents a partial node in Jbuilder template (json.partial!)
Instance Attribute Summary collapse
-
#comment_data ⇒ Object
readonly
Returns the value of attribute comment_data.
-
#is_conditional ⇒ Object
readonly
Returns the value of attribute is_conditional.
-
#local_variables ⇒ Object
readonly
Returns the value of attribute local_variables.
-
#partial_path ⇒ Object
readonly
Returns the value of attribute partial_path.
-
#property_name ⇒ Object
readonly
Returns the value of attribute property_name.
Attributes inherited from BaseNode
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Accept visitor for visitor pattern.
-
#add_parsed_properties(properties) ⇒ Array<BaseNode>
Add parsed properties from the partial.
-
#description ⇒ String?
Get the description for this partial.
-
#has_locals? ⇒ Boolean
Check if partial has local variables.
-
#initialize(partial_path:, property_name: nil, comment_data: nil, is_conditional: false, local_variables: {}, parent: nil, metadata: {}) ⇒ PartialNode
constructor
A new instance of PartialNode.
-
#local_names ⇒ Array<String>
Get local variable names.
-
#local_value(name) ⇒ Object
Get value for a local variable.
-
#optional? ⇒ Boolean
Check if this partial is optional in OpenAPI schema.
-
#properties ⇒ Array<BaseNode>
Get all properties from the parsed partial.
-
#required? ⇒ Boolean
Check if this partial is required in OpenAPI schema.
-
#resolve_path(base_path = nil) ⇒ String
Resolve the absolute path of the partial.
-
#to_h ⇒ Hash
Convert to hash representation.
Methods inherited from BaseNode
#add_child, #debug_line, #descendants, #leaf?, #pretty_print, #remove_child, #root, #root?, #summary_attributes
Constructor Details
#initialize(partial_path:, property_name: nil, comment_data: nil, is_conditional: false, local_variables: {}, parent: nil, metadata: {}) ⇒ PartialNode
Returns a new instance of PartialNode.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 8 def initialize( partial_path:, property_name: nil, comment_data: nil, is_conditional: false, local_variables: {}, parent: nil, metadata: {} ) super(parent: parent, metadata: ) @partial_path = partial_path @property_name = property_name @comment_data = comment_data || CommentData.new @is_conditional = is_conditional @local_variables = local_variables end |
Instance Attribute Details
#comment_data ⇒ Object (readonly)
Returns the value of attribute comment_data.
6 7 8 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 6 def comment_data @comment_data end |
#is_conditional ⇒ Object (readonly)
Returns the value of attribute is_conditional.
6 7 8 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 6 def is_conditional @is_conditional end |
#local_variables ⇒ Object (readonly)
Returns the value of attribute local_variables.
6 7 8 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 6 def local_variables @local_variables end |
#partial_path ⇒ Object (readonly)
Returns the value of attribute partial_path.
6 7 8 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 6 def partial_path @partial_path end |
#property_name ⇒ Object (readonly)
Returns the value of attribute property_name.
6 7 8 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 6 def property_name @property_name end |
Instance Method Details
#accept(visitor) ⇒ Object
Accept visitor for visitor pattern
107 108 109 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 107 def accept(visitor) visitor.visit_partial(self) end |
#add_parsed_properties(properties) ⇒ Array<BaseNode>
Add parsed properties from the partial
78 79 80 81 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 78 def add_parsed_properties(properties) properties.each { |prop| add_child(prop) } properties end |
#description ⇒ String?
Get the description for this partial
52 53 54 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 52 def description @comment_data.description end |
#has_locals? ⇒ Boolean
Check if partial has local variables
58 59 60 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 58 def has_locals? !@local_variables.empty? end |
#local_names ⇒ Array<String>
Get local variable names
64 65 66 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 64 def local_names @local_variables.keys end |
#local_value(name) ⇒ Object
Get value for a local variable
71 72 73 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 71 def local_value(name) @local_variables[name] end |
#optional? ⇒ Boolean
Check if this partial is optional in OpenAPI schema
46 47 48 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 46 def optional? !required? end |
#properties ⇒ Array<BaseNode>
Get all properties from the parsed partial
85 86 87 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 85 def properties @children end |
#required? ⇒ Boolean
Check if this partial is required in OpenAPI schema
40 41 42 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 40 def required? @comment_data.required? && !@is_conditional end |
#resolve_path(base_path = nil) ⇒ String
Resolve the absolute path of the partial
28 29 30 31 32 33 34 35 36 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 28 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 |
#to_h ⇒ Hash
Convert to hash representation
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rails-openapi-gen/ast_nodes/partial_node.rb', line 91 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 |