Sha256: 2b1ff1721546b238086d0c730767b5ee762896e30c9d0030d48644edf7a80376

Contents?: true

Size: 1.68 KB

Versions: 7

Compression:

Stored size: 1.68 KB

Contents

module Ecoportal
  module API
    class V2
      class Page
        class Force < Common::Content::DoubleModel
          INITIAL_WEIGHT = 9999

          class << self
            def new_doc
              {
                "id"     => new_uuid,
                "weight" => INITIAL_WEIGHT
              }
            end
          end

          class_resolver :bindings_class, "Ecoportal::API::V2::Page::Force::Bindings"
          class_resolver :helper_class, "Ecoportal::API::V2::Page::Force::Helper"

          passkey     :id
          passforced  :patch_ver, default: 1
          passthrough :name, :weight
          passdate    :last_synced_at
          passthrough :custom_script
          passthrough :script, read_only: true
          embeds_many :bindings, enum_class: :bindings_class
          embeds_many :helpers, klass: :helper_class

          def ooze
            _parent.ooze
          end

          # @see Ecoportal::API::V2::Page::Force::Bindings#add
          def bind(reference, **kargs, &block)
            bindings.add(reference, **kargs, &block)
          end

          # It updates `script` by using `helpers`
          def custom_script=(value)
            doc["custom_script"] = value
            update_script
          end

          # It sets the `script` value by using `custom_script` and `helpers[N..1].script`
          def update_script
            doc["script"] = helpers.to_a.reverse.map(&:script).push(custom_script).join("\n")
          end
        end
      end
    end
  end
end

require 'ecoportal/api/v2/page/force/helper'
require 'ecoportal/api/v2/page/force/binding'
require 'ecoportal/api/v2/page/force/bindings'

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ecoportal-api-v2-2.0.6 lib/ecoportal/api/v2/page/force.rb
ecoportal-api-v2-2.0.5 lib/ecoportal/api/v2/page/force.rb
ecoportal-api-v2-2.0.4 lib/ecoportal/api/v2/page/force.rb
ecoportal-api-v2-2.0.3 lib/ecoportal/api/v2/page/force.rb
ecoportal-api-v2-2.0.2 lib/ecoportal/api/v2/page/force.rb
ecoportal-api-v2-2.0.1 lib/ecoportal/api/v2/page/force.rb
ecoportal-api-v2-2.0.0 lib/ecoportal/api/v2/page/force.rb