Module: Motr::Cargo::Context

Extended by:
ActiveSupport::Concern
Defined in:
lib/motr/cargo/context.rb,
lib/motr/cargo/context/mongoid.rb

Overview

Defines base functionality for contexts When applied a package will accept_nested_attributes_for :context_name, and each context will ensure that, when created, it sets its position to the end of the context list.

Defined Under Namespace

Modules: Mongoid

Instance Method Summary collapse

Instance Method Details

#context_nameObject

Defines a name to represent the context. When the name attribute is set, it is used, if not the class name is used.



64
65
66
# File 'lib/motr/cargo/context.rb', line 64

def context_name
  (self.name.blank? ? self.class.name : self.name)
end

#ensure_context_position_valueObject

Ensure new contexts are added to the end of the context list.



55
56
57
58
# File 'lib/motr/cargo/context.rb', line 55

def ensure_context_position_value
  return true unless self.position.nil?
  self.position = _parent.send(:"#{self.class.name.pluralize.underscore}").count + 1
end