Class: PgQuery::Node
- Inherits:
-
Object
- Object
- PgQuery::Node
- Defined in:
- lib/pg_query/node.rb
Overview
Patch the auto-generated generic node type with additional convenience functions
Class Method Summary collapse
-
.from(node_field_val) ⇒ Object
Make it easier to initialize nodes from a given node child object.
- .from_integer(ival) ⇒ Object
-
.from_string(str) ⇒ Object
Make it easier to initialize value nodes.
Instance Method Summary collapse
Class Method Details
.from(node_field_val) ⇒ Object
Make it easier to initialize nodes from a given node child object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pg_query/node.rb', line 9 def self.from(node_field_val) # This needs to match libpg_query naming for the Node message field names # (see "underscore" method in libpg_query's scripts/generate_protobuf_and_funcs.rb) node_field_name = node_field_val.class.name.split('::').last node_field_name.gsub!(/^([A-Z\d])([A-Z][a-z])/, '\1__\2') node_field_name.gsub!(/([A-Z\d]+[a-z]+)([A-Z][a-z])/, '\1_\2') node_field_name.gsub!(/([a-z\d])([A-Z])/, '\1_\2') node_field_name.tr!('-', '_') node_field_name.downcase! PgQuery::Node.new(node_field_name => node_field_val) end |
Instance Method Details
#inspect ⇒ Object
4 5 6 |
# File 'lib/pg_query/node.rb', line 4 def inspect node ? format('<PgQuery::Node: %s: %s>', node, public_send(node).inspect) : '<PgQuery::Node>' end |