Skip to content

Commit

Permalink
lib/embed.rb: use mattr_accessor instead of class variable for regist…
Browse files Browse the repository at this point in the history
…ered_viewers
  • Loading branch information
ndushay committed Apr 14, 2016
1 parent c63bc31 commit 8442263
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
33 changes: 21 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-03-09 16:41:18 -0800 using RuboCop version 0.37.2.
# on 2016-04-14 11:34:02 -0700 using RuboCop version 0.37.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 7
# Offense count: 9
Metrics/AbcSize:
Max: 58

# Offense count: 3
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 286
Max: 290

# Offense count: 335
# Offense count: 344
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Max: 265

# Offense count: 13
# Offense count: 15
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 67
Expand All @@ -40,15 +40,17 @@ Style/AccessorMethodName:
- 'spec/features/was_seed_viewer_spec.rb'
- 'spec/lib/embed/viewer/was_seed_spec.rb'

# Offense count: 1
Style/ClassVars:
Exclude:
- 'lib/embed.rb'

# Offense count: 26
# Offense count: 28
Style/Documentation:
Enabled: false

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: call, braces
Style/LambdaCall:
Enabled: false

# Offense count: 7
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
# NamePrefix: is_, has_, have_
Expand All @@ -69,3 +71,10 @@ Style/RegexpLiteral:
- 'lib/embed/request.rb'
- 'lib/embed/viewer/common_viewer.rb'
- 'spec/features/embed_this_panel_spec.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false
13 changes: 6 additions & 7 deletions lib/embed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ module Embed
require 'embed/request'
require 'embed/response'

@@registered_viewers = []
def self.register_viewer(viewer)
raise DuplicateViewerRegistration if viewer_supported_type_already_registered?(viewer)
@@registered_viewers << viewer
mattr_accessor :registered_viewers do
[]
end

def self.registered_viewers
@@registered_viewers
def self.register_viewer(viewer)
raise DuplicateViewerRegistration if viewer_supported_type_already_registered?(viewer)
registered_viewers << viewer
end

class << self
private

def viewer_supported_type_already_registered?(viewer)
viewer.supported_types.any? do |supported_type|
@@registered_viewers.any? do |registered_viewer|
registered_viewers.any? do |registered_viewer|
registered_viewer.supported_types.include?(supported_type)
end
end
Expand Down

0 comments on commit 8442263

Please sign in to comment.