Class: Aker::ConfigParser

Inherits:
Object
  • Object
show all
Defined in:
app/models/aker/config_parser.rb

Overview

Translates config in initializers/aker.rb to a mapping object from Aker::Mapping Parses expressions like:

sample_metadata.gender              <=   gender
  |
   -> It will update gender from Aker into sample_metadata.gender

sample_metadata.sample_common_name   =>   common_name
  |
   -> Update sample_common_name from sample_metadata into common_name in Aker

 volume                             <=   volume
  |
   -> Update volume from Aker into Sequencescape using the setter method (volume=) in the mapping class

concentration                       <=>  concentration
  |
   -> Updates both ways, from Aker into Sequencescape and from Sequencescape into Aker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ ConfigParser

Returns a new instance of ConfigParser


26
27
28
# File 'app/models/aker/config_parser.rb', line 26

def initialize(config = nil)
  @config = config || initial_config
end

Instance Attribute Details

#configObject

Returns the value of attribute config


24
25
26
# File 'app/models/aker/config_parser.rb', line 24

def config
  @config
end

Instance Method Details

#initial_configObject


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/aker/config_parser.rb', line 30

def initial_config
  {
    # Maps SS models with Aker attributes
    map_ss_columns_with_aker: {
    },

    # Aker attributes allowed to update from Aker into SS
    updatable_attrs_from_aker_into_ss: [],

    # Sequencescape models with columns allowed to update from SS into Aker
    updatable_columns_from_ss_into_aker: {}
  }
end

#parse(description_text) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/aker/config_parser.rb', line 44

def parse(description_text)
  description_text.split("\n").each do |line|
    next unless line.include?('=')

    token = tokenizer(line)
    __parse_map_ss_columns_with_aker(token)
    __parse_updatable_attrs_from_aker_into_ss(token)
    __parse_updatable_columns_from_ss_into_aker(token)
  end
  config
end

#tokenizer(str) ⇒ Object


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/aker/config_parser.rb', line 56

def tokenizer(str)
  list = str.split('=').map { |s| s.gsub(/[<=> ]/, '') }
  ss = list[0]
  aker_name = list[1].to_sym
  ss_to_aker = str.include?('=>')
  aker_to_ss = str.include?('<=')
  ss_name, ss_model = ss.split('.').reverse.map(&:to_sym)
  ss_model = :self if ss_model.nil?

  {
    # Attribute name in Aker
    aker_name: aker_name,
    # Left hand side string
    ss: ss,
    # Sequencescape mapping model
    ss_model: ss_model,
    # Sequencescape mapping column
    ss_name: ss_name,
    # Boolean specifying update from SS to Aker
    ss_to_aker: ss_to_aker,
    # Boolean specifying update from Aker into SS
    aker_to_ss: aker_to_ss
  }
end