Class: Tataru::SubroutineCompiler

Inherits:
Object
  • Object
show all
Includes:
CreateSubroutines, DeleteSubroutines, UpdateSubroutines
Defined in:
lib/tataru/subroutine_compiler.rb

Overview

a subroutine for handling a resource

Instance Method Summary collapse

Methods included from DeleteSubroutines

#check_delete_instructions, #commit_delete_instructions, #delete_instructions, #finish_delete_instructions

Methods included from UpdateSubroutines

#check_update_instructions, #commit_update_instructions, #finish_update_instructions, #modify_check_instructions, #modify_instructions, #recreate_check_instructions, #recreate_commit_instructions, #recreate_finish_instructions, #recreate_instructions, #update_instructions

Methods included from CreateSubroutines

#check_create_instructions, #commit_create_instructions, #create_instructions, #finish_create_instructions

Constructor Details

#initialize(resource_representation, action) ⇒ SubroutineCompiler

Returns a new instance of SubroutineCompiler.



10
11
12
13
# File 'lib/tataru/subroutine_compiler.rb', line 10

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

Instance Method Details

#base_actionObject



23
24
25
# File 'lib/tataru/subroutine_compiler.rb', line 23

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

#body_instructionsObject



27
28
29
30
31
32
33
# File 'lib/tataru/subroutine_compiler.rb', line 27

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

#call_instructionObject



48
49
50
# File 'lib/tataru/subroutine_compiler.rb', line 48

def call_instruction
  { call: label }
end

#descObject



15
16
17
# File 'lib/tataru/subroutine_compiler.rb', line 15

def desc
  @rrep.desc
end

#inner_instructionsObject



44
45
46
# File 'lib/tataru/subroutine_compiler.rb', line 44

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

#labelObject



19
20
21
# File 'lib/tataru/subroutine_compiler.rb', line 19

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

#load_resource_instructionsObject



35
36
37
38
39
40
41
42
# File 'lib/tataru/subroutine_compiler.rb', line 35

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