Class: Cockroach::Source::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/cockroach/source/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) ⇒ Model

Returns a new instance of Model.



6
7
8
9
# File 'lib/cockroach/source/model.rb', line 6

def initialize model, options = {}
  @model = model
  @options = options
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/cockroach/source/model.rb', line 4

def model
  @model
end

Instance Method Details

#sampleObject

Returns a random record, among generated.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cockroach/source/model.rb', line 12

def sample
  if @options.blank?
    model.order('RAND()').first
  else
    if @options.has_key?("id")
      find @options["id"]
    elsif @options.has_key?("conditions")
      model.order('RAND()').where(@options["conditions"]).first
    end
  end
end