Class: ActiveGroonga::Vector

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_groonga/vector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, klass, values = []) ⇒ Vector

Returns a new instance of Vector.



21
22
23
24
25
26
# File 'lib/active_groonga/vector.rb', line 21

def initialize(owner, klass, values=[])
  @owner = owner
  @klass = klass
  @values = values
  @values = [@values] unless @values.is_a?(Array)
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



20
21
22
# File 'lib/active_groonga/vector.rb', line 20

def klass
  @klass
end

#ownerObject (readonly)

Returns the value of attribute owner.



20
21
22
# File 'lib/active_groonga/vector.rb', line 20

def owner
  @owner
end

#valuesObject (readonly)

Returns the value of attribute values.



20
21
22
# File 'lib/active_groonga/vector.rb', line 20

def values
  @values
end

Instance Method Details

#<<(value) ⇒ Object



46
47
48
49
# File 'lib/active_groonga/vector.rb', line 46

def <<(value)
  value = @klass.create(value) if @owner.persisted?
  @values << value
end

#build(*args, &block) ⇒ Object



28
29
30
# File 'lib/active_groonga/vector.rb', line 28

def build(*args, &block)
  @klass.new(*args, &block)
end

#create(*args, &block) ⇒ Object



32
33
34
# File 'lib/active_groonga/vector.rb', line 32

def create(*args, &block)
  @klass.create(*args, &block)
end

#create!(*args, &block) ⇒ Object



36
37
38
# File 'lib/active_groonga/vector.rb', line 36

def create!(*args, &block)
  @klass.create!(*args, &block)
end

#eachObject



40
41
42
43
44
# File 'lib/active_groonga/vector.rb', line 40

def each
  @values.each do |value|
    yield(instantiate(value))
  end
end

#to_aryObject



51
52
53
# File 'lib/active_groonga/vector.rb', line 51

def to_ary
  to_a
end