Sha256: 702e242a36797030d461bb8647bac52bf69e143822c1ab2d0edeff5a2f4a3d47

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Foobara
  module Generators
    module RedisCrudDriverGenerator
      module Generators
        # Kind of tricky... for the first time we will be loading an existing file in the working directory
        # and modifying it.
        class GemfileGenerator < RedisCrudDriverGenerator
          def applicable?
            gemfile_contents !~ /^\s*gem\s*["']foobara-redis-crud-driver\b/
          end

          def template_path
            "Gemfile"
          end

          def target_path
            "Gemfile"
          end

          def generate(_elements_to_generate)
            match = gemfile_contents.match(/^gem /)

            if match
              new_entry = 'gem "foobara-redis-crud-driver", github: "foobara/redis-crud-driver"'
              "#{match.pre_match}\n#{new_entry}\n#{match}#{match.post_match}"
            else
              # TODO: maybe print a warning and return the original Gemfile
              # :nocov:
              raise "Not sure how to inject redis_crud_driver into the Gemfile"
              # :nocov:
            end
          end

          def gemfile_contents
            File.read(template_path)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foobara-redis-crud-driver-generator-0.0.3 src/generators/gemfile_generator.rb
foobara-redis-crud-driver-generator-0.0.2 src/generators/gemfile_generator.rb
foobara-redis-crud-driver-generator-0.0.1 src/generators/gemfile_generator.rb