Skip to content

Instantly share code, notes, and snippets.

View MaksimenkoPG's full-sized avatar

Maksimenko Pavel MaksimenkoPG

  • [d.i.p]team
  • Luxembourg
View GitHub Profile
# lib/print_repository_info.rb
module PrintRepositoryInfo
DEFAULT_URL = 'https://api.github.com/repos/MaksimenkoPG/ruby_app_boilerplate'.freeze
extend self
def perform(url:)
response = Downloader.perform url: url || DEFAULT_URL
Printer.perform status: response.status, body: response.body
end
# lib/downloader.rb
require 'faraday'
module Downloader
extend self
def perform(url:)
Faraday.get(url)
end
end
# lib/printer.rb
module Printer
extend self
def perform(status:, body:)
puts status
puts body
end
end
# lib/tasks/print_repository_info.rake
desc 'Print repo info, usage: rake print_repository_info repository_url=repository_url'
task :print_repository_info do
PrintRepositoryInfo.perform url: ENV['repository_url']
end
rake aborted!
NameError: uninitialized constant PrintRepositoryInfo
lib/tasks/print_repository_info.rake:3:in `block in <top (required)>'
# config/application.rb
require_relative 'boot'
module Application
extend self
def root
@root ||= File.dirname(File.expand_path(__dir__))
end
# config/boot.rb
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
# irb
require_relative 'config/application'
PrintRepositoryInfo.perform(url: 'https://api.github.com/repos/rails/rails')
desc 'Foo'
task foo: :environment do
...
end