Sha256: b30f7051b92dc9490c13ae76c88d914707a0d8cb3d661f36d9c86f3e9eeaad89

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 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            = ContainerChainBuilder.new(parent_path).call

        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

3 entries across 3 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/builder/widget_builder.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/builder/widget_builder.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/builder/widget_builder.rb