Sha256: 9963d678630b409d2a4b3e108e4d3ccad277a1f32d01f613b49058bfb64706f1

Contents?: true

Size: 815 Bytes

Versions: 20

Compression:

Stored size: 815 Bytes

Contents

# frozen_string_literal: true

require "ostruct" unless defined?(OpenStruct)

module Lite
  module Command
    class Context < OpenStruct

      def self.build(attributes = {})
        return attributes if attributes.is_a?(self) && !attributes.frozen?

        # To save memory and speed up the access to an attribute, the accessor methods
        # of an attribute are lazy loaded at certain points. This means that the methods
        # are defined only when a set of defined actions are triggered. This allows context
        # to only define the minimum amount of required methods to make your data structure work
        os = new(attributes.to_h)
        os.methods(false)
        os
      end

      def merge!(attributes = {})
        attributes.to_h.each { |k, v| self[k] = v }
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
lite-command-3.3.3 lib/lite/command/context.rb
lite-command-3.3.2 lib/lite/command/context.rb
lite-command-3.3.1 lib/lite/command/context.rb
lite-command-3.3.0 lib/lite/command/context.rb
lite-command-3.2.1 lib/lite/command/context.rb
lite-command-3.2.0 lib/lite/command/context.rb
lite-command-3.1.5 lib/lite/command/context.rb
lite-command-3.1.4 lib/lite/command/context.rb
lite-command-3.1.3 lib/lite/command/context.rb
lite-command-3.1.2 lib/lite/command/context.rb
lite-command-3.1.1 lib/lite/command/context.rb
lite-command-3.1.0 lib/lite/command/context.rb
lite-command-3.0.1 lib/lite/command/context.rb
lite-command-3.0.0 lib/lite/command/context.rb
lite-command-2.1.3 lib/lite/command/context.rb
lite-command-2.1.2 lib/lite/command/context.rb
lite-command-2.1.1 lib/lite/command/context.rb
lite-command-2.1.0 lib/lite/command/context.rb
lite-command-2.0.3 lib/lite/command/context.rb
lite-command-2.0.2 lib/lite/command/context.rb