Class: Shaven::Transformer::Context

Inherits:
Base
  • Object
show all
Defined in:
lib/shaven/transformers/context.rb

Overview

This transformer Can be applied only when value is an instance of Hash, Shaven::Scope, or Shaven::Preseneter. It doesn’t modify anything within given node, but modifies context for childrens.

Example

<div rb="user">
  <div rb="name">John Doe</div>
  <div rb="email">[email protected]</div>
</div>

applied with given value:

{ :name => "Marty Macfly", :email => "[email protected]" }

… generates:

<div>
  <div>Marty Macfly</div>
  <div>[email protected]</div>
</div>

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.can_be_transformed?(value) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/shaven/transformers/context.rb', line 26

def self.can_be_transformed?(value)
  value.is_a?(::Hash)
end

Instance Method Details

#transform!Object



30
31
32
# File 'lib/shaven/transformers/context.rb', line 30

def transform!
  value.stringify_keys
end