Module: Legion::Extensions::Helpers::Base

Included in:
Cache, Core, Data, Transport
Defined in:
lib/legion/extensions/helpers/base.rb

Instance Method Summary collapse

Instance Method Details

#actor_classObject



28
29
30
# File 'lib/legion/extensions/helpers/base.rb', line 28

def actor_class
  calling_class
end

#actor_constObject



36
37
38
# File 'lib/legion/extensions/helpers/base.rb', line 36

def actor_const
  @actor_const ||= calling_class_array.last
end

#actor_nameObject



32
33
34
# File 'lib/legion/extensions/helpers/base.rb', line 32

def actor_name
  @actor_name ||= calling_class_array.last.gsub(/(?<!^)[A-Z]/) { "_#{Regexp.last_match(0)}" }.downcase
end

#calling_classObject



20
21
22
# File 'lib/legion/extensions/helpers/base.rb', line 20

def calling_class
  @calling_class ||= respond_to?(:ancestors) ? ancestors.first : self.class
end

#calling_class_arrayObject



24
25
26
# File 'lib/legion/extensions/helpers/base.rb', line 24

def calling_class_array
  @calling_class_array ||= calling_class.to_s.split('::')
end

#from_json(string) ⇒ Object



57
58
59
# File 'lib/legion/extensions/helpers/base.rb', line 57

def from_json(string)
  Legion::JSON.load(string)
end

#full_pathObject Also known as: extension_path



52
53
54
# File 'lib/legion/extensions/helpers/base.rb', line 52

def full_path
  @full_path ||= "#{Gem::Specification.find_by_name("lex-#{lex_name}").gem_dir}/lib/legion/extensions/#{lex_filename}"
end

#lex_classObject Also known as: extension_class



5
6
7
# File 'lib/legion/extensions/helpers/base.rb', line 5

def lex_class
  @lex_class ||= Kernel.const_get(calling_class_array[0..2].join('::'))
end

#lex_constObject



16
17
18
# File 'lib/legion/extensions/helpers/base.rb', line 16

def lex_const
  @lex_const ||= calling_class_array[2]
end

#lex_nameObject Also known as: extension_name, lex_filename



10
11
12
# File 'lib/legion/extensions/helpers/base.rb', line 10

def lex_name
  @lex_name ||= calling_class_array[2].gsub(/(?<!^)[A-Z]/) { "_#{Regexp.last_match(0)}" }.downcase
end

#normalize(thing) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/legion/extensions/helpers/base.rb', line 61

def normalize(thing)
  if thing.is_a? String
    to_json(from_json(thing))
  else
    from_json(to_json(thing))
  end
end

#runner_classObject



40
41
42
# File 'lib/legion/extensions/helpers/base.rb', line 40

def runner_class
  @runner_class ||= Kernel.const_get(actor_class.to_s.sub!('Actor', 'Runners'))
end

#runner_constObject



48
49
50
# File 'lib/legion/extensions/helpers/base.rb', line 48

def runner_const
  @runner_const ||= runner_class.to_s.split('::').last
end

#runner_nameObject



44
45
46
# File 'lib/legion/extensions/helpers/base.rb', line 44

def runner_name
  @runner_name ||= runner_class.to_s.split('::').last.gsub(/(?<!^)[A-Z]/) { "_#{Regexp.last_match(0)}" }.downcase
end

#to_dotted_hash(hash, recursive_key = '') ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/legion/extensions/helpers/base.rb', line 69

def to_dotted_hash(hash, recursive_key = '')
  hash.each_with_object({}) do |(k, v), ret|
    key = recursive_key + k.to_s
    if v.is_a? Hash
      ret.merge! to_dotted_hash(v, "#{key}.")
    else
      ret[key.to_sym] = v
    end
  end
end