Class: Scribo::FormDrop

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
app/drops/scribo/form_drop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, attribute = nil) ⇒ FormDrop

Returns a new instance of FormDrop.



5
6
7
8
# File 'app/drops/scribo/form_drop.rb', line 5

def initialize(model, attribute = nil)
  @model     = model
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



10
11
12
# File 'app/drops/scribo/form_drop.rb', line 10

def attribute
  @attribute
end

#modelObject (readonly)

Returns the value of attribute model.



10
11
12
# File 'app/drops/scribo/form_drop.rb', line 10

def model
  @model
end

Instance Method Details

#class_nameObject



12
13
14
# File 'app/drops/scribo/form_drop.rb', line 12

def class_name
  model.class.name.gsub(/Drop$/, '')
end

#errorsObject



16
17
18
19
20
21
22
23
24
# File 'app/drops/scribo/form_drop.rb', line 16

def errors
  errors = if @model&.instance_variable_get('@object')
             @model.instance_variable_get('@object').errors
           else
             ::ActiveModel::Errors.new([])
           end

  ::Scribo::ActiveModel::ErrorsDrop.new errors
end