koraktor/gallerist

View on GitHub
lib/gallerist/library.rb

Summary

Maintainability
A
0 mins
Test Coverage

Gallerist::Library has at least 19 methods
Open

class Gallerist::Library
Severity: Minor
Found in lib/gallerist/library.rb by reek

Too Many Methods is a special case of LargeClass.

Example

Given this configuration

TooManyMethods:
  max_methods: 3

and this code:

class TooManyMethods
  def one; end
  def two; end
  def three; end
  def four; end
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:TooManyMethods has at least 4 methods (TooManyMethods)

Gallerist::Library tests 'iphoto?' at least 3 times
Open

    copy_tmp_db (iphoto? ? 'Faces.db' : 'Person.db')
  end

  def copy_tmp_db(db_name)
    @temp_path ||= Gallerist::App.tempdir
Severity: Minor
Found in lib/gallerist/library.rb by reek

Repeated Conditional is a special case of Simulated Polymorphism. Basically it means you are checking the same value throughout a single class and take decisions based on this.

Example

Given

class RepeatedConditionals
  attr_accessor :switch

  def repeat_1
    puts "Repeat 1!" if switch
  end

  def repeat_2
    puts "Repeat 2!" if switch
  end

  def repeat_3
    puts "Repeat 3!" if switch
  end
end

Reek would emit the following warning:

test.rb -- 4 warnings:
  [5, 9, 13]:RepeatedConditionals tests switch at least 3 times (RepeatedConditional)

If you get this warning then you are probably not using the right abstraction or even more probable, missing an additional abstraction.

Gallerist::Library#check_db calls 'File.dirname File.realpath(main_db_path)' 2 times
Open

    @db_path = File.dirname File.realpath(main_db_path)
  rescue
    main_db_path = file @path, 'Database', 'Library.apdb'
    @db_path = File.dirname File.realpath(main_db_path)
Severity: Minor
Found in lib/gallerist/library.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

Gallerist::Library has no descriptive comment
Open

class Gallerist::Library
Severity: Minor
Found in lib/gallerist/library.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

Gallerist::Library assumes too much for instance variable '@db_path'
Open

class Gallerist::Library
Severity: Minor
Found in lib/gallerist/library.rb by reek

Classes should not assume that instance variables are set or present outside of the current class definition.

Good:

class Foo
  def initialize
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Good as well:

class Foo
  def foo?
    bar == :foo
  end

  def bar
    @bar ||= :foo
  end
end

Bad:

class Foo
  def go_foo!
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Example

Running Reek on:

class Dummy
  def test
    @ivar
  end
end

would report:

