Module: Bldr

Defined in:
lib/bldr.rb,
lib/bldr/node.rb,
lib/bldr/railtie.rb,
lib/bldr/version.rb,
lib/bldr/template.rb

Defined Under Namespace

Classes: Node, Railtie, Template

Constant Summary collapse

VERSION =
'1.0.1'

Class Method Summary collapse

Class Method Details

.handler(klass, &block) ⇒ Object

Define a custom handler.

Examples:

Over-riding BSON::ObjectId

Bldr.handler BSON::ObjectId do |value|
  val.to_s # => "4e77a682364141ecf5000002"
end

Parameters:

  • klass (Class)

    The klass name of the class to match

  • block (Proc)

    The code to execute to properly format the data

Raises:

  • (ArgumentError)


30
31
32
33
34
35
# File 'lib/bldr.rb', line 30

def handler(klass,&block)
  raise(ArgumentError, "You must pass a Proc") if block.nil?
  raise(ArgumentError, "You must pass only one argument to the Proc") unless block.arity == 1

  handlers[klass] = block
end

.handlersObject



37
38
39
# File 'lib/bldr.rb', line 37

def handlers
  @handlers ||= {}
end

.json_encoder=(encoder) ⇒ Object



17
18
19
# File 'lib/bldr.rb', line 17

def json_encoder=(encoder)
  MultiJson.engine = encoder
end