Sha256: 0c5c06a3d6ed53b9cb53b60e93f50f5a2ae153ae62807390397f8b5ccde112b6

Contents?: true

Size: 1.47 KB

Versions: 29

Compression:

Stored size: 1.47 KB

Contents

module Eco
  module API
    module Common
      class BaseLoader
        extend Eco::API::Common::ClassHelpers

        class << self
          attr_writer :name, :type

          # The name that this case, policy or error handler will have.
          def name(value = nil)
            name_only_once! if value
            set_created_at!
            return @name ||= self.to_s unless value
            @name = value
          end

          # Sort order
          def <=>(other)
            created_at <=> other.created_at
          end

          # If still not set, it sets the `created_at` class timestamp.
          def set_created_at!
            @created_at = Time.now unless @created_at
          end

          # Class creation timestamp, to be able to load them in the order they were declared.
          def created_at
            @created_at ||= Time.now
          end

          # Prevent the same class to be re-opened/re-named
          def name_only_once!
            raise "You have already declared #{self} or you are trying to give it a name twice" if @name
          end

        end

        # This method will be called when the BaseLoader is created
        # @note
        #   - this method should implement the loading logics for the given `Children` class.
        def initialize
          raise "You should implement this method"
        end

        def name
          self.class.name
        end

      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
eco-helpers-2.0.16 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.15 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.14 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.13 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.12 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.11 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.10 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.9 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.8 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.7 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.6 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.5 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.4 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.3 lib/eco/api/common/base_loader.rb
eco-helpers-2.0.2 lib/eco/api/common/base_loader.rb
eco-helpers-1.5.15 lib/eco/api/common/base_loader.rb
eco-helpers-1.5.14 lib/eco/api/common/base_loader.rb
eco-helpers-1.5.13 lib/eco/api/common/base_loader.rb
eco-helpers-1.5.12 lib/eco/api/common/base_loader.rb
eco-helpers-1.5.11 lib/eco/api/common/base_loader.rb