Skip to content

Commit

Permalink
Use the safe navigation operator (&.) in a couple places per rubocop …
Browse files Browse the repository at this point in the history
…suggestion

Disable some rubocop rules
  • Loading branch information
tjgrathwell committed Oct 9, 2016
1 parent 70092d0 commit 8c94d37
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
17 changes: 10 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Lint/UnusedMethodArgument:
Enabled: false

Lint/UselessAssignment:
Enabled: false
Exclude:
- '**/*_spec.rb'

Lint/Void:
Enabled: false
Expand All @@ -25,6 +26,8 @@ Metrics/AbcSize:

Metrics/ClassLength:
Max: 500
Exclude:
- 'app/models/course.rb'

Metrics/CyclomaticComplexity:
Max: 11
Expand All @@ -44,12 +47,6 @@ Metrics/PerceivedComplexity:
Performance/Count:
Enabled: false

Performance/Detect:
Enabled: false

Performance/StringReplacement:
Enabled: false

Style/AccessorMethodName:
Enabled: false

Expand Down Expand Up @@ -187,6 +184,9 @@ Style/RaiseArgs:
Style/RedundantReturn:
Enabled: false

Style/SafeNavigation:
Enabled: false

Style/SelfAssignment:
Enabled: false

Expand Down Expand Up @@ -244,6 +244,9 @@ Style/TrailingCommaInLiteral:
Style/TrailingWhitespace:
Enabled: false

Style/VariableNumber:
Enabled: false

Style/WordArray:
MinSize: 3
Exclude:
Expand Down
6 changes: 3 additions & 3 deletions app/models/event_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EventSession < ActiveRecord::Base
validates_uniqueness_of :name, scope: [:event_id]
validate on: :create do
if starts_at && starts_at < Time.now
errors.add(:starts_at, 'must start in the future') unless event && event.historical?
errors.add(:starts_at, 'must start in the future') unless event&.historical?
end
end
validate do
Expand Down Expand Up @@ -56,11 +56,11 @@ def update_event_times
end

def starts_at
(event && event.persisted?) ? date_in_time_zone(:starts_at) : read_attribute(:starts_at)
(event&.persisted?) ? date_in_time_zone(:starts_at) : read_attribute(:starts_at)
end

def ends_at
(event && event.persisted?) ? date_in_time_zone(:ends_at) : read_attribute(:ends_at)
(event&.persisted?) ? date_in_time_zone(:ends_at) : read_attribute(:ends_at)
end

def session_date
Expand Down
4 changes: 2 additions & 2 deletions app/models/rsvp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Rsvp < ActiveRecord::Base

def set_defaults
if has_attribute?(:token)
self.token ||= SecureRandom.uuid.gsub(/\-/, '')
self.token ||= SecureRandom.uuid.delete('-')
end
end

Expand Down Expand Up @@ -205,7 +205,7 @@ def waitlisted?
end

def update_counter_cache
event.update_rsvp_counts if event
event&.update_rsvp_counts
end

def as_json(options={})
Expand Down
2 changes: 1 addition & 1 deletion app/policies/chapter_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create?
end

def destroy?
user && user.admin?
user&.admin?
end

def modify_leadership?
Expand Down
2 changes: 1 addition & 1 deletion app/policies/location_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def update?
end

def edit_additional_details?
record.region && record.region.has_leader?(user)
record.region&.has_leader?(user)
end
end
4 changes: 2 additions & 2 deletions app/services/database_anonymizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def anonymize_rsvp(rsvp)

def anonymize_profile(profile)
profile.other = Faker::Company.catch_phrase
profile.github_username = "#{Faker::Hacker.noun.gsub(' ', '-').downcase}#{Random.rand(10_000_000)}"
profile.twitter_username = "#{Faker::Hacker.noun.gsub(' ', '_').downcase}#{Random.rand(100)}"
profile.github_username = "#{Faker::Hacker.noun.tr(' ', '-').downcase}#{Random.rand(10_000_000)}"
profile.twitter_username = "#{Faker::Hacker.noun.tr(' ', '_').downcase}#{Random.rand(100)}"
profile.bio = Faker::Company.bs
profile.save!
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ db_namespace = namespace :db do
end

File.write(filename, new_schema_content)
rescue StandardError => e
rescue StandardError => _e
File.write(filename, existing_schema_content)
raise
end
Expand Down

0 comments on commit 8c94d37

Please sign in to comment.