Skip to content

Commit

Permalink
Merge pull request #4 from samvera-labs/rubocop
Browse files Browse the repository at this point in the history
Add Rubocop
  • Loading branch information
mjgiarlo authored Jul 26, 2017
2 parents 3a5e2c7 + 915dbd9 commit 717ec35
Show file tree
Hide file tree
Showing 22 changed files with 242 additions and 131 deletions.
15 changes: 15 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require: rubocop-rspec
inherit_from: .rubocop_todo.yml

AllCops:
DisplayCopNames: true

Metrics/LineLength:
Max: 120

Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'

RSpec/MultipleExpectations:
Enabled: false
75 changes: 75 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-07-26 10:46:37 -0500 using RuboCop version 0.49.1.
# 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: 2
Metrics/AbcSize:
Exclude:
- 'lib/iiif_manifest/manifest_builder/resource_builder.rb'
- 'lib/iiif_manifest/manifest_factory.rb'

# Offense count: 1
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Exclude:
- 'iiif_manifest.gemspec'

# Offense count: 1
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/lib/iiif_manifest/manifest_factory_spec.rb'

# Offense count: 8
RSpec/NamedSubject:
Exclude:
- 'spec/lib/iiif_manifest/display_image_spec.rb'
- 'spec/lib/iiif_manifest/iiif_endpoint_spec.rb'
- 'spec/lib/iiif_manifest/manifest_builder/resource_builder_spec.rb'

# Offense count: 1
# Configuration parameters: IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/lib/iiif_manifest/display_image_spec.rb'

# Offense count: 20
Style/Documentation:
Exclude:
- 'lib/iiif_manifest/display_image.rb'
- 'lib/iiif_manifest/iiif_collection.rb'
- 'lib/iiif_manifest/iiif_endpoint.rb'
- 'lib/iiif_manifest/manifest_builder/canvas_builder.rb'
- 'lib/iiif_manifest/manifest_builder/canvas_builder.rb'
- 'lib/iiif_manifest/manifest_builder/canvas_builder_factory.rb'
- 'lib/iiif_manifest/manifest_builder/child_manifest_builder_factory.rb'
- 'lib/iiif_manifest/manifest_builder/composite_builder.rb'
- 'lib/iiif_manifest/manifest_builder/composite_builder_factory.rb'
- 'lib/iiif_manifest/manifest_builder/deep_canvas_builder_factory.rb'
- 'lib/iiif_manifest/manifest_builder/image_builder.rb'
- 'lib/iiif_manifest/manifest_builder/image_service_builder.rb'
- 'lib/iiif_manifest/manifest_builder/record_property_builder.rb'
- 'lib/iiif_manifest/manifest_builder/resource_builder.rb'
- 'lib/iiif_manifest/manifest_builder/sequence_builder.rb'
- 'lib/iiif_manifest/manifest_builder.rb'
- 'lib/iiif_manifest/manifest_factory.rb'
- 'lib/iiif_manifest/manifest_service_locator.rb'
- 'lib/iiif_manifest.rb'
- 'spec/lib/iiif_manifest/manifest_factory_spec.rb'

# Offense count: 1
Style/MethodMissing:
Exclude:
- 'lib/iiif_manifest/manifest_builder/composite_builder.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: MinSize, SupportedStyles.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets
15 changes: 12 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
desc 'Run style checker'
RuboCop::RakeTask.new(:rubocop) do |task|
task.fail_on_error = true
end

desc 'Run all checks'
task ci: [:rubocop, :spec]

task default: :ci
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "iiif_manifest"
require 'bundler/setup'
require 'iiif_manifest'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +10,5 @@ require "iiif_manifest"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start
31 changes: 17 additions & 14 deletions iiif_manifest.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'iiif_manifest/version'

Gem::Specification.new do |spec|
spec.name = "iiif_manifest"
spec.name = 'iiif_manifest'
spec.version = IIIFManifest::VERSION
spec.authors = ["Justin Coyne", "Trey Pendragon"]
spec.email = ["jcoyne@justincoyne.com"]
spec.authors = ['Justin Coyne', 'Trey Pendragon']
spec.email = ['jcoyne@justincoyne.com']

