Class: PushType::MatrixField

Inherits:
FieldType show all
Defined in:
app/fields/push_type/matrix_field.rb

Instance Attribute Summary

Attributes inherited from FieldType

#model, #name

Instance Method Summary collapse

Methods inherited from FieldType

#css_class, #field_options, #form_helper, #html_options, #json_primitive, #json_value, #kind, #label, #multiple?, on_class, on_instance, options, #primitive, #template

Constructor Details

#initialize(*args, &block) ⇒ MatrixField

Returns a new instance of MatrixField.



8
9
10
11
# File 'app/fields/push_type/matrix_field.rb', line 8

def initialize(*args, &block)
  super
  structure_class.class_eval(&block) if block
end

Instance Method Details

#fieldsObject



18
19
20
# File 'app/fields/push_type/matrix_field.rb', line 18

def fields
  @fields ||= structure_class.new.fields
end

#grid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/fields/push_type/matrix_field.rb', line 22

def grid?
  !!@opts[:grid]
end

#rowsObject



26
27
28
29
30
# File 'app/fields/push_type/matrix_field.rb', line 26

def rows
  Array(json_value).map do |h|
    structure_class.new(field_store: h)
  end
end

#structureObject



32
33
34
# File 'app/fields/push_type/matrix_field.rb', line 32

def structure
  @structure ||= structure_class.new
end

#valueObject



13
14
15
16
# File 'app/fields/push_type/matrix_field.rb', line 13

def value
  return if json_value.blank?
  rows.reject(&:blank?)
end