Class: Jrq::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/jrq.rb

Instance Method Summary collapse

Instance Method Details

#display(o, options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jrq.rb', line 27

def display(o, options)
  if options.raw
    if o.is_a?(Hash)
      puts JSON.pretty_generate(o)
    elsif o.is_a?(Array) && o.any?{|ob| ob.is_a?(Hash) }
      puts JSON.pretty_generate(o)
    else
      puts o
    end
  else
    puts JSON.pretty_generate(o) rescue puts o
  end
end

#run(args, opts) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jrq.rb', line 10

def run(args, opts)
  _ = JSON.load(stdin)
  _ = case _
      when Hash  then Hashie::Mash.new(_)
      when Array then _.map{|obj| Hashie::Mash.new(obj) }
      end
  if args.length.zero?
    display(_, opts)
  else
    display(eval(args.first), opts)
  end
end

#stdinObject



23
24
25
# File 'lib/jrq.rb', line 23

def stdin
  STDIN.read
end