Sha256: eda1292c87ebcd5512f9830b6b49f577703d2fab53dcaffaffdc65a328e08d95

Contents?: true

Size: 937 Bytes

Versions: 1

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

module Tataru
  # a subroutine for handling a resource
  class SubroutineCompiler
    include CreateSubroutines
    include UpdateSubroutines
    include DeleteSubroutines

    def initialize(resource_representation, action)
      @rrep = resource_representation
      @action = action
    end

    def desc
      @rrep.desc
    end

    def label
      "#{@action}_#{@rrep.name}"
    end

    def base_action
      @action.to_s.split('_')[1].to_s
    end

    def body_instructions
      [
        :clear,
        *inner_instructions,
        :return
      ]
    end

    def load_resource_instructions
      [
        { key: :resource_name },
        { value: @rrep.name },
        { key: :resource_desc },
        { value: @rrep.desc.class.name }
      ]
    end

    def inner_instructions
      send :"#{@action}_instructions"
    end

    def call_instruction
      { call: label }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tataru-0.2.0 lib/tataru/subroutine_compiler.rb