Class: Cassandra::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra/function.rb

Overview

Represents a cassandra user defined function

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyString (readonly)



34
35
36
# File 'lib/cassandra/function.rb', line 34

def body
  @body
end

#languageString (readonly)



30
31
32
# File 'lib/cassandra/function.rb', line 30

def language
  @language
end

#nameString (readonly)



28
29
30
# File 'lib/cassandra/function.rb', line 28

def name
  @name
end

#typeCassandra::Type (readonly)



32
33
34
# File 'lib/cassandra/function.rb', line 32

def type
  @type
end

Instance Method Details

#argument(name) ⇒ Cassandra::Argument?



65
66
67
# File 'lib/cassandra/function.rb', line 65

def argument(name)
  @arguments_hash[name]
end

#argument_typesArray<Cassandra::Type>

Get the list of argument types for this function.



89
90
91
# File 'lib/cassandra/function.rb', line 89

def argument_types
  @arguments.map(&:type)
end

#called_on_null?Boolean



53
54
55
# File 'lib/cassandra/function.rb', line 53

def called_on_null?
  @called_on_null
end

#each_argument {|argument| ... } ⇒ Cassandra::Table #each_argumentArray<Cassandra::Argument> Also known as: arguments

Yield or enumerate each argument defined in this function

Overloads:



75
76
77
78
79
80
81
82
83
84
# File 'lib/cassandra/function.rb', line 75

def each_argument(&block)
  if block_given?
    @arguments.each(&block)
    self
  else
    # We return a dup of the arguments so that the caller can manipulate
    # the array however they want without affecting the source.
    @arguments.dup
  end
end

#has_argument?(name) ⇒ Boolean



59
60
61
# File 'lib/cassandra/function.rb', line 59

def has_argument?(name)
  @arguments_hash.key?(name)
end

#to_cqlString



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/cassandra/function.rb', line 133

def to_cql
  cql = "CREATE FUNCTION #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}("
  first = true
  @arguments.each do |argument|
    if first
      first = false
    else
      cql << ', '
    end
    cql << "#{argument.name} #{argument.type}"
  end
  cql << ')'
  cql << if @called_on_null
           "\n  CALLED ON NULL INPUT"
         else
           "\n  RETURNS NULL ON NULL INPUT"
         end
  cql << "\n  RETURNS #{@type}"
  cql << "\n  LANGUAGE #{@language}"
  cql << "\n  AS $$#{@body}$$"
  cql << ';'
end