Module: JSONResponse

Extended by:
JSONResponse
Included in:
JSONResponse
Defined in:
lib/json_response.rb

Defined Under Namespace

Classes: JSONStruct

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#attributes_for(name, options = {}) ⇒ Object



39
40
41
# File 'lib/json_response.rb', line 39

def attributes_for(name, options={})
  registry[name].build.merge(options)
end

#build(name, options = {}) ⇒ Object



35
36
37
# File 'lib/json_response.rb', line 35

def build(name, options={})
  JSON.generate(registry[name].build.merge(options))
end

#countersObject



8
9
10
# File 'lib/json_response.rb', line 8

def counters
  @counters ||= Hash.new(0)
end

#define(name, &block) ⇒ Object



31
32
33
# File 'lib/json_response.rb', line 31

def define(name, &block)
  registry[name] = JSONStruct.new(&block)
end

#next(name) ⇒ Object



12
13
14
# File 'lib/json_response.rb', line 12

def next(name)
  counters[name] += 1
end