Sha256: af622b23525701915d047975a71ce7903b6fdda6ed43b4ec7928cada536d6b42

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module Ecoportal
  module API
    class V2
      class Page
        class Components < Common::Content::CollectionModel
          class_resolver :component_class, "Ecoportal::API::V2::Page::Component"

          self.klass do |doc|
            component_class.get_class(doc).tap do |klass|
              klass.key = :id
            end
          end

          order_matters = true

          def get_by_type(type)
            self.select do |comp|
              comp.type.downcase == type.to_s.strip.downcase
            end
          end

          def get_by_name(name, type: nil)
            pool = type ? get_by_type(type) : self

            pool.select do |comp|
              comp.label.to_s.strip.downcase == name.to_s.strip.downcase
            end.first
          end

          def add(label:, type:)
            fld_doc = component_class.new_doc(type: type)
            upsert!(fld_doc) do |fld|
              fld.label  = label
              yield(fld) if block_given?
            end
          end

        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ecoportal-api-v2-0.8.8 lib/ecoportal/api/v2/page/components.rb
ecoportal-api-v2-0.8.7 lib/ecoportal/api/v2/page/components.rb
ecoportal-api-v2-0.8.6 lib/ecoportal/api/v2/page/components.rb
ecoportal-api-v2-0.8.5 lib/ecoportal/api/v2/page/components.rb
ecoportal-api-v2-0.8.4 lib/ecoportal/api/v2/page/components.rb
ecoportal-api-oozes-0.7.5 lib/ecoportal/api/v2/page/components.rb
ecoportal-api-oozes-0.7.4 lib/ecoportal/api/v2/page/components.rb