Class: Mincer::Processors::PgJsonDumper::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/mincer/processors/pg_json_dumper/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(mincer, options = {}) ⇒ Processor

Returns a new instance of Processor.



6
7
8
# File 'lib/mincer/processors/pg_json_dumper/processor.rb', line 6

def initialize(mincer, options = {})
  @mincer, @args, @relation, @options = mincer, mincer.args, mincer.relation, options
end

Instance Method Details

#applyObject



10
11
12
# File 'lib/mincer/processors/pg_json_dumper/processor.rb', line 10

def apply
  @relation
end

#to_jsonObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/mincer/processors/pg_json_dumper/processor.rb', line 14

def to_json
  if dump_supported?
    result = Mincer.connection.select_all(json_query).first['json']
    return result unless @options[:singularize]
    return (result[1..-2].presence || '{}') unless @options[:root]
    (result.sub('[', '').sub(/(\])}$/, '}').presence || '{}')
  else
    warn 'To dump data to json with postgres you need to use postgres server version >= 9.2'
  end
end