File: environment/context/value/entry.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Environment#8
  module: Context#10
  module: Value#12
has properties
function: make_bindings / 2 #78
  class: Entry#14
inherits from
  Abstract ( Umu::Environment::Context::Value )
has properties
attribute: bindings [R] #15
attribute: old_context [R] #16
method: initialize / 2 #19
method: get_bindings #28
method: get_bindings_difference_with / 1 #35
method: __extend__ / 2 #62

Class Hierarchy

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module Environment
   9 
  10  module Context
  11 
  12  module Value
  13 
  14  class Entry < Abstract
  15      attr_reader :bindings
  16      attr_reader :old_context
  17 
  18 
  19      def initialize(bindings, old_context)
  20          ASSERT.kind_of bindings,    ::Hash
  21          ASSERT.kind_of old_context, ECV::Abstract
  22 
  23          @bindings       = bindings
  24          @old_context    = old_context
  25      end
  26 
  27 
  28      def get_bindings
  29          self.bindings.inject({}) { |hash, (sym, target)|
  30              hash.merge(sym => target.get_value(self))
  31          }.freeze
  32      end
  33 
  34 
  35      def get_bindings_difference_with(prev_ctx)
  36          ASSERT.kind_of prev_ctx, ECV::Abstract
  37 
  38          prev_bindings = prev_ctx.get_bindings
  39 
  40          diff_bindings = self.get_bindings.select {
  41              |sym, value|
  42 
  43              opt_prev_value = prev_bindings[sym]
  44 
  45              if opt_prev_value
  46                  if opt_prev_value == value
  47                      false
  48                  else
  49                      true
  50                  end
  51              else
  52                  true
  53              end
  54          }
  55 
  56          ASSERT.kind_of diff_bindings, ::Hash
  57      end
  58 
  59 
  60  private
  61 
  62      def __extend__(sym, target)
  63          ASSERT.kind_of sym,     ::Symbol
  64          ASSERT.kind_of target,  Target::Abstract
  65 
  66          if self.bindings.has_key? sym
  67              [{sym => target},                       self]
  68          else
  69              [self.bindings.merge(sym => target),    self.old_context]
  70          end
  71      end
  72  end
  73 
  74 
  75 
  76  module_function
  77 
  78      def make_bindings(bindings, old_context)
  79          ASSERT.kind_of bindings,    ::Hash
  80          ASSERT.kind_of old_context, ECV::Abstract
  81 
  82          Entry.new(bindings.freeze, old_context).freeze
  83      end
  84 
  85  end # Umu::Environment::Context::Value
  86 
  87  end # Umu::Environment::Context
  88 
  89  end # Umu::Environment
  90 
  91  end # Umu