Class: Poke::Group
- Inherits:
-
Object
- Object
- Poke::Group
- Defined in:
- lib/poke/group.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, config_path:) ⇒ Group
constructor
A new instance of Group.
- #position ⇒ Object
- #requests ⇒ Object
- #save_config! ⇒ Object
- #use! ⇒ Object
Constructor Details
#initialize(name:, config_path:) ⇒ Group
Returns a new instance of Group.
31 32 33 34 35 |
# File 'lib/poke/group.rb', line 31 def initialize(name:, config_path:) @name = name @config_path = config_path @config = Poke::GroupConfig.from_path(config_path) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
29 30 31 |
# File 'lib/poke/group.rb', line 29 def config @config end |
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
29 30 31 |
# File 'lib/poke/group.rb', line 29 def config_path @config_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/poke/group.rb', line 29 def name @name end |
Class Method Details
.all ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/poke/group.rb', line 13 def self.all @all ||= begin config_paths = TTY::Command.new(printer: :null).run("find #{Dir.home}/.poke -name 'config.json'").out.split("\n") config_paths.map do |config_path| name = ::Pathname.new(config_path).parent.basename.to_s new(name:, config_path:) end end end |
Instance Method Details
#position ⇒ Object
45 46 47 |
# File 'lib/poke/group.rb', line 45 def position LastRecentlyUsed.position(namespace: 'groups', key: name.to_s) end |
#requests ⇒ Object
41 42 43 |
# File 'lib/poke/group.rb', line 41 def requests @requests ||= Request.all.filter { |request| request.group_name == name } end |
#save_config! ⇒ Object
37 38 39 |
# File 'lib/poke/group.rb', line 37 def save_config! @config.save_to(@config_path) end |
#use! ⇒ Object
49 50 51 |
# File 'lib/poke/group.rb', line 49 def use! LastRecentlyUsed.use!(namespace: 'groups', key: name.to_s) end |