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.3"

Instance Method Summary collapse

Instance Method Details

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



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

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

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



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

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



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

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