Class: Cockroach::Source::Model
- Inherits:
-
Object
- Object
- Cockroach::Source::Model
- Defined in:
- lib/cockroach/source/model.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model, options = {}) ⇒ Model
constructor
A new instance of Model.
-
#sample ⇒ Object
Returns a random record, among generated.
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, = {} @model = model @options = end |
Instance Attribute Details
#model ⇒ Object (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
#sample ⇒ Object
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 |