Class: Eco::API::Common::BaseLoader

Inherits:
Object
  • Object
show all
Extended by:
ClassHelpers
Defined in:
lib/eco/api/common/base_loader.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassHelpers

class_resolver, descendants, descendants?, new_class, resolve_class, to_constant

Constructor Details

#initializeBaseLoader

Note:
  • this method should implement the loading logics for the given Children class.

This method will be called when the BaseLoader is created



43
44
45
# File 'lib/eco/api/common/base_loader.rb', line 43

def initialize
  raise "You should implement this method"
end

Class Attribute Details

.name(value = nil) ⇒ Object

The name that this case, policy or error handler will have.



11
12
13
14
15
16
# File 'lib/eco/api/common/base_loader.rb', line 11

def name(value = nil)
  name_only_once! if value
  set_created_at!
  return @name ||= self.to_s unless value
  @name = value
end

.type=(value) ⇒ Object (writeonly)

Sets the attribute type

Parameters:

  • value

    the value to set the attribute type to.



8
9
10
# File 'lib/eco/api/common/base_loader.rb', line 8

def type=(value)
  @type = value
end

Class Method Details

.<=>(other) ⇒ Object

Sort order



19
20
21
# File 'lib/eco/api/common/base_loader.rb', line 19

def <=>(other)
  created_at <=> other.created_at
end

.created_atObject

Class creation timestamp, to be able to load them in the order they were declared.



29
30
31
# File 'lib/eco/api/common/base_loader.rb', line 29

def created_at
  @created_at ||= Time.now
end

.name_only_once!Object

Prevent the same class to be re-opened/re-named



34
35
36
# File 'lib/eco/api/common/base_loader.rb', line 34

def name_only_once!
  raise "You have already declared #{self} or you are trying to give it a name twice" if @name
end

.set_created_at!Object

If still not set, it sets the created_at class timestamp.



24
25
26
# File 'lib/eco/api/common/base_loader.rb', line 24

def set_created_at!
  @created_at = Time.now unless @created_at
end

Instance Method Details

#nameObject



47
48
49
# File 'lib/eco/api/common/base_loader.rb', line 47

def name
  self.class.name
end