spec.summary = %q{Generate IIIF presentation manifests for Hydra::Works}
spec.description = %q{IIIF http://iiif.io/ defines an API for presenting related images in a viewer. This transforms Hydra::Works objects into that format usable by players such as http://universalviewer.io/}
spec.homepage = "http://github.com/projecthydra-labs/iiif_manifest"
spec.summary = 'Generate IIIF presentation manifests for Hydra::Works'
spec.description = 'IIIF http://iiif.io/ defines an API for presenting related images in a viewer. This transforms Hydra::Works objects into that format usable by players such as http://universalviewer.io/'
spec.homepage = 'http://github.com/projecthydra-labs/iiif_manifest'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency 'activesupport', '>= 4'
spec.add_dependency 'iiif-presentation', '~> 0.2.0'

spec.add_dependency "activesupport", ">= 4"
spec.add_dependency "iiif-presentation", '~> 0.2.0'

spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rubocop-rspec'
end
2 changes: 1 addition & 1 deletion lib/iiif_manifest.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "iiif_manifest/version"
require 'iiif_manifest/version'
require 'active_support'
require 'active_support/core_ext/module'
require 'active_support/core_ext/object'
Expand Down
2 changes: 1 addition & 1 deletion lib/iiif_manifest/iiif_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(url, profile: nil)
end

def context
"http://iiif.io/api/image/2/context.json"
'http://iiif.io/api/image/2/context.json'
end
end
end
16 changes: 8 additions & 8 deletions lib/iiif_manifest/manifest_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def initialize(work, builders:, top_record_factory:)
end

def apply(collection)
collection["manifests"] ||= []
collection["manifests"] << to_h
collection['manifests'] ||= []
collection['manifests'] << to_h
collection
end

Expand All @@ -33,12 +33,12 @@ def to_h

private

def manifest
@manifest ||= manifest_builder_class
end
def manifest
@manifest ||= manifest_builder_class
end

def top_record
top_record_factory.new
end
def top_record
top_record_factory.new
end
end
end
24 changes: 12 additions & 12 deletions lib/iiif_manifest/manifest_builder/canvas_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ def apply(sequence)

private

def display_image
record.display_image if record.respond_to?(:display_image)
end

def apply_record_properties
canvas['@id'] = path
canvas.label = record.to_s
end

def attach_image
ImageBuilder.new(display_image).apply(canvas)
end
def display_image
record.display_image if record.respond_to?(:display_image)
end

def apply_record_properties
canvas['@id'] = path
canvas.label = record.to_s
end

def attach_image
ImageBuilder.new(display_image).apply(canvas)
end
end
end
end
6 changes: 3 additions & 3 deletions lib/iiif_manifest/manifest_builder/canvas_builder_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def from(work)

private

def file_set_presenters(work)
work.file_set_presenters
end
def file_set_presenters(work)
work.file_set_presenters
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def each(&block)

private

def file_set_presenters
work.try(:file_set_presenters) || []
end
def file_set_presenters
work.try(:file_set_presenters) || []
end

def work_presenters
work.try(:work_presenters) || []
end
def work_presenters
work.try(:work_presenters) || []
end
end
end
end
18 changes: 9 additions & 9 deletions lib/iiif_manifest/manifest_builder/image_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ def apply(canvas)

private

def build_resource
resource_builder.apply(annotation)
end
def build_resource
resource_builder.apply(annotation)
end

def resource_builder
ResourceBuilder.new(display_image)
end
def resource_builder
ResourceBuilder.new(display_image)
end

def annotation
@annotation ||= IIIF::Presentation::Annotation.new
end
def annotation
@annotation ||= IIIF::Presentation::Annotation.new
end
end
end
end
6 changes: 3 additions & 3 deletions lib/iiif_manifest/manifest_builder/image_service_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def apply(resource)

private

def service
@service ||= IIIF::Service.new
end
def service
@service ||= IIIF::Service.new
end
end
end
end
6 changes: 3 additions & 3 deletions lib/iiif_manifest/manifest_builder/record_property_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def apply(manifest)

private

def viewing_hint
(record.respond_to?(:viewing_hint) && record.send(:viewing_hint)) || 'individuals'
end
def viewing_hint
(record.respond_to?(:viewing_hint) && record.send(:viewing_hint)) || 'individuals'
end

# def viewing_direction
# record.try(:viewing_direction) || "left-to-right"
Expand Down
18 changes: 9 additions & 9 deletions lib/iiif_manifest/manifest_builder/resource_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ def apply(annotation)

private

def resource
@resource ||= IIIF::Presentation::Resource.new
end
def resource
@resource ||= IIIF::Presentation::Resource.new
end

def iiif_endpoint
display_image.try(:iiif_endpoint)
end
def iiif_endpoint
display_image.try(:iiif_endpoint)
end

def image_service_builder
ImageServiceBuilder.new(iiif_endpoint)
end
def image_service_builder
ImageServiceBuilder.new(iiif_endpoint)
end
end
end
end
24 changes: 12 additions & 12 deletions lib/iiif_manifest/manifest_builder/sequence_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ def empty?

private

def canvas_builder
canvas_builder_factory.from(work)
end
def canvas_builder
canvas_builder_factory.from(work)
end

def sequence
@sequence ||=
begin
sequence = IIIF::Presentation::Sequence.new
sequence["@id"] ||= work.manifest_url + "/sequence/normal"
canvas_builder.apply(sequence)
sequence
end
end
def sequence
@sequence ||=
begin
sequence = IIIF::Presentation::Sequence.new
sequence['@id'] ||= work.manifest_url + '/sequence/normal'
canvas_builder.apply(sequence)
sequence
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/iiif_manifest/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module IIIFManifest
VERSION = "0.2.0"
VERSION = '0.2.0'.freeze
end
Loading

0 comments on commit 717ec35

Please sign in to comment.