class Janko::TaggedColumn

Public Instance Methods

default_state() click to toggle source
# File lib/janko/tagged_column.rb, line 20
def default_state
    { tags: {} }
end
has_tag?(tag) click to toggle source
# File lib/janko/tagged_column.rb, line 40
def has_tag?(tag)
    tags.has_key?(tag.to_s)
end
inspect() click to toggle source
# File lib/janko/tagged_column.rb, line 81
def inspect
    children = "(#{tags.keys.join(" ")})"
    "#<#{self.class}:0x#{self.__id__.to_s(16)} #{name}#{children}>"
end
quoted(prefix = nil) click to toggle source

FIXME: Quoting

# File lib/janko/tagged_column.rb, line 57
def quoted(prefix = nil)
    prefix.nil? ? "\"#{name}\"" : "\"#{prefix}\".\"#{name}\""
end
set(updates) click to toggle source
# File lib/janko/tagged_column.rb, line 24
def set(updates)
    chain(updates)
end
tag(tag) click to toggle source
# File lib/janko/tagged_column.rb, line 28
def tag(tag)
    tag = tag.to_s
    tags.merge!(tag => true) unless (tag == "")
    self
end
tagged?() click to toggle source
# File lib/janko/tagged_column.rb, line 44
def tagged?
    not tags.empty?
end
to_bind(position) click to toggle source
# File lib/janko/tagged_column.rb, line 73
def to_bind(position)
    "$#{position}"
end
to_condition(left, right) click to toggle source
# File lib/janko/tagged_column.rb, line 61
def to_condition(left, right)
    "#{quoted(left)} = #{quoted(right)}"
end
to_s() click to toggle source
# File lib/janko/tagged_column.rb, line 48
def to_s
    tags.keys.join(" ")
end
to_setter(left, right) click to toggle source
# File lib/janko/tagged_column.rb, line 65
def to_setter(left, right)
    "#{quoted} = #{maybe_on_update(left, right)}"
end
to_typecast_bind(position) click to toggle source
# File lib/janko/tagged_column.rb, line 77
def to_typecast_bind(position)
    "$#{position}::#{type}"
end
to_value(prefix = nil) click to toggle source
# File lib/janko/tagged_column.rb, line 69
def to_value(prefix = nil)
    maybe_wrap(nil, prefix)
end
type() click to toggle source
# File lib/janko/tagged_column.rb, line 52
def type
    connection.column_type(table, name)
end
untag(tag) click to toggle source
# File lib/janko/tagged_column.rb, line 34
def untag(tag)
    tag = tag.to_s
    tags.reject! { |k| k == tag } unless (tag == "")
    self
end

Private Instance Methods

column_default_value() click to toggle source
# File lib/janko/tagged_column.rb, line 119
def column_default_value
    @column_default_value ||= begin
        return unless (value = @default)
        return(value) unless value.is_a?(Flag)
        return unless (value == Janko::DEFAULT)
        connection.column_default(table, name)
    end
end
flagged(value, flag) click to toggle source
# File lib/janko/tagged_column.rb, line 128
def flagged(value, flag)
    return(false) unless value.is_a?(Fixnum)
    (value & flag) == value
end
keep_existing_value(prefix) click to toggle source
# File lib/janko/tagged_column.rb, line 112
def keep_existing_value(prefix)
    return if prefix.nil?
    return unless (value = @default)
    return unless (value == Janko::KEEP)
    quoted(prefix)
end
maybe_default(left, right) click to toggle source
# File lib/janko/tagged_column.rb, line 103
def maybe_default(left, right)
    values = [ quoted(right) ]
    values.push(keep_existing_value(left))
    values.push(column_default_value)
    values.compact!
    return(values.first) if (values.length == 1)
    "COALESCE(#{values.join(", ")})"
end
maybe_on_update(left, right) click to toggle source
# File lib/janko/tagged_column.rb, line 94
def maybe_on_update(left, right)
    inner = maybe_wrap(left, right)
    return(inner) unless @on_update
    output = Agrippa::State.new(@on_update, :gsub)
    output.gsub(/\$NEW/i) { inner }
    output.gsub(/\$OLD/i) { quoted(left) }
    output._value
end
maybe_wrap(left, right) click to toggle source
# File lib/janko/tagged_column.rb, line 88
def maybe_wrap(left, right)
    inner = maybe_default(left, right)
    return(inner) unless @wrap
    @wrap.gsub(/\$NEW/i) { inner }
end