Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce global namespace pollution #190

Merged
merged 3 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/xcake.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'xcake/core_ext/array'
require 'xcake/core_ext/object'
require 'xcake/core_ext/class'
require 'xcake/core_ext/string'

require 'xcake/xcode/project'
Expand Down
5 changes: 0 additions & 5 deletions lib/xcake/core_ext/array.rb

This file was deleted.

14 changes: 14 additions & 0 deletions lib/xcake/core_ext/class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Xcake
module CoreExtensions
# @example Including in a class
# Class.send(:include, Xcake::CoreExtensions::ClassDescendants) # done with send because of old ruby versions
#
module ClassDescendants
# Returns all descendants of a class
#
def descendants
ObjectSpace.each_object(singleton_class).select { |klass| klass < self }
end
end
end
end
7 changes: 0 additions & 7 deletions lib/xcake/core_ext/object.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/xcake/dependency_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class DependencyProvider
def initialize(dependency_class)
plugins = dependency_class.load_plugins

@dependency_graph = plugins.map do |p|
[p, p.dependencies]
end.to_h
@dependency_graph = plugins.each_with_object({}) do |p, hash|
hash[p] = p.dependencies
end
end

def tsort_each_node(&block)
Expand Down
1 change: 1 addition & 0 deletions lib/xcake/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Generator
include Dependency
include Plugin
include Visitor
Class.send(:include, CoreExtensions::ClassDescendants) # done with send because of old ruby versions

attr_accessor :context

Expand Down
7 changes: 0 additions & 7 deletions spec/core_ext/array_spec.rb

This file was deleted.

4 changes: 3 additions & 1 deletion spec/core_ext/object_spec.rb → spec/core_ext/class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'

class Parent
Class.send(:include, Xcake::CoreExtensions::ClassDescendants) # done with send because of old ruby versions
end

class Child < Parent
Expand All @@ -9,10 +10,11 @@ class Child < Parent
class Grandchild < Child
end

describe Object do
describe Xcake::CoreExtensions do
it 'should return all descendants' do
descendants = Parent.descendants

expect(descendants.count).to eq(2)
expect(descendants).to include(Child)
expect(descendants).to include(Grandchild)
end
Expand Down