Class: ActiveFedora::Associations::SingularAssociation
- Inherits:
-
Association
- Object
- Association
- ActiveFedora::Associations::SingularAssociation
- Defined in:
- lib/active_fedora/associations/singular_association.rb
Overview
:nodoc:
Direct Known Subclasses
BasicContainsAssociation, BelongsToAssociation, DirectlyContainsOneAssociation, RDF
Instance Attribute Summary
Attributes inherited from Association
#inversed, #owner, #reflection, #target
Instance Method Summary collapse
- #build(attributes = {}) ⇒ Object
- #create(attributes = {}) ⇒ Object
- #create!(attributes = {}) ⇒ Object
-
#reader(force_reload = false) ⇒ Object
Implements the reader method, e.g.
-
#writer(record) ⇒ Object
Implements the writer method, e.g.
Methods inherited from Association
#association_scope, #initialize, #initialize_attributes, #load_target, #loaded!, #loaded?, #reload, #reset, #scope, #set_inverse_instance, #stale_target?, #target_scope
Constructor Details
This class inherits a constructor from ActiveFedora::Associations::Association
Instance Method Details
#build(attributes = {}) ⇒ Object
28 29 30 |
# File 'lib/active_fedora/associations/singular_association.rb', line 28 def build(attributes = {}) new_record(:build, attributes) end |
#create(attributes = {}) ⇒ Object
20 21 22 |
# File 'lib/active_fedora/associations/singular_association.rb', line 20 def create(attributes = {}) new_record(:create, attributes) end |
#create!(attributes = {}) ⇒ Object
24 25 26 |
# File 'lib/active_fedora/associations/singular_association.rb', line 24 def create!(attributes = {}) build(attributes).tap(&:save!) end |
#reader(force_reload = false) ⇒ Object
Implements the reader method, e.g. foo.bar for Foo.has_one :bar
5 6 7 8 9 10 11 12 13 |
# File 'lib/active_fedora/associations/singular_association.rb', line 5 def reader(force_reload = false) if force_reload raise NotImplementedError, "Need to define the uncached method" # TODO # klass.uncached { reload } elsif !loaded? || stale_target? reload end target end |
#writer(record) ⇒ Object
Implements the writer method, e.g. foo.items= for Foo.has_many :items
16 17 18 |
# File 'lib/active_fedora/associations/singular_association.rb', line 16 def writer(record) replace(record) end |