Class: Mincer::Processors::PgJsonDumper::Processor
- Inherits:
-
Object
- Object
- Mincer::Processors::PgJsonDumper::Processor
- Defined in:
- lib/mincer/processors/pg_json_dumper/processor.rb
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(mincer, options = {}) ⇒ Processor
constructor
A new instance of Processor.
- #to_json ⇒ Object
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, = {}) @mincer, @args, @relation, @options = mincer, mincer.args, mincer.relation, end |
Instance Method Details
#apply ⇒ Object
10 11 12 |
# File 'lib/mincer/processors/pg_json_dumper/processor.rb', line 10 def apply @relation end |
#to_json ⇒ Object
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 |