Class: ActiveShrine::Attached::Changes::CreateOne

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shrine/attached/changes/create_one.rb

Overview

:nodoc:

Direct Known Subclasses

CreateOneOfMany

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, record, attachable) ⇒ CreateOne

Returns a new instance of CreateOne.



12
13
14
15
16
17
18
# File 'lib/active_shrine/attached/changes/create_one.rb', line 12

def initialize(name, record, attachable)
  @name = name
  @record = record
  @attachable = attachable

  attach
end

Instance Attribute Details

#attachableObject (readonly)

Returns the value of attribute attachable.



10
11
12
# File 'lib/active_shrine/attached/changes/create_one.rb', line 10

def attachable
  @attachable
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/active_shrine/attached/changes/create_one.rb', line 10

def name
  @name
end

#recordObject (readonly)

Returns the value of attribute record.



10
11
12
# File 'lib/active_shrine/attached/changes/create_one.rb', line 10

def record
  @record
end

Instance Method Details

#attachmentObject



20
21
22
# File 'lib/active_shrine/attached/changes/create_one.rb', line 20

def attachment
  @attachment ||= find_or_build_attachment
end

#saveObject



24
25
26
# File 'lib/active_shrine/attached/changes/create_one.rb', line 24

def save
  record.public_send(:"#{name}_attachment=", attachment)
end