[1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

Note that this example would trigger this smell warning as well:

class Parent
  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    @omg
  end
end

The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

class Parent
  attr_reader :omg

  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    omg
  end
end

Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

If you don't want to expose those methods as public API just make them private like this:

class Parent
  def initialize(omg)
    @omg = omg
  end

  private
  attr_reader :omg
end

class Child < Parent
  def foo
    omg
  end
end

Current Support in Reek

An instance variable must:

  • be set in the constructor
  • or be accessed through a method with lazy initialization / memoization.

If not, Instance Variable Assumption will be reported.

Gallerist::Library assumes too much for instance variable '@legacy'
Open

class Gallerist::Library
Severity: Minor
Found in lib/gallerist/library.rb by reek

Classes should not assume that instance variables are set or present outside of the current class definition.

Good:

class Foo
  def initialize
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Good as well:

class Foo
  def foo?
    bar == :foo
  end

  def bar
    @bar ||= :foo
  end
end

Bad:

class Foo
  def go_foo!
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Example

Running Reek on:

class Dummy
  def test
    @ivar
  end
end

would report:

[1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

Note that this example would trigger this smell warning as well:

class Parent
  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    @omg
  end
end

The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

class Parent
  attr_reader :omg

  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    omg
  end
end

Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

If you don't want to expose those methods as public API just make them private like this:

class Parent
  def initialize(omg)
    @omg = omg
  end

  private
  attr_reader :omg
end

class Child < Parent
  def foo
    omg
  end
end

Current Support in Reek

An instance variable must:

  • be set in the constructor
  • or be accessed through a method with lazy initialization / memoization.

If not, Instance Variable Assumption will be reported.

Gallerist::Library#check_db calls 'File.realpath(main_db_path)' 2 times
Open

    @db_path = File.dirname File.realpath(main_db_path)
  rescue
    main_db_path = file @path, 'Database', 'Library.apdb'
    @db_path = File.dirname File.realpath(main_db_path)
Severity: Minor
Found in lib/gallerist/library.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

Gallerist::Library assumes too much for instance variable '@temp_path'
Open

class Gallerist::Library
Severity: Minor
Found in lib/gallerist/library.rb by reek

Classes should not assume that instance variables are set or present outside of the current class definition.

Good:

class Foo
  def initialize
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Good as well:

class Foo
  def foo?
    bar == :foo
  end

  def bar
    @bar ||= :foo
  end
end

Bad:

class Foo
  def go_foo!
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Example

Running Reek on:

class Dummy
  def test
    @ivar
  end
end

would report:

[1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

Note that this example would trigger this smell warning as well:

class Parent
  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    @omg
  end
end

The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

class Parent
  attr_reader :omg

  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    omg
  end
end

Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

If you don't want to expose those methods as public API just make them private like this:

class Parent
  def initialize(omg)
    @omg = omg
  end

  private
  attr_reader :omg
end

class Child < Parent
  def foo
    omg
  end
end

Current Support in Reek

An instance variable must:

  • be set in the constructor
  • or be accessed through a method with lazy initialization / memoization.

If not, Instance Variable Assumption will be reported.

Gallerist::Library#file doesn't depend on instance state (maybe move it to another class?)
Open

  def file(*path_components)
Severity: Minor
Found in lib/gallerist/library.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

Gallerist::Library#tags doesn't depend on instance state (maybe move it to another class?)
Open

  def tags
Severity: Minor
Found in lib/gallerist/library.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

Gallerist::Library#albums doesn't depend on instance state (maybe move it to another class?)
Open

  def albums
Severity: Minor
Found in lib/gallerist/library.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

Gallerist::Library#persons doesn't depend on instance state (maybe move it to another class?)
Open

  def persons
Severity: Minor
Found in lib/gallerist/library.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

Gallerist::Library#photos doesn't depend on instance state (maybe move it to another class?)
Open

  def photos
Severity: Minor
Found in lib/gallerist/library.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

(...) interpreted as grouped expression.
Open

    copy_tmp_db (iphoto? ? 'Faces.db' : 'Person.db')
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

Checks for space between the name of a called method and a left parenthesis.

Example:

# bad

puts (x + y)

Example:

# good

puts(x + y)

Avoid rescuing without specifying an error class.
Open

  rescue
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Place the . on the next line, together with the method name.
Open

    @app_id ||= Gallerist::AdminData.
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cop checks the . position in multi-line method calls.

Example: EnforcedStyle: leading (default)

# bad
something.
  mehod

# good
something
  .method

Example: EnforcedStyle: trailing

# bad
something
  .method

# good
something.
  mehod

Missing top-level class documentation comment.
Open

class Gallerist::Library
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Use nested module/class definitions instead of compact style.
Open

class Gallerist::Library
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cop checks the style of children definitions at classes and modules. Basically there are two different styles:

Example: EnforcedStyle: nested (default)

# good
# have each child on its own line
class Foo
  class Bar
  end
end

Example: EnforcedStyle: compact

# good
# combine definitions as much as possible
class Foo::Bar
end

The compact style is only forced for classes/modules with one child.

Place the . on the next line, together with the method name.
Open

      where(propertyArea: 'database', propertyName: 'applicationIdentifier').
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cop checks the . position in multi-line method calls.

Example: EnforcedStyle: leading (default)

# bad
something.
  mehod

# good
something
  .method

Example: EnforcedStyle: trailing

# bad
something
  .method

# good
something.
  mehod

Extra empty line detected at class body end.
Open


end
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Extra empty line detected at class body beginning.
Open


  attr_reader :name
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Align where with Gallerist::AdminData. on line 26.
Open

      where(propertyArea: 'database', propertyName: 'applicationIdentifier').
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cop checks the indentation of the method name part in method calls that span more than one line.

Example: EnforcedStyle: aligned

# bad
while myvariable
.b
  # do something
end

# good
while myvariable
      .b
  # do something
end

# good
Thing.a
     .b
     .c

Example: EnforcedStyle: indented

# good
while myvariable
  .b

  # do something
end

Example: EnforcedStyle: indentedrelativeto_receiver

# good
while myvariable
        .a
        .b

  # do something
end

# good
myvariable = Thing
               .a
               .b
               .c

Align pluck with Gallerist::AdminData. on line 26.
Open

      pluck(:propertyValue).first
Severity: Minor
Found in lib/gallerist/library.rb by rubocop

This cop checks the indentation of the method name part in method calls that span more than one line.

Example: EnforcedStyle: aligned

# bad
while myvariable
.b
  # do something
end

# good
while myvariable
      .b
  # do something
end

# good
Thing.a
     .b
     .c

Example: EnforcedStyle: indented

# good
while myvariable
  .b

  # do something
end

Example: EnforcedStyle: indentedrelativeto_receiver

# good
while myvariable
        .a
        .b

  # do something
end

# good
myvariable = Thing
               .a
               .b
               .c

There are no issues that match your filters.

Category
Status