module Kelbim::PolicyTypes
Constants
- EXPANDERS
- POLICIES
- UNEXPANDERS
Public Class Methods
convert_to_dsl(policy)
click to toggle source
# File lib/kelbim/policy-types.rb, line 60 def convert_to_dsl(policy) policy_name = policy[:name] policy_type = policy[:type] policy_attrs = policy[:attributes] sym = string_to_symbol(policy_type) if (expander = EXPANDERS[sym]) policy_attrs = expander.call(policy_attrs) if policy_attrs.kind_of?(Hash) new_policy_attrs = {} policy_attrs.each do |name, value| value = value[0] if value.length < 2 new_policy_attrs[name] = value end args = new_policy_attrs.inspect.gsub(/\A\s*\{/, '').gsub(/\}\s*\Z/, '') else args = policy_attrs.inspect end else args = policy_name.inspect end "#{sym} #{args}" end
expand(sym_or_str, policy_attrs)
click to toggle source
# File lib/kelbim/policy-types.rb, line 92 def expand(sym_or_str, policy_attrs) if sym_or_str.kind_of?(String) sym_or_str = string_to_symbol(sym_or_str) end expander = EXPANDERS[sym_or_str] expander ? expander.call(policy_attrs) : policy_attrs end
name?(name_or_attrs)
click to toggle source
# File lib/kelbim/policy-types.rb, line 88 def name?(name_or_attrs) name_or_attrs.kind_of?(String) end
string_to_symbol(str)
click to toggle source
# File lib/kelbim/policy-types.rb, line 54 def string_to_symbol(str) sym = POLICIES.key(str) raise "PolicyTypes `#{str}` is not supported" unless sym return sym end
symbol_to_string(sym)
click to toggle source
# File lib/kelbim/policy-types.rb, line 48 def symbol_to_string(sym) str = POLICIES[sym] raise "PolicyTypes `#{sym}` is not supported" unless str return str end
unexpand(sym_or_str, expanded_attrs)
click to toggle source
# File lib/kelbim/policy-types.rb, line 101 def unexpand(sym_or_str, expanded_attrs) if sym_or_str.kind_of?(String) sym_or_str = string_to_symbol(sym_or_str) end unexpander = UNEXPANDERS[sym_or_str] unexpander ? unexpander.call(expanded_attrs) : expanded_attrs end