tataru 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/tataru.rb +70 -12
- data/lib/tataru/base_resource.rb +49 -0
- data/lib/tataru/base_resource_desc.rb +35 -0
- data/lib/tataru/compiler.rb +100 -0
- data/lib/tataru/create_subroutines.rb +31 -0
- data/lib/tataru/delete_subroutines.rb +42 -0
- data/lib/tataru/flattener.rb +81 -0
- data/lib/tataru/init_hash_compiler.rb +41 -0
- data/lib/tataru/instruction.rb +52 -7
- data/lib/tataru/instruction_hash.rb +54 -0
- data/lib/tataru/instructions/call_instruction.rb +19 -0
- data/lib/tataru/instructions/check_create_instruction.rb +27 -0
- data/lib/tataru/instructions/check_delete_instruction.rb +20 -0
- data/lib/tataru/instructions/check_instruction.rb +26 -0
- data/lib/tataru/instructions/check_update_instruction.rb +27 -0
- data/lib/tataru/instructions/clear_instruction.rb +12 -0
- data/lib/tataru/instructions/compare_instruction.rb +16 -0
- data/lib/tataru/instructions/create_instruction.rb +20 -0
- data/lib/tataru/instructions/delete_instruction.rb +14 -0
- data/lib/tataru/instructions/end_instruction.rb +12 -0
- data/lib/tataru/instructions/goto_if_instruction.rb +26 -0
- data/lib/tataru/instructions/immediate_mode_instruction.rb +12 -0
- data/lib/tataru/instructions/init_instruction.rb +27 -0
- data/lib/tataru/instructions/key_instruction.rb +12 -0
- data/lib/tataru/instructions/mark_deletable_instruction.rb +13 -0
- data/lib/tataru/instructions/read_instruction.rb +28 -0
- data/lib/tataru/instructions/rescmp_instruction.rb +34 -0
- data/lib/tataru/instructions/resource_instruction.rb +15 -0
- data/lib/tataru/instructions/return_instruction.rb +16 -0
- data/lib/tataru/instructions/update_instruction.rb +16 -0
- data/lib/tataru/instructions/value_instruction.rb +15 -0
- data/lib/tataru/instructions/value_rom_instruction.rb +23 -0
- data/lib/tataru/instructions/value_update_instruction.rb +18 -0
- data/lib/tataru/memory.rb +16 -0
- data/lib/tataru/quest.rb +43 -0
- data/lib/tataru/representation.rb +22 -0
- data/lib/tataru/representations/array_representation.rb +18 -0
- data/lib/tataru/representations/hash_representation.rb +20 -0
- data/lib/tataru/representations/literal_representation.rb +9 -0
- data/lib/tataru/representations/output_representation.rb +19 -0
- data/lib/tataru/representations/resource_representation.rb +49 -0
- data/lib/tataru/resolver.rb +39 -0
- data/lib/tataru/resource_dsl.rb +21 -71
- data/lib/tataru/resource_type_pool.rb +22 -0
- data/lib/tataru/rom_reader.rb +47 -0
- data/lib/tataru/runner.rb +48 -0
- data/lib/tataru/sub_planner.rb +41 -0
- data/lib/tataru/subroutine_compiler.rb +52 -0
- data/lib/tataru/top_dsl.rb +35 -0
- data/lib/tataru/update_subroutines.rb +111 -0
- data/lib/tataru/version.rb +1 -1
- data/spec/compiler_spec.rb +181 -0
- data/spec/flattener_spec.rb +88 -0
- data/spec/init_hash_compiler_spec.rb +85 -0
- data/spec/instruction_hash_spec.rb +63 -0
- data/spec/instruction_spec.rb +36 -0
- data/spec/instructions/call_instruction_spec.rb +28 -0
- data/spec/instructions/check_create_instruction_spec.rb +67 -0
- data/spec/instructions/check_delete_instruction_spec.rb +47 -0
- data/spec/instructions/check_update_instruction_spec.rb +67 -0
- data/spec/instructions/clear_instruction_spec.rb +16 -0
- data/spec/instructions/compare_instruction_spec.rb +29 -0
- data/spec/instructions/create_instruction_spec.rb +62 -0
- data/spec/instructions/delete_instruction_spec.rb +20 -0
- data/spec/instructions/end_instruction_spec.rb +15 -0
- data/spec/instructions/goto_if_instruction_spec.rb +42 -0
- data/spec/instructions/init_instruction_spec.rb +16 -0
- data/spec/instructions/key_instruction_spec.rb +15 -0
- data/spec/instructions/mark_deletable_instruction_spec.rb +20 -0
- data/spec/instructions/read_instruction_spec.rb +34 -0
- data/spec/instructions/rescmp_instruction_spec.rb +113 -0
- data/spec/instructions/return_instruction_spec.rb +28 -0
- data/spec/instructions/update_instruction_spec.rb +39 -0
- data/spec/instructions/value_instruction_spec.rb +27 -0
- data/spec/instructions/value_rom_instruction_spec.rb +170 -0
- data/spec/instructions/value_update_instruction_spec.rb +35 -0
- data/spec/quest_spec.rb +9 -0
- data/spec/representations/array_representation_spec.rb +29 -0
- data/spec/representations/hash_representation_spec.rb +29 -0
- data/spec/representations/literal_representation_spec.rb +10 -0
- data/spec/representations/output_representation_spec.rb +11 -0
- data/spec/representations/resource_representation_spec.rb +50 -0
- data/spec/resource_dsl_spec.rb +71 -0
- data/spec/runner_spec.rb +99 -0
- data/spec/spec_helper.rb +401 -0
- data/spec/subroutine_compiler_spec.rb +39 -0
- data/spec/taru_spec.rb +616 -0
- data/spec/top_dsl_spec.rb +68 -0
- data/tataru.gemspec +45 -0
- metadata +145 -27
- data/Rakefile +0 -8
- data/lib/tataru/default_resource_finder.rb +0 -10
- data/lib/tataru/execution_step.rb +0 -79
- data/lib/tataru/planner.rb +0 -93
- data/lib/tataru/requirements.rb +0 -67
- data/lib/tataru/requirements_dsl.rb +0 -33
- data/lib/tataru/resource.rb +0 -52
- data/lib/tataru/state.rb +0 -64
data/lib/tataru/planner.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tataru
|
4
|
-
module Rage
|
5
|
-
# not valid
|
6
|
-
class InvalidRequirement < StandardError; end
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
# A plan
|
11
|
-
class Planner
|
12
|
-
def initialize(current_state, requirement)
|
13
|
-
@current_state = current_state
|
14
|
-
@requirement = requirement
|
15
|
-
@actions = {}
|
16
|
-
|
17
|
-
raise Rage::InvalidRequirement unless requirement.valid?
|
18
|
-
end
|
19
|
-
|
20
|
-
def order
|
21
|
-
Bunny::Tsort.tsort(@requirement.dep_tree)
|
22
|
-
end
|
23
|
-
|
24
|
-
def delete_instruction_for(id, pref)
|
25
|
-
Instruction.new(:"#{pref}_delete", id, @current_state[id], @requirement)
|
26
|
-
end
|
27
|
-
|
28
|
-
def generate_delete_instruction_for(id, pref)
|
29
|
-
return if @current_state[id].nil?
|
30
|
-
return unless action(id) == :replace
|
31
|
-
|
32
|
-
delete_instruction_for(id, pref)
|
33
|
-
end
|
34
|
-
|
35
|
-
def generate_instruction_for(id, pref)
|
36
|
-
if @current_state[id].nil?
|
37
|
-
Instruction.new(:"#{pref}_create", id, end_state[id], @requirement)
|
38
|
-
elsif action(id) == :replace
|
39
|
-
Instruction.new(:"#{pref}_create", id, end_state[id], @requirement)
|
40
|
-
elsif action(id) == :update
|
41
|
-
Instruction.new(:"#{pref}_update", id, end_state[id], @requirement)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def generate_removal_instructions
|
46
|
-
remove_actions = []
|
47
|
-
@current_state.id_list.keys.each do |id|
|
48
|
-
next if @requirement.exist? id
|
49
|
-
|
50
|
-
remove_actions << delete_instruction_for(id, :begin)
|
51
|
-
end
|
52
|
-
remove_actions
|
53
|
-
end
|
54
|
-
|
55
|
-
def generate_delete_instructions
|
56
|
-
delete_actions = []
|
57
|
-
order.reverse.each do |step|
|
58
|
-
%i[begin wait].each do |substep|
|
59
|
-
step.each do |id|
|
60
|
-
delete_action = generate_delete_instruction_for(id, substep)
|
61
|
-
delete_actions << delete_action unless delete_action.nil?
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
delete_actions + generate_removal_instructions
|
66
|
-
end
|
67
|
-
|
68
|
-
def generate_instructions
|
69
|
-
instr = []
|
70
|
-
order.each do |step|
|
71
|
-
%i[begin wait].each do |substep|
|
72
|
-
step.each do |id|
|
73
|
-
instruction = generate_instruction_for(id, substep)
|
74
|
-
instr << instruction unless instruction.nil?
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
instr + generate_delete_instructions
|
79
|
-
end
|
80
|
-
|
81
|
-
def instructions
|
82
|
-
@instructions ||= generate_instructions
|
83
|
-
end
|
84
|
-
|
85
|
-
def action(id)
|
86
|
-
@actions[id] ||= @requirement.action(id, @current_state[id])
|
87
|
-
end
|
88
|
-
|
89
|
-
def end_state
|
90
|
-
@requirement.end_state
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
data/lib/tataru/requirements.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tataru
|
4
|
-
# Requirements list
|
5
|
-
class Requirements
|
6
|
-
attr_reader :resource_finder, :errors
|
7
|
-
|
8
|
-
def initialize(resource_finder = DefaultResourceFinder.new, &block)
|
9
|
-
dsl = RequirementsDSL.new(resource_finder)
|
10
|
-
dsl.instance_exec(&block)
|
11
|
-
@errors = dsl.errors
|
12
|
-
@reqs = dsl.resource_list
|
13
|
-
@resource_finder = resource_finder
|
14
|
-
end
|
15
|
-
|
16
|
-
def dep_tree
|
17
|
-
@reqs.map { |k, v| [k, v[:dependencies]] }.to_h
|
18
|
-
end
|
19
|
-
|
20
|
-
def end_state
|
21
|
-
state = State.new
|
22
|
-
@reqs.each do |id, info|
|
23
|
-
info[:state].each do |state_name, state_value|
|
24
|
-
state.putstate(id, state_name, state_value)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
state
|
28
|
-
end
|
29
|
-
|
30
|
-
def exist?(id)
|
31
|
-
@reqs.key? id
|
32
|
-
end
|
33
|
-
|
34
|
-
def type(id)
|
35
|
-
@reqs[id][:type]
|
36
|
-
end
|
37
|
-
|
38
|
-
def valid?
|
39
|
-
errors.length.zero?
|
40
|
-
end
|
41
|
-
|
42
|
-
def compare(id, current_state)
|
43
|
-
rclass = @resource_finder.resource_named(type(id))
|
44
|
-
resdef = rclass.new
|
45
|
-
changed = false
|
46
|
-
replace = false
|
47
|
-
|
48
|
-
current_state.each do |state_name, current_value|
|
49
|
-
next if current_value == @reqs[id][:state][state_name]
|
50
|
-
|
51
|
-
changed = true
|
52
|
-
replace ||= resdef.send(:"#{state_name}_change_action") == :replace
|
53
|
-
end
|
54
|
-
|
55
|
-
[changed, replace]
|
56
|
-
end
|
57
|
-
|
58
|
-
def action(id, current_state)
|
59
|
-
changed, replace = compare(id, current_state)
|
60
|
-
|
61
|
-
return :nothing unless changed
|
62
|
-
return :update unless replace
|
63
|
-
|
64
|
-
:replace
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tataru
|
4
|
-
# Requirements DSL
|
5
|
-
class RequirementsDSL
|
6
|
-
attr_reader :resource_list
|
7
|
-
|
8
|
-
def initialize(resource_finder)
|
9
|
-
@resource_finder = resource_finder
|
10
|
-
@resource_list = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
def respond_to_missing?
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
def method_missing(type, name, &block)
|
18
|
-
rclass = @resource_finder.resource_named(type)
|
19
|
-
res = ResourceDSL.new(rclass.new)
|
20
|
-
res.instance_exec(&block) if block
|
21
|
-
@resource_list[name] = {
|
22
|
-
type: type, dependencies: res.dependencies,
|
23
|
-
state: res.fields, errors: res.errors
|
24
|
-
}
|
25
|
-
rescue NameError
|
26
|
-
super
|
27
|
-
end
|
28
|
-
|
29
|
-
def errors
|
30
|
-
@resource_list.flat_map { |_, v| v[:errors] }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/tataru/resource.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tataru
|
4
|
-
# base resource class
|
5
|
-
class Resource
|
6
|
-
class << self
|
7
|
-
def state(state_name, change_behaviour)
|
8
|
-
define_method "#{state_name}_change_action" do
|
9
|
-
change_behaviour
|
10
|
-
end
|
11
|
-
|
12
|
-
define_method "_state_#{state_name}" do
|
13
|
-
state_name
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def output(output_name)
|
18
|
-
define_method "_output_#{output_name}" do
|
19
|
-
output_name
|
20
|
-
end
|
21
|
-
|
22
|
-
define_method(output_name) {}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def states
|
27
|
-
list_props(:state)
|
28
|
-
end
|
29
|
-
|
30
|
-
def outputs
|
31
|
-
list_props(:output)
|
32
|
-
end
|
33
|
-
|
34
|
-
%i[
|
35
|
-
begin_create
|
36
|
-
begin_update
|
37
|
-
begin_delete
|
38
|
-
create_complete?
|
39
|
-
update_complete?
|
40
|
-
delete_complete?
|
41
|
-
].each do |thing|
|
42
|
-
define_method(thing) { |_state| }
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def list_props(prop_type)
|
48
|
-
methods.select { |x| x.to_s.start_with? "_#{prop_type}_" }
|
49
|
-
.map { |x| x.to_s.sub("_#{prop_type}_", '').to_sym }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/lib/tataru/state.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tataru
|
4
|
-
# The state of the environment
|
5
|
-
class State
|
6
|
-
def initialize(objstate = {})
|
7
|
-
@current_ids = objstate[:current_ids] || {}
|
8
|
-
@replacer_ids = objstate[:replacer_ids] || {}
|
9
|
-
@waiting_ids = objstate[:waiting_ids] || {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def putstate(id, state, value, replacer: false)
|
13
|
-
ids = id_list(replacer)
|
14
|
-
ids[id] = {} unless ids.key? id
|
15
|
-
ids[id][state] = value
|
16
|
-
end
|
17
|
-
|
18
|
-
def getstate(id, state, replacer: false)
|
19
|
-
ids = id_list(replacer)
|
20
|
-
return unless ids.key? id
|
21
|
-
|
22
|
-
ids[id][state]
|
23
|
-
end
|
24
|
-
|
25
|
-
def id_list(replacer = false)
|
26
|
-
return @replacer_ids if replacer
|
27
|
-
|
28
|
-
@current_ids
|
29
|
-
end
|
30
|
-
|
31
|
-
def replace(id)
|
32
|
-
@current_ids[id] = @replacer_ids[id]
|
33
|
-
@replacer_ids.delete(id)
|
34
|
-
end
|
35
|
-
|
36
|
-
def delete_list
|
37
|
-
@replacer_ids.keys.select { |x| @current_ids.key? x }
|
38
|
-
end
|
39
|
-
|
40
|
-
def [](id)
|
41
|
-
@current_ids[id].clone
|
42
|
-
end
|
43
|
-
|
44
|
-
def waiting_on(id, what)
|
45
|
-
@waiting_ids[id] = what
|
46
|
-
end
|
47
|
-
|
48
|
-
def no_longer_waiting(id)
|
49
|
-
@waiting_ids.delete(id)
|
50
|
-
end
|
51
|
-
|
52
|
-
def waiting_list
|
53
|
-
@waiting_ids.clone
|
54
|
-
end
|
55
|
-
|
56
|
-
def to_h
|
57
|
-
{
|
58
|
-
current_ids: @current_ids,
|
59
|
-
replacer_ids: @replacer_ids,
|
60
|
-
waiting_ids: @waiting_ids
|
61
|
-
}
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|