From b25e8b7b9ac97255934f671c34165d3810cbf5ca Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Thu, 21 Nov 2013 00:58:13 -0800 Subject: [PATCH] Change Adamantium.included to be private * Refactor to use class_eval --- config/flay.yml | 2 +- lib/adamantium.rb | 7 +++- .../adamantium/class_methods/included_spec.rb | 40 ------------------- 3 files changed, 6 insertions(+), 43 deletions(-) delete mode 100644 spec/unit/adamantium/class_methods/included_spec.rb diff --git a/config/flay.yml b/config/flay.yml index cfc03e5..12d18b2 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 7 -total_score: 56 +total_score: 53 diff --git a/lib/adamantium.rb b/lib/adamantium.rb index 73dfb98..88abd8e 100644 --- a/lib/adamantium.rb +++ b/lib/adamantium.rb @@ -48,10 +48,13 @@ def self.included(descendant) # # @api private def self.included(descendant) - descendant.extend ModuleMethods - descendant.extend ClassMethods if descendant.kind_of?(Class) + descendant.class_eval do + extend ModuleMethods + extend ClassMethods if kind_of?(Class) + end self end + private_class_method :included # Freeze the object # diff --git a/spec/unit/adamantium/class_methods/included_spec.rb b/spec/unit/adamantium/class_methods/included_spec.rb deleted file mode 100644 index 6bae5d7..0000000 --- a/spec/unit/adamantium/class_methods/included_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# encoding: utf-8 - -require 'spec_helper' - -describe Adamantium, '.included' do - let(:object) { described_class } - - subject { object.included(target) } - - let(:included_modules) do - target.singleton_class.included_modules - end - - before { subject } - - context 'when target is a module' do - let(:target) { Module.new } - - it_should_behave_like 'a command method' - - it 'includes Adamantium::ModuleMethods' do - expect(included_modules).to include(Adamantium::ModuleMethods) - end - - it 'does not include Adamantium::ClassMethods' do - expect(included_modules).to_not include(Adamantium::ClassMethods) - end - end - - context 'when target is a class' do - let(:target) { Class.new } - - it 'includes Adamantium::{Class,Module}Methods' do - expect(included_modules).to include(Adamantium::ModuleMethods) - expect(included_modules).to include(Adamantium::ClassMethods) - end - - it_should_behave_like 'a command method' - end -end