Skip to content

Commit 3b29270

Browse files
committed
replace activesupport/concern
Signed-off-by: neha-p6 <neha.pansare@progress.com>
1 parent 59d15c5 commit 3b29270

2 files changed

Lines changed: 41 additions & 11 deletions

File tree

oc-chef-pedant/lib/pedant/concern.rb

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,42 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# ActiveSupport::Concern is needed to help abstract out the boilerplate for creating includable modules
17-
# TODO: Consider embedding active_support/concern directly. The difference in license will have to be addressed.
18-
19-
require "active_support/concern"
16+
# Light Concern implementation without ActiveSupport
2017

2118
module Pedant
22-
Concern = ActiveSupport::Concern
19+
module Concern
20+
def self.extended(base)
21+
base.instance_variable_set(:@_dependencies, [])
22+
end
23+
24+
def included(base = nil, &block)
25+
if base.nil?
26+
raise MultipleIncludedBlocks if instance_variable_defined?(:@_included_block)
27+
@_included_block = block
28+
else
29+
super
30+
31+
if instance_variable_defined?(:@_included_block)
32+
base.class_eval(&@_included_block)
33+
end
34+
35+
const_get(:ClassMethods).tap do |class_methods|
36+
base.extend(class_methods) if defined?(class_methods)
37+
end if const_defined?(:ClassMethods)
38+
39+
@_dependencies.each { |dep| base.include(dep) }
40+
end
41+
end
42+
43+
def append_features(base)
44+
return false if base < self
45+
super
46+
(@_dependencies ||= []).each { |dep| base.include(dep) }
47+
end
2348

24-
# This is a trick passed on by Dan Deleo. This creates a module Pedant::Concern that
25-
# is exactly ActiveSupport::Concern. We can then reference Pedant::Concern instead of
26-
# ActiveSupport::Concern. If we want to embed ActiveSupport::Concern, we can fill out
27-
# Pedant::Concern without having to do a massive refactor.
49+
def class_methods(&block)
50+
mod = const_defined?(:ClassMethods, false) ? const_get(:ClassMethods) : const_set(:ClassMethods, Module.new)
51+
mod.module_eval(&block)
52+
end
53+
end
2854
end

oc-chef-pedant/lib/pedant/rspec/role_util.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
require "pedant/request"
1717
require "rspec/core/shared_context"
18-
require "active_support/core_ext/hash/keys"
1918
require "pedant/concern"
2019

2120
module Pedant
@@ -24,6 +23,11 @@ module RoleUtil
2423
extend ::RSpec::Core::SharedContext
2524
extend ::Pedant::Concern
2625

26+
# Helper to stringify hash keys without ActiveSupport
27+
def self.stringify_keys(hash)
28+
hash.transform_keys(&:to_s)
29+
end
30+
2731
# Add some context-level helper macros
2832
module ClassMethods
2933

@@ -329,7 +333,7 @@ def new_role(name, opts = {}, lists = {} )
329333
"chef_type" => "role",
330334
"run_list" => [],
331335
"env_run_lists" => lists[:env_run_lists] || {},
332-
}.merge(opts.stringify_keys).merge(lists.stringify_keys)
336+
}.merge(RoleUtil.stringify_keys(opts)).merge(RoleUtil.stringify_keys(lists))
333337
# TODO: For backwards compatibility. This should be simplified to arity 1 and the tests refactored
334338
end
335339
end

0 commit comments

Comments
 (0)