Skip to content

Commit

Permalink
Raise update error to inform the user
Browse files Browse the repository at this point in the history
  • Loading branch information
relf committed Feb 17, 2021
1 parent 97c9e72 commit b9fdd01
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ WORKDIR /whatsopt
COPY Gemfile Gemfile.lock ./

RUN bundle config without staging production \
&& bundle install --jobs 20 --retry 5
&& bundle install --jobs 20 --retry 5

COPY . ./

Expand Down
25 changes: 1 addition & 24 deletions app/models/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,40 +63,17 @@ def self.create_connection!(from_disc, to_disc, name, sub_analysis_check = true)
vout = Variable.of_analysis(from_disc.analysis)
.where(name: name, io_mode: WhatsOpt::Variable::OUT)
.first_or_create!(shape: 1, type: "Float", desc: "", units: "", active: true)
vout.update(discipline_id: from_disc.id)
vout.update!(discipline_id: from_disc.id)
vin = Variable.where(discipline_id: to_disc.id, name: name, io_mode: WhatsOpt::Variable::IN)
.first_or_create!(shape: 1, type: "Float", desc: "", units: "", active: true)
conn = Connection.where(from_id: vout.id, to_id: vin.id).first_or_create!
# downgrade the role if needed
# Rails.logger.info "CREATED #{conn.from.inspect} #{conn.to.inspect}"
if !conn.from.discipline.is_driver? && !conn.to.discipline.is_driver?
Connection.where(from_id: vout.id).update(role: WhatsOpt::Variable::STATE_VAR_ROLE)
end
conn
end
end

# manage exclusively Driver variables if deconnected should be removed
# def delete_driver_variables!
# Rails.logger.info "BEFORE DESTROY #{self.from&.name} #{self.from&.discipline&.name} #{self.to&.discipline&.name}"
# Connection.transaction do
# to = self.to
# if to&.discipline&.is_driver?
# Rails.logger.info "----------------------- Connection to driver: supress #{to.name} #{to.id} driver var"
# to.delete
# end
# conns = Connection.where(from: from)
# Rails.logger.info "#{conns.inspect}"
# if conns.size == 1
# from = conns.first.from
# if from&.discipline&.is_driver?
# Rails.logger.info "----------------------- Connection only from driver: supress #{from.name} #{from.id} driver var"
# from.delete
# end
# end
# end
# end

def update_connections!(params)
params = params.to_h # accept string parameters
_sanitize_connection_params(params)
Expand Down
5 changes: 4 additions & 1 deletion app/models/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class Variable < ApplicationRecord

validates :name, format: { with: /\A[a-zA-Z][\-\.=:_a-zA-Z0-9]*\z/, message: "%{value} is not a valid variable name." }
validates :name, :io_mode, :type, :shape, presence: true, allow_blank: false
validates :name, uniqueness: { scope: [:discipline], message: "%{value} should be unique per discipline." }
validates :name, uniqueness: { scope: [:discipline], message: -> (object, data) {
"%{value} as a variable name should be unique for discipline #{object.discipline.name}."
}
}
validate :shape_is_well_formed

scope :numeric, -> { where.not(type: STRING_T) }
Expand Down

0 comments on commit b9fdd01

Please sign in to comment.