Skip to content

Commit

Permalink
Merge pull request #396 from no-reply/feature/class-constantize
Browse files Browse the repository at this point in the history
Enabled class_name constantization on access
  • Loading branch information
jcoyne committed Apr 11, 2014
2 parents 109fd5b + 088a4fd commit 9baee16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/active_fedora/rdf/node_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ def [](value)
self.respond_to?(value) ? self.send(value) : nil
end

def class_name
if @class_name.kind_of?(String)
begin
new_class = @class_name.constantize
@class_name = new_class
rescue NameError
end
end
@class_name
end

def with_index (&block)
# needed for solrizer integration
iobj = IndexObject.new
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/rdf_properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class DummyProperties
DummyProperties.property :title, :predicate => RDF::DC.title, :class_name => RDF::Literal
expect(DummyProperties.properties[:title][:class_name]).to eq RDF::Literal
end

it "should constantize string class names" do
DummyProperties.property :title, :predicate => RDF::DC.title, :class_name => "RDF::Literal"
expect(DummyProperties.properties[:title][:class_name]).to eq RDF::Literal
end

it "should keep strings which it can't constantize as strings" do
DummyProperties.property :title, :predicate => RDF::DC.title, :class_name => "FakeClassName"
expect(DummyProperties.properties[:title][:class_name]).to eq "FakeClassName"
end

end

context "when using a subclass" do
Expand Down

0 comments on commit 9baee16

Please sign in to comment.