Sha256: 4d7b666f4ef8e4ce533ef48c4f518cce7503bd956f248f8dad3f966c1014281a

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Lite
  module Command
    module Internals
      module Context

        def self.included(base)
          base.extend ClassMethods
        end

        module ClassMethods

          def attribute(*args, **options)
            args.each do |method_name|
              attributes[method_name] = options

              define_method(method_name) do
                ivar = :"@#{method_name}"
                return instance_variable_get(ivar) if instance_variable_defined?(ivar)

                attribute = Lite::Command::Attribute.new(self, method_name, options)
                instance_variable_set(ivar, attribute.value)
              end
            end
          end

          def attributes
            @attributes ||= {}
          end

        end

        private

        def validate_context_attributes
          validator = Lite::Command::AttributeValidator.new(self)
          return if validator.valid?

          invalid!("Invalid context attributes", validator.errors)
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lite-command-2.1.0 lib/lite/command/internals/context.rb