Module: Smith::Utils
- Included in:
- ACL::Factory, AgentBootstrap, AgentProcess
- Defined in:
- lib/smith/utils.rb
Instance Method Summary collapse
-
#agent_path(name) ⇒ Pathname
Searches the agent load path for agents.
-
#class_from_name(name) ⇒ Class
Performs a Kernel.const_get on each element of the class.
- #class_name_from_path(root, path) ⇒ Object
-
#path_from_class(root, clazz) ⇒ Object
Constructs a path from a root and a fully qualified class.
Instance Method Details
#agent_path(name) ⇒ Pathname
Searches the agent load path for agents. If there are multiple agents with the same name in different directories the first wins.
9 10 11 12 13 14 15 |
# File 'lib/smith/utils.rb', line 9 def agent_path(name) Smith.agent_paths.each do |path| p = path_from_class(path, name) return p if p.exist? end return nil end |
#class_from_name(name) ⇒ Class
Performs a Kernel.const_get on each element of the class.
38 39 40 |
# File 'lib/smith/utils.rb', line 38 def class_from_name(name) name.to_s.split(/::/).inject(Kernel) { |acc, t| acc.const_get(t) } end |
#class_name_from_path(root, path) ⇒ Object
28 29 30 31 32 |
# File 'lib/smith/utils.rb', line 28 def class_name_from_path(root, path) relative_path = path.relative_path_from(root) parts = relative_path.split parts.map { |p| p.to_s.camel_case }.join('::') end |
#path_from_class(root, clazz) ⇒ Object
Constructs a path from a root and a fully qualified class.
@@return [Pathname] the path
22 23 24 25 26 |
# File 'lib/smith/utils.rb', line 22 def path_from_class(root, clazz) parts = clazz.split(/::/).map(&:snake_case) parts[-1] = "#{parts[-1]}.rb" Pathname.new(root).join(*parts) end |