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 6, 2024
1 parent 98b901e commit 42dcb14
Show file tree
Hide file tree
Showing 5 changed files with 33 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
36 changes: 17 additions & 19 deletions lib/magic/presenter/authors.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# frozen_string_literal: true

Gem::Author ||= Struct.new(
:name,
:email,
:github,
) do
def github_url = github && "https://github.com/#{github}"
begin
require 'rubygems/author'
rescue LoadError # HACK: install magic-support
`gem install magic-support --no-lock --ignore-dependencies --no-document`
.scan(/^Successfully installed (?<full_name>.*)$/)
.first[:full_name]
.then { Bundler.bundle_path.join 'gems', *_1, 'lib' }
.then { $LOAD_PATH << _1 }

require 'rubygems/author' # 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 42dcb14

Please sign in to comment.