Class: ActiveRecord::BaseWithoutTable

Inherits:
Base
  • Object
show all
Defined in:
lib/plantwatchdog/model.rb

Direct Known Subclasses

PlantWatchdog::Model::Measurement

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.column(name, sql_type = nil, default = nil, null = true) ⇒ Object



53
54
55
56
# File 'lib/plantwatchdog/model.rb', line 53

def column(name, sql_type = nil, default = nil, null = true)
  columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
  reset_column_information
end

.columnsObject



49
50
51
# File 'lib/plantwatchdog/model.rb', line 49

def columns()
  @columns ||= []
end

.reset_column_informationObject

Do not reset @columns



59
60
61
62
# File 'lib/plantwatchdog/model.rb', line 59

def reset_column_information
  generated_methods.each { |name| undef_method(name) }
  @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @read_methods = nil
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
42
# File 'lib/plantwatchdog/model.rb', line 39

def == other
  return false if other.class != self.class
  attributes.values.eql?(other.attributes.values)
end

#create_or_updateObject



35
36
37
# File 'lib/plantwatchdog/model.rb', line 35

def create_or_update
  errors.empty?
end

#hashObject



44
45
46
# File 'lib/plantwatchdog/model.rb', line 44

def hash
  attributes.values.hash
end