Sha256: c0b2d80738b740c83639acc030a59a0985adeeb2769d6bedd244fa1216ff4fe6

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'fiona7/builder/obj_builder'
require 'fiona7/builder/widget_building'

module Fiona7
  module Builder
    class WidgetBuilder < ObjBuilder
      include WidgetBuilding
      def initialize(owner_obj, widget_id, values, path_map)
        @owner_obj, @widget_id, @values, @widget_path_map = owner_obj, widget_id, values.symbolize_keys, path_map
      end

      protected
      def update?
        false
      end

      def write_widget_pool
        true
      end

      def widgets_gc
        true
      end

      def prepare_object
        @path              = self.generate_widget_path
        @obj_class         = @values.delete(:_obj_class)
        @real_obj_class    = Fiona7::ObjClassNameMangler.new(@obj_class).mangle

        @path = "/#{@path}" unless @path.start_with?('/')
        @name, parent_path = name_and_parent_path_from_path(@path)
        @parent            = ensure_parent_exists(parent_path) if parent_path

        ensure_obj_class_exists

        # bottom one is faster, but can only work when there are no uploads
        if (@values.any? {|_, (_, v)| v.kind_of?(File) || v.kind_of?(ActionDispatch::Http::UploadedFile) } )
          @obj = WriteObj.create!(name: @name, parent_obj_id: @parent.id, obj_class: @real_obj_class)
        else
          @obj = WriteObj.new(name: @name, parent_obj_id: @parent.id, obj_class: @real_obj_class)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
infopark_fiona7-1.5.5.5.1 lib/fiona7/builder/widget_builder.rb
infopark_fiona7-1.5.5.5.0 lib/fiona7/builder/widget_builder.rb
infopark_fiona7-1.5.5.4.1 lib/fiona7/builder/widget_builder.rb
infopark_fiona7-1.5.5.4.0 lib/fiona7/builder/widget_builder.rb