Class: Coupler::Models::Field

Inherits:
Sequel::Model
  • Object
show all
Includes:
CommonModel
Defined in:
lib/coupler/models/field.rb

Constant Summary collapse

TYPES =
{
  'integer'  => {:type => Integer},
  'string'   => {:type => String, :size => 255},
  'datetime' => {:type => DateTime}
}

Instance Method Summary collapse

Methods included from CommonModel

#after_destroy, #after_save, #before_create, #before_update, included, #save!, #touch!

Instance Method Details

#final_db_typeObject



22
23
24
# File 'lib/coupler/models/field.rb', line 22

def final_db_type
  local_db_type || db_type
end

#final_typeObject



18
19
20
# File 'lib/coupler/models/field.rb', line 18

def final_type
  local_type || self[:type]
end

#local_column_optionsObject



14
15
16
# File 'lib/coupler/models/field.rb', line 14

def local_column_options
  { :name => name, :primary_key => is_primary_key }.merge!(TYPES[final_type])
end

#name_symObject



36
37
38
# File 'lib/coupler/models/field.rb', line 36

def name_sym
  @name_sym ||= name.to_sym
end

#scenarios_datasetObject



26
27
28
29
30
31
32
33
34
# File 'lib/coupler/models/field.rb', line 26

def scenarios_dataset
  marshalled_id = [Marshal.dump(id)].pack('m')
  Scenario.
    select(:scenarios.*).
    filter({:project_id => resource.project_id} & ({:resource_1_id => resource_id} | {:resource_2_id => resource_id})).
    join(Matcher, :scenario_id => :id).
    join(Comparison, :matcher_id => :id).
    filter({:lhs_type => 'field', :raw_lhs_value => marshalled_id} | {:rhs_type => 'field', :raw_rhs_value => marshalled_id})
end