class Cassandra::UDT::Strict

@private

Public Class Methods

new(keyspace, name, fields, values) click to toggle source
   # File lib/cassandra/udt.rb
24 def initialize(keyspace, name, fields, values)
25   @keyspace     = keyspace
26   @name         = name
27   @fields       = fields
28   @values       = values
29   @name_to_type = fields.each_with_object(::Hash.new) do |f, index|
30     index[f.name] = f.type
31   end
32 end

Public Instance Methods

==(other)
Alias for: eql?
[](field) click to toggle source

Returns value of the field.

@param field [String, Integer] name or numeric index of the field @return [Object] value of the field

   # File lib/cassandra/udt.rb
69 def [](field)
70   case field
71   when ::Integer
72     return nil if field < 0 || field >= @fields.size
73     @values[@fields[field][0]]
74   when ::String
75     @values[field]
76   else
77     raise ::ArgumentError, "unrecognized field #{field} in UDT: " \
78       "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
79   end
80 end
[]=(field, value) click to toggle source

Sets value of the field.

@param field [String, Integer] name or numeric index of the field @param value [Object] new value for the field

@raise [IndexError] when numeric index given is out of bounds @raise [KeyError] when field with a given name is not present @raise [ArgumentError] when neither a numeric index nor a field name

given

@return [Object] value.

    # File lib/cassandra/udt.rb
125 def []=(field, value)
126   case field
127   when ::Integer
128     if field < 0 || field >= @fields.size
129       raise ::IndexError,
130             "field index #{field} is not present in UDT: " \
131             "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
132     end
133     Util.assert_type(@fields[field][1], value)
134     @values[@fields[field][0]] = value
135   when ::String
136     unless @name_to_type.key?(field)
137       raise ::KeyError,
138             "field #{field} is not defined in UDT: " \
139             "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
140     end
141     Util.assert_type(@name_to_type[field], value)
142     @values[field] = value
143   else
144     raise ::ArgumentError, "unrecognized field #{field} in UDT: " \
145       "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
146   end
147 end
each() { |n, values| ... } click to toggle source

Iterates over all fields of the UDT @yieldparam name [String] field name @yieldparam value [Object] field value @return [Cassandra::UDT] self

    # File lib/cassandra/udt.rb
153 def each(&block)
154   @fields.each do |f|
155     n = f.name
156     yield(n, @values[n])
157   end
158   self
159 end
eql?(other) click to toggle source
    # File lib/cassandra/udt.rb
171 def eql?(other)
172   (other.is_a?(Strict) && @values.all? {|n, v| v == other[n]}) ||
173     (other.is_a?(UDT) && other == self)
174 end
Also aliased as: ==
fetch(field) click to toggle source

Returns value of the field.

@param field [String, Integer] name or numeric index of the field to

lookup

@raise [IndexError] when numeric index given is out of bounds @raise [KeyError] when field with a given name is not present @raise [ArgumentError] when neither a numeric index nor a field name given

@return [Object] value of the field

    # File lib/cassandra/udt.rb
 92 def fetch(field)
 93   case field
 94   when ::Integer
 95     if field < 0 || field >= @fields.size
 96       raise ::IndexError,
 97             "field index #{field} is not present in UDT: " \
 98             "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
 99     end
100     @values[@fields[field][0]]
101   when ::String
102     unless @name_to_type.key?(field)
103       raise ::KeyError,
104             "field #{field} is not defined in UDT: " \
105             "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
106     end
107     @values[field]
108   else
109     raise ::ArgumentError, "unrecognized field #{field} in UDT: " \
110       "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
111   end
112 end
inspect() click to toggle source
    # File lib/cassandra/udt.rb
167 def inspect
168   "#<Cassandra::UDT:0x#{object_id.to_s(16)} #{self}>"
169 end
method_missing(method, *args, &block) click to toggle source
Calls superclass method Cassandra::UDT#method_missing
   # File lib/cassandra/udt.rb
34 def method_missing(method, *args, &block)
35   return super if block_given? || args.size > 1
36 
37   field  = method.to_s
38   assign = !field.chomp!('=').nil?
39 
40   return super if assign && args.empty?
41   return super unless @name_to_type.key?(field)
42 
43   if assign
44     value = args.first
45     Util.assert_type(@name_to_type[field], value)
46     @values[field] = value
47   else
48     @values[field]
49   end
50 end
respond_to?(method) click to toggle source

Returns true if a field with a given name is present in this value

@param method [Symbol] name of the field

@return [Boolean] whether a field is present

Calls superclass method Cassandra::UDT#respond_to?
   # File lib/cassandra/udt.rb
57 def respond_to?(method)
58   field = method.to_s
59   field.chomp!('=')
60 
61   return true if @name_to_type.key?(field)
62   super
63 end
size() click to toggle source

Returns UDT size @return [Integer] UDT size

    # File lib/cassandra/udt.rb
163 def size
164   @fields.size
165 end