Module: Legion::Extensions::Helpers::Base
Instance Method Summary collapse
- #actor_class ⇒ Object
- #actor_const ⇒ Object
- #actor_name ⇒ Object
- #calling_class ⇒ Object
- #calling_class_array ⇒ Object
- #from_json(string) ⇒ Object
- #full_path ⇒ Object (also: #extension_path)
- #lex_class ⇒ Object (also: #extension_class)
- #lex_const ⇒ Object
- #lex_name ⇒ Object (also: #extension_name, #lex_filename)
- #normalize(thing) ⇒ Object
- #runner_class ⇒ Object
- #runner_const ⇒ Object
- #runner_name ⇒ Object
- #to_dotted_hash(hash, recursive_key = '') ⇒ Object
Instance Method Details
#actor_class ⇒ Object
28 29 30 |
# File 'lib/legion/extensions/helpers/base.rb', line 28 def actor_class calling_class end |
#actor_const ⇒ Object
36 37 38 |
# File 'lib/legion/extensions/helpers/base.rb', line 36 def actor_const @actor_const ||= calling_class_array.last end |
#actor_name ⇒ Object
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_class ⇒ Object
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_array ⇒ Object
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_path ⇒ Object 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_class ⇒ Object 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_const ⇒ Object
16 17 18 |
# File 'lib/legion/extensions/helpers/base.rb', line 16 def lex_const @lex_const ||= calling_class_array[2] end |
#lex_name ⇒ Object 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_class ⇒ Object
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_const ⇒ Object
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_name ⇒ Object
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 |