File tree Expand file tree Collapse file tree 4 files changed +36
-5
lines changed
Expand file tree Collapse file tree 4 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module ActionPolicy
4+ module Ext
5+ # Add transform_keys to Hash for older Rubys
6+ module HashTransformKeys
7+ refine Hash do
8+ def transform_keys
9+ return enum_for ( :transform_keys ) { size } unless block_given?
10+ result = { }
11+ each_key do |key |
12+ result [ yield ( key ) ] = self [ key ]
13+ end
14+ result
15+ end
16+ end
17+ end
18+ end
19+ end
Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ module ActionPolicy # :nodoc:
99 require "action_policy/ext/yield_self_then"
1010 require "action_policy/ext/policy_cache_key"
1111
12- using ActionPolicy ::Ext ::YieldSelfThen
12+ unless "" . respond_to? ( :then )
13+ require "action_policy/ext/yield_self_then"
14+ using ActionPolicy ::Ext ::YieldSelfThen
15+ end
1316 using ActionPolicy ::Ext ::PolicyCacheKey
1417
1518 module Policy
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- require "action_policy/ext/yield_self_then"
4- using ActionPolicy ::Ext ::YieldSelfThen
3+ unless "" . respond_to? ( :then )
4+ require "action_policy/ext/yield_self_then"
5+ using ActionPolicy ::Ext ::YieldSelfThen
6+ end
7+
8+ unless { } . respond_to? ( :transform_keys )
9+ require "action_policy/ext/hash_transform_keys"
10+ using ActionPolicy ::Ext ::HashTransformKeys
11+ end
512
613module ActionPolicy
714 module Policy
Original file line number Diff line number Diff line change 99end
1010
1111module ActionPolicy
12- require "action_policy/ext/yield_self_then"
13- using ActionPolicy ::Ext ::YieldSelfThen
12+ unless "" . respond_to? ( :then )
13+ require "action_policy/ext/yield_self_then"
14+ using ActionPolicy ::Ext ::YieldSelfThen
15+ end
1416
1517 # Takes the object and a method name,
1618 # and returns the "annotated" source code for the method:
You can’t perform that action at this time.
0 commit comments