Module: PGTrunk::Operation::RubyHelpers
- Extended by:
- ActiveSupport::Concern
- Included in:
- PGTrunk::Operation
- Defined in:
- lib/pg_trunk/core/operation/ruby_helpers.rb
Overview
Helpers to build ruby snippet from the operation definition
Instance Method Summary collapse
- #dump(stream) ⇒ Object
-
#to_a ⇒ Object
List of attributes assigned that are assigned via Ruby method parameters.
- #to_opts ⇒ Object
-
#to_ruby ⇒ String
Ruby snippet to dump the creator.
Instance Method Details
#dump(stream) ⇒ Object
95 96 97 |
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 95 def dump(stream) to_ruby&.rstrip&.lines&.each { |line| stream.print(line.indent(2)) } end |
#to_a ⇒ Object
List of attributes assigned that are assigned via Ruby method parameters.
We can use it to announce the operation to $stdout
like create_foreign_key("users", "roles")
.
86 87 88 |
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 86 def to_a to_h.values_at(*self.class.ruby_params) end |
#to_opts ⇒ Object
90 91 92 |
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 90 def to_opts to_h.except(*self.class.ruby_params) end |
#to_ruby ⇒ String
Ruby snippet to dump the creator
75 76 77 78 79 |
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 75 def to_ruby builder = RubyBuilder.new(self.class.ruby_name) instance_exec(builder, &self.class.ruby_snippet) builder.build.rstrip end |