module Legion::Extensions::Helpers::Base

Public Instance Methods

actor_class() click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 28
def actor_class
  calling_class
end
actor_const() click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 36
def actor_const
  @actor_const ||= calling_class_array.last
end
actor_name() click to toggle source
# 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_class() click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 20
def calling_class
  @calling_class ||= respond_to?(:ancestors) ? ancestors.first : self.class
end
calling_class_array() click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 24
def calling_class_array
  @calling_class_array ||= calling_class.to_s.split('::')
end
extension_class()
Alias for: lex_class
extension_name()
Alias for: lex_name
extension_path()
Alias for: full_path
from_json(string) click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 57
def from_json(string)
  Legion::JSON.load(string)
end
full_path() click to toggle source
# 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
Also aliased as: extension_path
lex_class() click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 5
def lex_class
  @lex_class ||= Kernel.const_get(calling_class_array[0..2].join('::'))
end
Also aliased as: extension_class
lex_const() click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 16
def lex_const
  @lex_const ||= calling_class_array[2]
end
lex_filename()
Alias for: lex_name
lex_name() click to toggle source
# 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
Also aliased as: extension_name, lex_filename
normalize(thing) click to toggle source
# 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_class() click to toggle source
# 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_const() click to toggle source
# File lib/legion/extensions/helpers/base.rb, line 48
def runner_const
  @runner_const ||= runner_class.to_s.split('::').last
end
runner_name() click to toggle source
# 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 = '') click to toggle source
# 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