Class: Bulldog::Attachment::Maybe::StorableAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/bulldog/attachment/maybe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ StorableAttribute

Returns a new instance of StorableAttribute.



230
231
232
233
234
# File 'lib/bulldog/attachment/maybe.rb', line 230

def initialize(attributes)
  attributes.each do |name, value|
    send("#{name}=", value)
  end
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



251
252
253
# File 'lib/bulldog/attachment/maybe.rb', line 251

def callback
  @callback
end

#castObject Also known as: cast?

Returns the value of attribute cast.



251
252
253
# File 'lib/bulldog/attachment/maybe.rb', line 251

def cast
  @cast
end

#memoizeObject Also known as: memoize?

Returns the value of attribute memoize.



251
252
253
# File 'lib/bulldog/attachment/maybe.rb', line 251

def memoize
  @memoize
end

#nameObject

Returns the value of attribute name.



251
252
253
# File 'lib/bulldog/attachment/maybe.rb', line 251

def name
  @name
end

#per_styleObject Also known as: per_style?

Returns the value of attribute per_style.



251
252
253
# File 'lib/bulldog/attachment/maybe.rb', line 251

def per_style
  @per_style
end

Instance Method Details

#value_for(attachment, style_name) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/bulldog/attachment/maybe.rb', line 236

def value_for(attachment, style_name)
  value =
    if callback.is_a?(Proc)
      callback.call(attachment)
    else
      if per_style?
        attachment.send(callback, style_name)
      else
        attachment.send(callback)
      end
    end
  value = attachment.send("serialize_#{name}", value) if cast
  value
end