Sha256: fa3aaffa569ba9a9d9694350f8fea80686280a3882cf856231fa3f0e8422c927

Contents?: true

Size: 1.58 KB

Versions: 15

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

##
# Usage example:
#
# result = ConvenientService::Examples::Rails::Gemfile::Services::FormatGemsWithoutEnvs.result(
#   parsed_content: {
#     gems: [
#       {
#         envs: [],
#         line: %(gem "bootsnap", ">= 1.4.4", require: false)
#       },
#       {
#         envs: [],
#         line: %(gem "pg")
#       },
#       {
#         envs: [],
#         line: %(gem "rails", "~> 6.1.3", ">= 6.1.3.2")
#       },
#       {
#         envs: [],
#         line: %(gem "webpacker", "~> 5.0")
#       },
#       {
#         envs: [],
#         line: %(gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby])
#       }
#     ]
#   }
# )
#
# NOTE: Check the corresponding spec file to see more examples.
#
module ConvenientService
  module Examples
    module Rails
      module Gemfile
        module Services
          class FormatGemsWithoutEnvs
            EMPTY_LINE = ""
            ENTER = "\n"

            include RailsService::Config

            attr_accessor :parsed_content

            def result
              success(formatted_content: format_content)
            end

            private

            def format_content
              return "" if gems_without_envs.none?

              gems_without_envs
                .map { |gem| gem[:line] }
                .reduce(EMPTY_LINE.dup) { |content, line| content << line << ENTER }
            end

            def gems_without_envs
              @gems_without_envs ||= parsed_content[:gems].to_a.select { |gem| gem[:envs].none? }
            end
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.11.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.10.1 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.10.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.9.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.8.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.7.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.6.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.5.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.4.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.3.1 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.3.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.2.1 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.2.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb
convenient_service-0.1.0 lib/convenient_service/examples/rails/gemfile/services/format_gems_without_envs.rb