Class: Janko::TaggedColumn

Inherits:
Object
  • Object
show all
Includes:
Agrippa::Delegation, Agrippa::Mutable
Defined in:
lib/janko/tagged_column.rb

Instance Method Summary collapse

Instance Method Details

#default_stateObject



20
21
22
# File 'lib/janko/tagged_column.rb', line 20

def default_state
    { tags: {} }
end

#has_tag?(tag) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/janko/tagged_column.rb', line 40

def has_tag?(tag)
    tags.has_key?(tag.to_s)
end

#inspectObject



81
82
83
84
# 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) ⇒ Object

FIXME: Quoting



57
58
59
# File 'lib/janko/tagged_column.rb', line 57

def quoted(prefix = nil)
    prefix.nil? ? "\"#{name}\"" : "\"#{prefix}\".\"#{name}\""
end

#set(updates) ⇒ Object



24
25
26
# File 'lib/janko/tagged_column.rb', line 24

def set(updates)
    chain(updates)
end

#tag(tag) ⇒ Object



28
29
30
31
32
# File 'lib/janko/tagged_column.rb', line 28

def tag(tag)
    tag = tag.to_s
    tags.merge!(tag => true) unless (tag == "")
    self
end

#tagged?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/janko/tagged_column.rb', line 44

def tagged?
    not tags.empty?
end

#to_bind(position) ⇒ Object



73
74
75
# File 'lib/janko/tagged_column.rb', line 73

def to_bind(position)
    "$#{position}"
end

#to_condition(left, right) ⇒ Object



61
62
63
# File 'lib/janko/tagged_column.rb', line 61

def to_condition(left, right)
    "#{quoted(left)} = #{quoted(right)}"
end

#to_sObject



48
49
50
# File 'lib/janko/tagged_column.rb', line 48

def to_s
    tags.keys.join(" ")
end

#to_setter(left, right) ⇒ Object



65
66
67
# File 'lib/janko/tagged_column.rb', line 65

def to_setter(left, right)
    "#{quoted} = #{maybe_on_update(left, right)}"
end

#to_typecast_bind(position) ⇒ Object



77
78
79
# File 'lib/janko/tagged_column.rb', line 77

def to_typecast_bind(position)
    "$#{position}::#{type}"
end

#to_value(prefix = nil) ⇒ Object



69
70
71
# File 'lib/janko/tagged_column.rb', line 69

def to_value(prefix = nil)
    maybe_wrap(nil, prefix)
end

#typeObject



52
53
54
# File 'lib/janko/tagged_column.rb', line 52

def type
    connection.column_type(table, name)
end

#untag(tag) ⇒ Object



34
35
36
37
38
# File 'lib/janko/tagged_column.rb', line 34

def untag(tag)
    tag = tag.to_s
    tags.reject! { |k| k == tag } unless (tag == "")
    self
end