Class: GemfileParser::Commands::Groups
- Inherits:
-
Object
- Object
- GemfileParser::Commands::Groups
- Defined in:
- lib/gemfile_parser/commands/groups.rb
Class Method Summary collapse
Instance Method Summary collapse
- #block_group ⇒ Object
- #bundler_def ⇒ Object
- #call ⇒ Object
- #gem_node ⇒ Object
- #group?(node) ⇒ Boolean
- #group_nodes ⇒ Object
- #groups(node) ⇒ Object
- #include_groups ⇒ Object
-
#initialize(gem_name:, gemfile_path:, ignore:, delimiter:) ⇒ Groups
constructor
A new instance of Groups.
Constructor Details
#initialize(gem_name:, gemfile_path:, ignore:, delimiter:) ⇒ Groups
Returns a new instance of Groups.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gemfile_parser/commands/groups.rb', line 28 def initialize( gem_name:, gemfile_path:, ignore:, delimiter: ) @gem_name = gem_name @gemfile_path = gemfile_path @ignore = ignore @delimiter = delimiter end |
Class Method Details
.call(gem_name:, gemfile_path:, ignore:, delimiter:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gemfile_parser/commands/groups.rb', line 13 def call( gem_name:, gemfile_path:, ignore:, delimiter: ) new( gem_name: gem_name, gemfile_path: gemfile_path, ignore: ignore, delimiter: delimiter ).call end |
Instance Method Details
#block_group ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/gemfile_parser/commands/groups.rb', line 67 def block_group if group?(group_nodes) groups(group_nodes).map { |group_sym| group_sym.children.first } else ::Kernel.abort("Please implement here.") # TODO: Implement end end |
#bundler_def ⇒ Object
56 57 58 |
# File 'lib/gemfile_parser/commands/groups.rb', line 56 def bundler_def Bundler::Definition.build(@gemfile_path, nil, nil) end |
#call ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/gemfile_parser/commands/groups.rb', line 40 def call ::Kernel.abort("Specified gem does not exist.") unless gem_node if @ignore ::Kernel.puts((bundler_def.groups - include_groups).sort.join(@delimiter)) else ::Kernel.puts(include_groups.sort.join(@delimiter)) end end |
#gem_node ⇒ Object
60 61 62 63 64 65 |
# File 'lib/gemfile_parser/commands/groups.rb', line 60 def gem_node @gem_node ||= NodeDetector.call( src_node: AstConverter.call(file_path: @gemfile_path), node: AstConverter.call(string: @gem_name) ) end |
#group?(node) ⇒ Boolean
79 80 81 |
# File 'lib/gemfile_parser/commands/groups.rb', line 79 def group?(node) node.select { |n| n == :group }.any? end |
#group_nodes ⇒ Object
75 76 77 |
# File 'lib/gemfile_parser/commands/groups.rb', line 75 def group_nodes @group_nodes ||= gem_node.root_node.children.first.children end |
#groups(node) ⇒ Object
83 84 85 |
# File 'lib/gemfile_parser/commands/groups.rb', line 83 def groups(node) node.select { |n| n.instance_of?(Parser::AST::Node) } end |
#include_groups ⇒ Object
50 51 52 53 54 |
# File 'lib/gemfile_parser/commands/groups.rb', line 50 def include_groups case gem_node.root_node.type when :block then block_group when :send then ::Kernel.abort("Please implement here.") end # TODO: Implement end |