Class: Trailblazer::Activity::State::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/activity/config.rb

Overview

Compile-time

DISCUSS: we could replace parts with Hamster::Hash.

Class Method Summary collapse

Class Method Details

.[](state, *args) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/trailblazer/activity/config.rb', line 28

def self.[](state, *args)
  directive, key = *args

  return state[directive] if args.size == 1
  return state[directive][key] if state.key?(directive)
  nil
end

.[]=(state, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/trailblazer/activity/config.rb', line 11

def self.[]=(state, *args)
  if args.size == 2
    key, value = *args

    state = state.merge(key => value)
  else
    directive, key, value = *args

    state = state.merge( directive => {}.freeze ) unless state.key?(directive)

    directive_hash = state[directive].merge(key => value)
    state = state.merge( directive => directive_hash.freeze )
  end

  state
end

.build(variables = {}) ⇒ Object



7
8
9
# File 'lib/trailblazer/activity/config.rb', line 7

def self.build(variables={})
  Hash[ variables.collect { |k,v| [k, v.freeze] } ].freeze
end