class HALPresenter::Policy::Rules
Constants
- DEFAULT_PROC
Attributes
transform_rels[RW]
Public Class Methods
new()
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 8 def initialize @transform_rels = true end
Public Instance Methods
add_attribute(name, block)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 30 def add_attribute(name, block) attributes[name] = block end
add_embed(name, block)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 53 def add_embed(name, block) name = transform(name) embedded[name] = block end
add_link(rel, block)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 41 def add_link(rel, block) rel = transform(rel) links[rel] = block end
attribute_rule_for(name)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 26 def attribute_rule_for(name) attributes[name] end
defaults(*types, value: false)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 20 def defaults(*types, value: false) types.each do |t| send(t).default= Proc.new { value } end end
dup()
click to toggle source
Calls superclass method
# File lib/hal_presenter/policy/rules.rb, line 12 def dup super.tap do |copy| copy.instance_variable_set(:@attributes, attributes.dup) copy.instance_variable_set(:@links, links.dup) copy.instance_variable_set(:@embedded, embedded.dup) end end
embed_rule_for(name)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 46 def embed_rule_for(name) name = transform(name) return embedded[name] if embedded.key? name embedded[strip_curie(name)] end
link_rule_for(rel)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 34 def link_rule_for(rel) rel = transform(rel) return links[rel] if links.key? rel links[strip_curie(rel)] end
Private Instance Methods
attributes()
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 60 def attributes @attributes ||= Hash.new(DEFAULT_PROC) end
embedded()
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 68 def embedded @embedded ||= Hash.new(DEFAULT_PROC) end
links()
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 64 def links @links ||= Hash.new(DEFAULT_PROC) end
strip_curie(rel)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 72 def strip_curie(rel) rel.to_s.split(':', 2)[1]&.to_sym end
transform(rel)
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 80 def transform(rel) return rel unless transform_rels? rel.to_s.tr('-', '_').to_sym end
transform_rels?()
click to toggle source
# File lib/hal_presenter/policy/rules.rb, line 76 def transform_rels? @transform_rels end