Skip to content

Commit

Permalink
Renamed name_for_dsid to method_name_for_path
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 11, 2014
1 parent 5225e6a commit 9bfd6be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions lib/active_fedora/attached_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def ds_specs
deprecation_deprecate :ds_specs

def serialize_attached_files
attached_files.each {|k, ds| ds.serialize! }
attached_files.each_value {|file| file.serialize! }
end

#
Expand Down Expand Up @@ -210,18 +210,18 @@ def has_file_datastream(*args)
end
deprecation_deprecate :has_file_datastream

def build_datastream_accessor(dsid)
name = name_for_dsid(dsid)
def build_datastream_accessor(path_name)
name = method_name_for_path(path_name)
define_method name do
attached_files[dsid]
attached_files[path_name]
end
end

private

## Given a dsid return a standard name
def name_for_dsid(dsid)
dsid.gsub('-', '_')
## Given a path_name return a valid method name
def method_name_for_path(path_name)
path_name.to_s.gsub('-', '_')
end

end
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/attached_files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ class FooHistory < ActiveFedora::Base
end
end

describe ".name_for_dsid" do
describe ".method_name_for_path" do
it "should use the name" do
expect(ActiveFedora::Base.send(:name_for_dsid, 'abc')).to eq 'abc'
expect(ActiveFedora::Base.send(:method_name_for_path, 'abc')).to eq 'abc'
end

it "should use the name" do
expect(ActiveFedora::Base.send(:name_for_dsid, 'ARCHIVAL_XML')).to eq 'ARCHIVAL_XML'
expect(ActiveFedora::Base.send(:method_name_for_path, 'ARCHIVAL_XML')).to eq 'ARCHIVAL_XML'
end

it "should use the name" do
expect(ActiveFedora::Base.send(:name_for_dsid, 'descMetadata')).to eq 'descMetadata'
expect(ActiveFedora::Base.send(:method_name_for_path, 'descMetadata')).to eq 'descMetadata'
end

it "should hash-erize underscores" do
expect(ActiveFedora::Base.send(:name_for_dsid, 'a-b')).to eq 'a_b'
expect(ActiveFedora::Base.send(:method_name_for_path, 'a-b')).to eq 'a_b'
end
end

Expand Down

0 comments on commit 9bfd6be

Please sign in to comment.