Skip to content

Commit

Permalink
chore: rename Primitives module to Primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Jan 23, 2025
1 parent bc69068 commit 975f3f2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/site_maps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def use(adapter, **options, &block)
adapter_class = if adapter.is_a?(Class) # && adapter < Adapters::Adapter
adapter
else
const_name = Primitives::String.new(adapter.to_s).classify
const_name = Primitive::String.new(adapter.to_s).classify
begin
Adapters.const_get(const_name)
rescue NameError
Expand Down
16 changes: 8 additions & 8 deletions lib/site_maps/builder/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class URL
def initialize(link, **attributes)
@attributes = DEFAULTS.merge(attributes)
@attributes[:loc] = link
@attributes[:alternates] = SiteMaps::Primitives::Array.wrap(@attributes[:alternates])
@attributes[:videos] = SiteMaps::Primitives::Array.wrap(@attributes[:videos])
@attributes[:images] = SiteMaps::Primitives::Array.wrap(@attributes[:images])
@attributes[:alternates] = SiteMaps::Primitive::Array.wrap(@attributes[:alternates])
@attributes[:videos] = SiteMaps::Primitive::Array.wrap(@attributes[:videos])
@attributes[:images] = SiteMaps::Primitive::Array.wrap(@attributes[:images])
if (video = @attributes.delete(:video))
@attributes[:videos].concat(SiteMaps::Primitives::Array.wrap(video))
@attributes[:videos].concat(SiteMaps::Primitive::Array.wrap(video))
end
if (alternate = @attributes.delete(:alternate))
@attributes[:alternates].concat(SiteMaps::Primitives::Array.wrap(alternate))
@attributes[:alternates].concat(SiteMaps::Primitive::Array.wrap(alternate))
end
if (image = @attributes.delete(:image))
@attributes[:images].concat(SiteMaps::Primitives::Array.wrap(image))
@attributes[:images].concat(SiteMaps::Primitive::Array.wrap(image))
end
@attributes[:images] = @attributes[:images][0...SiteMaps::MAX_LENGTH[:images]]
end
Expand Down Expand Up @@ -121,9 +121,9 @@ def to_xml

if self[:pagemap].is_a?(Hash) && (pagemap = self[:pagemap]).any?
builder.pagemap :PageMap do
SiteMaps::Primitives::Array.wrap(pagemap[:dataobjects]).each do |dataobject|
SiteMaps::Primitive::Array.wrap(pagemap[:dataobjects]).each do |dataobject|
builder.pagemap :DataObject, type: dataobject[:type].to_s, id: dataobject[:id].to_s do
SiteMaps::Primitives::Array.wrap(dataobject[:attributes]).each do |attribute|
SiteMaps::Primitive::Array.wrap(dataobject[:attributes]).each do |attribute|
builder.pagemap :Attribute, attribute[:value].to_s, name: attribute[:name].to_s
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/site_maps/notification/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def payload(data = nil)

# @api private
def listener_method
@listener_method ||= Primitives::String.new("on_#{id}").underscore.to_sym
@listener_method ||= Primitive::String.new("on_#{id}").underscore.to_sym
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module SiteMaps::Primitives
module SiteMaps::Primitive
class Array < ::Array
def self.wrap(object)
if object.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
end

module SiteMaps
module Primitives
module Primitive
module Output
module_function

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# noop
end

module SiteMaps::Primitives
module SiteMaps::Primitive
class String < ::String
def classify
new_str = if defined?(Dry::Inflector)
Expand Down
4 changes: 2 additions & 2 deletions lib/site_maps/runner/event_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module SiteMaps
module Runner::EventListener
extend Primitives::Output
extend Primitive::Output

module_function

def [](event_name)
method_name = Primitives::String.new(event_name).underscore.to_sym
method_name = Primitive::String.new(event_name).underscore.to_sym
return unless respond_to?(:"on_#{method_name}")

method(:"on_#{method_name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

RSpec.describe SiteMaps::Primitives::Array do
RSpec.describe SiteMaps::Primitive::Array do
describe ".wrap" do
specify do
expect(described_class.wrap(nil)).to eq([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

RSpec.describe SiteMaps::Primitives::String do
RSpec.describe SiteMaps::Primitive::String do
describe "#classify" do
context "when dry-inflector is available" do
before do
Expand Down Expand Up @@ -39,6 +39,43 @@ def self.classify(string)
end
end

describe "#constantize" do
let(:constant) { Class.new }

before do
stub_const("MyConstant", constant)
end

context "when dry-inflector is available" do
before do
stub_const("Dry::Inflector", Class.new {
def constantize(string)
MyConstant if string == "MyConstant"
end
})
end

it "returns the constantized string" do
expect(described_class.new("MyConstant").constantize).to eq(constant)
end
end

context "when active-support is available" do
before do
stub_const("ActiveSupport::Inflector", Class.new {
def self.constantize(string)
MyConstant if string == "MyConstant"
end
})
end

it "returns the constantized string" do
expect(described_class.new("MyConstant").constantize).to eq(constant)
end
end
end


describe "#underscore" do
subject { described_class.new(arg).underscore }

Expand Down
4 changes: 2 additions & 2 deletions spec/site_maps/runner/event_listener_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@
end

def colorize(*args)
SiteMaps::Primitives::Output.colorize(*args)
SiteMaps::Primitive::Output.colorize(*args)
end

def formatted_runtime(runtime)
SiteMaps::Primitives::Output.formatted_runtime(runtime)
SiteMaps::Primitive::Output.formatted_runtime(runtime)
end
end

0 comments on commit 975f3f2

Please sign in to comment.