Class: Hiiro::Environment
- Inherits:
-
Object
- Object
- Hiiro::Environment
- Defined in:
- lib/hiiro/tasks.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #all_apps ⇒ Object
- #all_sessions ⇒ Object
- #all_tasks ⇒ Object
- #all_trees ⇒ Object
- #app_matcher ⇒ Object
- #config ⇒ Object
- #external_task_tree ⇒ Object
- #find_app(abbreviated) ⇒ Object
- #find_session(abbreviated) ⇒ Object
- #find_task(abbreviated) ⇒ Object
- #find_tree(abbreviated) ⇒ Object
-
#initialize(path: Dir.pwd, config: nil) ⇒ Environment
constructor
A new instance of Environment.
- #session ⇒ Object
- #session_matcher ⇒ Object
- #task ⇒ Object
- #task_matcher ⇒ Object
- #tree ⇒ Object
- #tree_matcher ⇒ Object
Constructor Details
#initialize(path: Dir.pwd, config: nil) ⇒ Environment
Returns a new instance of Environment.
1674 1675 1676 1677 |
# File 'lib/hiiro/tasks.rb', line 1674 def initialize(path: Dir.pwd, config: nil) @path = path @config = config end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
1668 1669 1670 |
# File 'lib/hiiro/tasks.rb', line 1668 def path @path end |
Class Method Details
.current ⇒ Object
1670 1671 1672 |
# File 'lib/hiiro/tasks.rb', line 1670 def self.current new(path: Dir.pwd) end |
Instance Method Details
#all_apps ⇒ Object
1695 1696 1697 |
# File 'lib/hiiro/tasks.rb', line 1695 def all_apps @all_apps ||= config.apps end |
#all_sessions ⇒ Object
1687 1688 1689 |
# File 'lib/hiiro/tasks.rb', line 1687 def all_sessions @all_sessions ||= Hiiro::Tmux::Session.all end |
#all_tasks ⇒ Object
1683 1684 1685 |
# File 'lib/hiiro/tasks.rb', line 1683 def all_tasks @all_tasks ||= config.tasks end |
#all_trees ⇒ Object
1691 1692 1693 |
# File 'lib/hiiro/tasks.rb', line 1691 def all_trees @all_trees ||= Tree.all end |
#app_matcher ⇒ Object
1707 1708 1709 |
# File 'lib/hiiro/tasks.rb', line 1707 def app_matcher @app_matcher ||= Hiiro::Matcher.new(all_apps, :name) end |
#config ⇒ Object
1679 1680 1681 |
# File 'lib/hiiro/tasks.rb', line 1679 def config @config ||= TaskManager::Config.new end |
#external_task_tree ⇒ Object
1769 1770 1771 1772 |
# File 'lib/hiiro/tasks.rb', line 1769 def external_task_tree task = all_tasks.find { |t| t.absolute_tree? && t.tree_name && (path == t.tree_name || path.start_with?(t.tree_name + '/')) } Tree.from_path(task.tree_name) if task end |
#find_app(abbreviated) ⇒ Object
1764 1765 1766 1767 |
# File 'lib/hiiro/tasks.rb', line 1764 def find_app(abbreviated) return nil if abbreviated.nil? app_matcher.find(abbreviated).first&.item end |
#find_session(abbreviated) ⇒ Object
1759 1760 1761 1762 |
# File 'lib/hiiro/tasks.rb', line 1759 def find_session(abbreviated) return nil if abbreviated.nil? session_matcher.find(abbreviated).resolved&.item end |
#find_task(abbreviated) ⇒ Object
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 |
# File 'lib/hiiro/tasks.rb', line 1734 def find_task(abbreviated) return nil if abbreviated.nil? if abbreviated.include?('/') result = task_matcher.resolve_path(abbreviated) return result.resolved&.item if result.match? parent_prefix, child_prefix = abbreviated.split('/', 2) if 'main'.start_with?(child_prefix) return task_matcher.find(parent_prefix).first&.item end nil else task_matcher.find(abbreviated).first&.item end end |
#find_tree(abbreviated) ⇒ Object
1752 1753 1754 1755 1756 1757 |
# File 'lib/hiiro/tasks.rb', line 1752 def find_tree(abbreviated) return nil if abbreviated.nil? return Tree.from_path(abbreviated) if abbreviated.to_s.start_with?('/') && Dir.exist?(abbreviated) tree_matcher.find(abbreviated).first&.item end |
#session ⇒ Object
1726 1727 1728 |
# File 'lib/hiiro/tasks.rb', line 1726 def session @session ||= Hiiro::Tmux::Session.current end |
#session_matcher ⇒ Object
1703 1704 1705 |
# File 'lib/hiiro/tasks.rb', line 1703 def session_matcher @session_matcher ||= Hiiro::Matcher.new(all_sessions, :name) end |
#task ⇒ Object
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 |
# File 'lib/hiiro/tasks.rb', line 1715 def task @task ||= begin s = session t = tree all_tasks.find { |task| (s && task.session_name == s.name) || (t && (task.tree_name == t.name || task.tree_name == t.path)) } end end |
#task_matcher ⇒ Object
1711 1712 1713 |
# File 'lib/hiiro/tasks.rb', line 1711 def task_matcher @task_matcher ||= Hiiro::Matcher.new(all_tasks, :name) end |
#tree ⇒ Object
1730 1731 1732 |
# File 'lib/hiiro/tasks.rb', line 1730 def tree @tree ||= all_trees.find { |t| t.match?(path) } || external_task_tree end |