Sha256: 6ff9c8f17cb79973d94c94ae98678eef1e71463c3c363a7a9053c49b9257d030

Contents?: true

Size: 744 Bytes

Versions: 3

Compression:

Stored size: 744 Bytes

Contents

module PushType
  class MatrixField < PushType::FieldType

    options json_primitive: :array,
            template:       'matrix'

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

    def value
      return if json_value.blank?
      rows
    end

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

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

    def structure
      @structure ||= structure_class.new
    end

    private

    def structure_class
      @structure_class ||= Class.new PushType::Structure do
        define_singleton_method(:name) { "PushType::Structure" }
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
push_type_core-0.6.0 app/fields/push_type/matrix_field.rb
push_type_core-0.6.0.beta.4 app/fields/push_type/matrix_field.rb
push_type_core-0.6.0.beta.3 app/fields/push_type/matrix_field.rb