Skip to content

Commit

Permalink
Framework / spec: refactored author info
Browse files Browse the repository at this point in the history
* Improved the API.
* Extracted `Gem::Author` into Magic Support.
* Replaced `Magic::Presenter::AUTHORS` with `Magic::Presenter::Author`.
  • Loading branch information
Alexander-Senko committed Dec 12, 2024
1 parent 2855cf5 commit 8cfedd0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.1.0] — UNRELEASED


## [1.0.0] — 2024-11-23

This release marks the gem to be stable enough.
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'puma'

gem 'sqlite3'
gem 'combustion'
gem 'magic-support'

group :test do
gem 'rspec'
Expand Down
38 changes: 19 additions & 19 deletions lib/magic/presenter/authors.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# frozen_string_literal: true

Gem::Author ||= Struct.new(
:name,
:email,
:github,
) do
def github_url = github && "https://github.com/#{github}"
begin
gem_original_require lib = 'rubygems/author'
rescue LoadError => error # HACK: install magic-support
raise unless error.path == lib

`gem install #{name = 'magic-support'} --ignore-dependencies --no-document`
.match(/^Successfully installed (?<full_name>#{name}-.*)$/)
&.match(:full_name)
&.then { Bundler.bundle_path.join 'gems', _1, 'lib' }
&.then { $LOAD_PATH << _1 }

require error.path # retry
end

module Magic
module Presenter # :nodoc:
AUTHORS = [ # rubocop:disable Style/MutableConstant
Gem::Author.new(
name: 'Alexander Senko',
email: 'Alexander.Senko@gmail.com',
github: 'Alexander-Senko',
),
]

class << AUTHORS
def names = filter_map &:name
def emails = filter_map &:email
def github_url = filter_map(&:github_url).first
module Presenter
class Author < Gem::Author # :nodoc:
new(
name: 'Alexander Senko',
email: 'Alexander.Senko@gmail.com',
github: 'Alexander-Senko',
)
end
end
end
2 changes: 1 addition & 1 deletion lib/magic/presenter/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Magic
module Presenter
VERSION = '1.0.0'
VERSION = '1.1.0.alpha'
end
end
6 changes: 3 additions & 3 deletions magic-presenter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require_relative 'lib/magic/presenter/authors'
Gem::Specification.new do |spec|
spec.name = 'magic-presenter'
spec.version = Magic::Presenter::VERSION
spec.authors = Magic::Presenter::AUTHORS.names
spec.email = Magic::Presenter::AUTHORS.emails
spec.homepage = "#{Magic::Presenter::AUTHORS.github_url}/#{spec.name}"
spec.authors = Magic::Presenter::Author.names
spec.email = Magic::Presenter::Author.emails
spec.homepage = "#{Magic::Presenter::Author.github_url}/#{spec.name}"
spec.summary = 'Presentation layer for Rails models'
spec.description = 'Based on Magic Decorator, it’s meant to replace Draper.'
spec.license = 'MIT'
Expand Down
9 changes: 9 additions & 0 deletions sig/magic/presenter/author.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Magic
module Presenter
class Author < Gem::Author
extend Gem::Author::ClassMethods

attr_reader self.all: Array[self]
end
end
end

0 comments on commit 8cfedd0

Please sign in to comment.