Class: ActiveGroonga::Vector
- Inherits:
-
Object
- Object
- ActiveGroonga::Vector
- Includes:
- Enumerable
- Defined in:
- lib/active_groonga/vector.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #build(*args, &block) ⇒ Object
- #create(*args, &block) ⇒ Object
- #create!(*args, &block) ⇒ Object
- #each ⇒ Object
-
#initialize(owner, klass, values = []) ⇒ Vector
constructor
A new instance of Vector.
- #to_ary ⇒ Object
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
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
20 21 22 |
# File 'lib/active_groonga/vector.rb', line 20 def klass @klass end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
20 21 22 |
# File 'lib/active_groonga/vector.rb', line 20 def owner @owner end |
#values ⇒ Object (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 |
#each ⇒ Object
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_ary ⇒ Object
51 52 53 |
# File 'lib/active_groonga/vector.rb', line 51 def to_ary to_a end |