lib/ecoportal/api/v2/page/components.rb in ecoportal-api-v2-1.1.7 vs lib/ecoportal/api/v2/page/components.rb in ecoportal-api-v2-1.1.8
- old
+ new
@@ -3,32 +3,32 @@
class V2
class Page
class Components < Common::Content::CollectionModel
class_resolver :component_class, "Ecoportal::API::V2::Page::Component"
- self.klass do |doc|
+ klass do |doc|
component_class.get_class(doc).tap do |klass|
klass.key = :id
end
end
- order_matters = true
+ #self.order_matters = true
def ooze
- self._parent.ooze
+ _parent.ooze
end
# @return [Ecoportal::API::V2::Page::Component] the field with `id`
def get_by_id(id)
- self.find do |comp|
+ find do |comp|
comp.id == id
end
end
# @return [Array<Ecoportal::API::V2::Page::Component>] the fields of that `type`
def get_by_type(type)
- self.select do |comp|
+ select do |comp|
comp.type.downcase == type.to_s.strip.downcase
end
end
# @param name [String, Regexp] the `name` to search the field based on their `label`
@@ -51,22 +51,22 @@
# @yieldparam [Ecoportal::API::V2::Page::Component] the created field
# @return [Ecoportal::API::V2::Page::Component] the created field.
def add(doc: nil, label: doc && doc["label"], type: doc && doc["type"])
fld_doc = doc ? JSON.parse(doc.to_json) : component_class.new_doc(type: type)
upsert!(fld_doc) do |fld|
- fld.label = label if !doc
- yield(fld) if block_given?
+ fld.label = label unless doc
+ yield(fld) if block_given?
end
end
# @return [Array<Ecoportal::API::V2::Page::Component>] **orphaned** fields (with no section).
def unattached
- select {|comp| !comp.attached?}
+ reject(&:attached?)
end
# @return [Array<Ecoportal::API::V2::Page::Component>] fields belonging to more than one section.
def multi_section
- select {|comp| comp.multi_section?}
+ select(&:multi_section?)
end
end
end
end
end