Class: Ecoportal::API::V2::Page::Component::ActionField
- Inherits:
-
Ecoportal::API::V2::Page::Component
- Object
- Common::BaseModel
- Common::Content::DoubleModel
- Ecoportal::API::V2::Page::Component
- Ecoportal::API::V2::Page::Component::ActionField
- Defined in:
- lib/ecoportal/api/v2/page/component/action_field.rb
Constant Summary
Constants included from Common::Content::StringDigest
Common::Content::StringDigest::MAX_HASH_LABEL
Constants included from Common::Content::DoubleModel::Diffable
Common::Content::DoubleModel::Diffable::DIFF_CLASS
Constants included from Common::Content::DoubleModel::Base
Common::Content::DoubleModel::Base::NOT_USED
Instance Attribute Summary
Attributes included from Common::Content::DoubleModel::Parented
Instance Method Summary collapse
-
#add_task(name) ⇒ Ecoportal::API::V2::Page::Component::Action
Adds a task with
nameshort description. -
#configure(*conf) ⇒ Object
Quick config helper.
- #empty? ⇒ Boolean
- #ordered_tasks ⇒ Object
- #to_s(delimiter: "\n") ⇒ Object
Methods inherited from Ecoportal::API::V2::Page::Component
#attached?, #bindings, #bindings?, #delete!, #forces, get_class, #indexable_label, #move, #multi_section?, new_doc, #ooze, #ref, #ref_backend, #replace, #replace_bindings, #section, #unattach!
Methods included from Common::Content::StringDigest
Methods inherited from Common::Content::DoubleModel
Methods included from Common::Content::DoubleModel::Diffable
Methods included from Common::Content::Includer
Constructor Details
This class inherits a constructor from Ecoportal::API::Common::Content::DoubleModel
Instance Method Details
#add_task(name) ⇒ Ecoportal::API::V2::Page::Component::Action
Adds a task with name short description
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 20 def add_task(name) task_doc = actions.items_class.new_doc actions.upsert!(task_doc) do |task| task.name = name if (prev = previous_task(task)) task.weight = prev.weight end yield(task) if block_given? fix_task_weights! end end |
#configure(*conf) ⇒ Object
Quick config helper
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 49 def configure(*conf) self.create_actions = true conf.each_with_object([]) do |cnf, unused| case cnf when Hash supported = [:requires] unless (rest = hash_except!(cnf.dup, *supported)).empty? unused.push(rest) end configure_required(cnf[:requires]) if cnf.key?(:requires) else unused.push(cnf) end end.then do |unused| super(*unused) end end |
#empty? ⇒ Boolean
14 15 16 |
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 14 def empty? actions.empty? end |
#ordered_tasks ⇒ Object
34 35 36 37 38 |
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 34 def ordered_tasks actions.sort_by.with_index do |task, index| [task.weight, index] end end |
#to_s(delimiter: "\n") ⇒ Object
40 41 42 |
# File 'lib/ecoportal/api/v2/page/component/action_field.rb', line 40 def to_s(delimiter: "\n") ordered_tasks.map(&:to_s).join(delimiter) end |