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 180ef48
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 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
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
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

0 comments on commit 180ef48

Please sign in to comment.