Module: Treat::Entities::Entity::Checkable

Included in:
Treat::Entities::Entity
Defined in:
lib/treat/entities/entity/checkable.rb

Overview

This module implements methods that are used by workers to determine if an entity is properly formatted before working on it.

Instance Method Summary collapse

Instance Method Details

#check_has(feature, do_it = true) ⇒ Object

Check if the entity has the given feature, and if so return it. If not, calculate the requested feature if do_it is set to true, or raise an exception if do_it is set to false.

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/treat/entities/entity/checkable.rb', line 10

def check_has(feature, do_it = true)
  return @features[feature] if has?(feature)
  return send(feature) if do_it
  task = caller_method(2) # This is dangerous !
  g1 = Treat::Workers.lookup(task)
  g2 = Treat::Workers.lookup(feature)

  raise Treat::Exception,
  "#{g1.type.to_s.capitalize} " +
  "requires #{g2.type} #{g2.method}."
end

#check_hasnt_childrenObject

Raises an error if the entity has children.

Raises:



23
24
25
26
27
28
29
# File 'lib/treat/entities/entity/checkable.rb', line 23

def check_hasnt_children
  return unless has_children?
  raise Treat::Exception,
  "Warning: can't #{caller_method(2)} "+
  "the text \"#{short_value}\", because it " +
  "already has children."
end