Class: Eco::API::Common::BaseLoader
- Inherits:
-
Object
- Object
- Eco::API::Common::BaseLoader
- Extended by:
- ClassHelpers
- Defined in:
- lib/eco/api/common/base_loader.rb
Direct Known Subclasses
Loaders::ErrorHandler, Loaders::Parser, Loaders::Policy, Loaders::UseCase
Class Attribute Summary collapse
-
.name(value = nil) ⇒ Object
The name that this case, policy or error handler will have.
-
.type ⇒ Object
writeonly
Sets the attribute type.
Class Method Summary collapse
-
.<=>(other) ⇒ Object
Sort order.
-
.created_at ⇒ Object
Class creation timestamp, to be able to load them in the order they were declared.
-
.name_only_once! ⇒ Object
Prevent the same class to be re-opened/re-named.
-
.set_created_at! ⇒ Object
If still not set, it sets the
created_at
class timestamp.
Instance Method Summary collapse
-
#initialize ⇒ BaseLoader
constructor
This method will be called when the BaseLoader is created.
- #name ⇒ Object
Methods included from ClassHelpers
class_resolver, descendants, descendants?, new_class, resolve_class, to_constant
Constructor Details
#initialize ⇒ BaseLoader
- 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
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_at ⇒ Object
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
#name ⇒ Object
47 48 49 |
# File 'lib/eco/api/common/base_loader.rb', line 47 def name self.class.name end |