Module: Nayati::OperationConfiguration

Defined in:
app/models/nayati/operation_configuration.rb

Class Method Summary collapse

Class Method Details

.add_operation_unless_present(workflow_name, operation_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/nayati/operation_configuration.rb', line 21

def add_operation_unless_present(workflow_name, operation_name)
  wf_namespace = ::Nayati::NameBasedConstantable.name_as_namespace(workflow_name.to_s)
  op_namespace = ::Nayati::NameBasedConstantable.name_as_namespace(operation_name.to_s)

  add_workflow_unless_present(wf_namespace)

  unless operation_names(wf_namespace).include?(op_namespace)
    configuration[wf_namespace.to_sym] << { name: op_namespace }
    write_configuration
  end
end

.add_workflow_unless_present(workflow_name) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/nayati/operation_configuration.rb', line 13

def add_workflow_unless_present(workflow_name)
  wf_namespace = ::Nayati::NameBasedConstantable.name_as_namespace(workflow_name.to_s)
  unless workflow_names.include?(wf_namespace.to_sym)
    configuration[wf_namespace.to_sym] = []
    write_configuration
  end
end

.configurationObject



4
5
6
# File 'app/models/nayati/operation_configuration.rb', line 4

def configuration
  @configuration ||= YAML.load(File.open(yaml_file_path)) || {}
end

.operation_names(workflow_name) ⇒ Object



8
9
10
11
# File 'app/models/nayati/operation_configuration.rb', line 8

def operation_names(workflow_name)
  wf_name = ::Nayati::NameBasedConstantable.name_as_namespace(workflow_name.to_s)
  (configuration[wf_name.to_sym] || []).map { |operation_conf| operation_conf.try(:[], :name) }
end

.update_operation(workflow_name, old_name, new_name) ⇒ Object



50
51
52
53
54
55
# File 'app/models/nayati/operation_configuration.rb', line 50

def update_operation(workflow_name, old_name, new_name)
  op_conf = operation_configuration(workflow_name, old_name)

  op_conf[:name] = ::Nayati::NameBasedConstantable.name_as_namespace(new_name.to_s)
  write_configuration
end

.workflow_exists?(workflow_name) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'app/models/nayati/operation_configuration.rb', line 33

def workflow_exists?(workflow_name)
  wf_namespace = ::Nayati::NameBasedConstantable.name_as_namespace(workflow_name.to_s)
  workflow_names.include?(wf_namespace.to_sym)
end

.workflow_namesObject



46
47
48
# File 'app/models/nayati/operation_configuration.rb', line 46

def workflow_names
  configuration.keys
end

.write_configurationObject



42
43
44
# File 'app/models/nayati/operation_configuration.rb', line 42

def write_configuration
  File.open(yaml_file_path, 'w') { |f| f.write configuration.to_yaml }
end

.yaml_file_pathObject



38
39
40
# File 'app/models/nayati/operation_configuration.rb', line 38

def yaml_file_path
  "#{Rails.root}/config/operations.yml"
end