Sha256: d76c84ed3fbbf4beb10869ffe57ea9bc4ece90253991a41f108c9672bc27af10

Contents?: true

Size: 523 Bytes

Versions: 1

Compression:

Stored size: 523 Bytes

Contents

module PgSerializable
  module Nodes
    class Attribute < Base
      def initialize(column_name, label: nil, &prc)
        @column_name = column_name
        @label = label || column_name
        @prc = prc if block_given?
      end

      def to_sql(table_alias=nil)
        [key, value(table_alias)].join(',')
      end

      private
      def key
        "\'#{@label}\'"
      end

      def value(tbl)
        val = "#{tbl && "#{tbl}."}#{@column_name}"
        @prc ? @prc.call(val) : val
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_serializable-0.1.1 lib/pg_serializable/nodes/attribute.rb