Skip to content

Commit

Permalink
[frontend] Fix Rails/ReadWriteAttribute offenses
Browse files Browse the repository at this point in the history
Mob-programming with @DavidKang
  • Loading branch information
bgeuken authored and David Kang committed Dec 15, 2017
1 parent 066db1b commit 855a0ae
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 24 deletions.
13 changes: 0 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,6 @@ Rails/OutputSafety:
- 'src/api/app/helpers/webui/request_helper.rb'
- 'src/api/app/helpers/webui/webui_helper.rb'

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/ReadWriteAttribute:
Exclude:
- 'src/api/app/models/bs_request.rb'
- 'src/api/app/models/event/base.rb'
- 'src/api/app/models/event_subscription.rb'
- 'src/api/app/models/project_log_entry.rb'
- 'src/api/app/models/review.rb'
- 'src/api/app/models/user.rb'

# Offense count: 8
# Configuration parameters: Include.
# Include: db/migrate/*.rb
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def superseding
end

def state
read_attribute(:state).to_sym
self[:state].to_sym
end

after_rollback :reset_cache
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/event/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def set_payload(attribs, keys)
end

def payload
@payload ||= Yajl::Parser.parse(read_attribute(:payload))
@payload ||= Yajl::Parser.parse(self[:payload])
end

def create_project_log_entry_job
Expand Down Expand Up @@ -287,7 +287,7 @@ def _roles(role, project, package = nil)
end

def send_to_bus
RabbitmqBus.publish(self.class.message_bus_routing_key, read_attribute(:payload))
RabbitmqBus.publish(self.class.message_bus_routing_key, self[:payload])
rescue Bunny::Exception => e
logger.error "Publishing to RabbitMQ failed: #{e.message}"
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/event_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def event_class
end

def receiver_role
read_attribute(:receiver_role).to_sym
self[:receiver_role].to_sym
end

def enabled?
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/models/project_log_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def user
# FIXME: We shouldn't slice the input here, this should either fit or never
# reach us through Event...
def additional_info=(obj)
write_attribute(:additional_info, YAML.dump(obj)[0..65534])
self[:additional_info] = YAML.dump(obj)[0..65534]
rescue
write_attribute(:additional_info, nil)
self[:additional_info] = nil
end

# Almost equivalent to the ApplicationRecord.serialize mechanism
def additional_info
a = read_attribute(:additional_info)
a = self[:additional_info]
a ? YAML.safe_load(a) : {}
end

Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NotFoundError < APIException
scope :bs_request_ids_of_involved_users, ->(user_ids) { where(user_id: user_ids).select(:bs_request_id) }

before_validation(on: :create) do
if read_attribute(:state).nil?
if self[:state].nil?
self.state = :new
end
end
Expand All @@ -69,7 +69,7 @@ def validate_not_self_assigned
end

def state
read_attribute(:state).to_sym
self[:state].to_sym
end

def accepted_at
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def create_user_registration
# the database.
def state=(value)
@old_state = state if @old_state.nil?
write_attribute(:state, value)
self[:state] = value
end

# This method checks whether the given value equals the password when
Expand Down Expand Up @@ -759,7 +759,7 @@ def user_relevant_packages_for_status
def state
return owner.state if owner

read_attribute(:state)
self[:state]
end

def to_s
Expand Down

0 comments on commit 855a0ae

Please sign in to comment.