Class: Cassandra::Function
- Inherits:
-
Object
- Object
- Cassandra::Function
- Defined in:
- lib/cassandra/function.rb
Overview
Represents a cassandra user defined function
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Function body.
-
#language ⇒ String
readonly
Function language.
-
#name ⇒ String
readonly
Function name.
-
#type ⇒ Cassandra::Type
readonly
Function return type.
Instance Method Summary collapse
-
#argument(name) ⇒ Cassandra::Argument?
An argument or nil.
-
#argument_types ⇒ Array<Cassandra::Type>
Get the list of argument types for this function.
-
#called_on_null? ⇒ Boolean
Whether this function will be called on null input.
-
#each_argument(&block) ⇒ Object
(also: #arguments)
Yield or enumerate each argument defined in this function.
-
#has_argument?(name) ⇒ Boolean
Whether this function has a given argument.
-
#to_cql ⇒ String
A cql representation of this function.
Instance Attribute Details
#body ⇒ String (readonly)
34 35 36 |
# File 'lib/cassandra/function.rb', line 34 def body @body end |
#language ⇒ String (readonly)
30 31 32 |
# File 'lib/cassandra/function.rb', line 30 def language @language end |
#name ⇒ String (readonly)
28 29 30 |
# File 'lib/cassandra/function.rb', line 28 def name @name end |
#type ⇒ Cassandra::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_types ⇒ Array<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_argument ⇒ Array<Cassandra::Argument> Also known as: arguments
Yield or enumerate each argument defined in this function
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_cql ⇒ String
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 |