File: common/abstraction.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Umu#6
  module: Abstraction#8
  class: Model#10
inherits from
  Object ( Builtin-Module )
has properties
attribute: loc [R] #11
method: initialize / 1 #14
method: to_s #21
  class: Record#33
inherits from
  Object ( Builtin-Module )
has properties
class method: __deconstruct_keys__ #34
method: deconstruct_keys #51
method: update / 1 #58
  class: Collection#77
includes
  Enumerable ( Builtin-Module )
inherits from
  Object ( Builtin-Module )

Class Hierarchy

Code

   1  # coding: utf-8
   2  # frozen_string_literal: true
   3 
   4 
   5 
   6  module Umu
   7 
   8  module Abstraction
   9 
  10  class Model
  11      attr_reader :loc
  12 
  13 
  14      def initialize(loc)
  15          ASSERT.kind_of loc, LOC::Entry
  16 
  17          @loc = loc
  18      end
  19 
  20 
  21      def to_s
  22          pp({
  23              msg:"============ InternalSubclassResponsibility ============",
  24              type:self.class
  25          })
  26 
  27          raise X::InternalSubclassResponsibility
  28      end
  29  end
  30 
  31 
  32 
  33  class Record
  34      def self.__deconstruct_keys__
  35          (
  36              if superclass.respond_to? :__deconstruct_keys__
  37                  superclass.__deconstruct_keys__
  38              else
  39                  {}.freeze
  40              end
  41          ).merge(
  42              if self.respond_to? :deconstruct_keys
  43                  ASSERT.kind_of self.deconstruct_keys, ::Hash
  44              else
  45                  {}.freeze
  46              end
  47          ).freeze
  48      end
  49 
  50 
  51      def deconstruct_keys
  52          self.class.__deconstruct_keys__.inject({}) { |hash, (key, _val)|
  53              hash.merge(key => self.public_send(key))
  54          }.freeze
  55      end
  56 
  57 
  58      def update(args)
  59          ASSERT.kind_of args, ::Hash
  60 
  61          class_keys = self.class.deconstruct_keys
  62          args.each do |key, value|
  63              unless class_keys.has_key? key
  64                  ASSERT.abort "Unknown key: %s", key
  65              end
  66 
  67              klass = class_keys[key]
  68              ASSERT.kind_of value, klass
  69          end
  70 
  71          self.class.new(*self.deconstruct_keys.merge(args).values).freeze
  72      end
  73  end
  74 
  75 
  76 
  77  class Collection
  78      include Enumerable
  79  end
  80 
  81  end # Umu::Abstraction
  82 
  83  end # Umu