Skip to content

Commit

Permalink
Use OpenStruct instead of implementing our own version
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Oct 4, 2022
1 parent 657ff47 commit 8b40058
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions lib/arclight/repository.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# frozen_string_literal: true

require 'ostruct'

module Arclight
#
# Static information about a given repository identified by a unique `slug`
#
class Repository
# rubocop:disable Style/OpenStructUse
class Repository < OpenStruct
include ActiveModel::Conversion # for to_partial_path

attr_accessor :name, :slug, :collection_count

# @param [String] `slug` the unique identifier for the repository
# @param [Hash] `data`
def initialize(slug, data = {})
@slug = slug
data.each do |field, value|
self.class.attr_accessor field.to_sym
send("#{field}=", value) if value.present?
end
super(**data, slug: slug)
end

# @return [String] handles the formatting of "city, state zip, country"
Expand Down Expand Up @@ -124,4 +120,5 @@ def self.find_by!(**kwargs)
repository
end
end
# rubocop:enable Style/OpenStructUse
end
2 changes: 1 addition & 1 deletion spec/helpers/arclight_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
context 'when searching within a repository' do
before do
expect(helper).to receive_messages(
repository_faceted_on: instance_double(Arclight::Repository, name: 'Repository Name')
repository_faceted_on: Arclight::Repository.new(nil, name: 'Repository Name')
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/arclight/document_downloads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
context 'when a template is provided for the href' do
before do
allow(document).to receive(:repository_config).and_return(
instance_double(Arclight::Repository, slug: 'the-repo-id')
Arclight::Repository.new('the-repo-id')
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/views/repositories/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
end

it 'does not show on repositories detail page' do
assign(:repository, instance_double(Arclight::Repository, name: 'My Repository'))
assign(:repository, Arclight::Repository.new(nil, name: 'My Repository'))
allow(view).to receive(:on_repositories_index?).and_return(false)
allow(view).to receive(:on_repositories_show?).and_return(true)
render
Expand Down

0 comments on commit 8b40058

Please sign in to comment.