Sha256: 6eb4ce564c8688634ad2330e9bc6b90e613dd64edec62253ab3a20f13d4ac335

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: false

module PGTrunk::Operations::Views
  # @abstract
  # @private
  # Base class for operations with views
  class Base < PGTrunk::Operation
    # All attributes that can be used by view-related commands
    attribute :check, :pg_trunk_symbol
    attribute :force, :pg_trunk_symbol
    attribute :replace_existing, :boolean
    attribute :sql_definition, :pg_trunk_multiline_text
    attribute :version, :integer, aliases: :revert_to_version

    # Load missed `sql_definition` from the external file
    after_initialize { self.sql_definition ||= read_snippet_from(:views) }

    # Ensure correctness of present values
    validates :check, inclusion: %i[local cascaded], allow_nil: true
    validates :force, inclusion: %i[cascade restrict], allow_nil: true

    # Use comparison by name from pg_trunk operations base class (default)
    # Support name as the only positional argument (default)

    ruby_snippet do |s|
      s.ruby_param(name.lean) if name.present?
      s.ruby_param(to: new_name.lean) if new_name.present?
      s.ruby_param(replace_existing: true) if replace_existing
      s.ruby_param(if_exists: true) if if_exists
      s.ruby_param(force: :cascade) if force == :cascade

      s.ruby_line(:version, version, from: from_version)
      s.ruby_line(:sql_definition, sql_definition, from: from_sql_definition)
      s.ruby_line(:check, check, from: from_check)
      s.ruby_line(:comment, comment, from: from_comment)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_trunk-0.2.0 lib/pg_trunk/operations/views/base.rb
pg_trunk-0.1.3 lib/pg_trunk/operations/views/base.rb
pg_trunk-0.1.2 lib/pg_trunk/operations/views/base.rb
pg_trunk-0.1.1 lib/pg_trunk/operations/views/base.rb
pg_trunk-0.1.0 lib/pg_trunk/operations/views/base.rb