Module: Cardio::Pry

Includes:
Commands, Rails::ConsoleMethods
Defined in:
mod/monkey/lib/cardio/pry.rb,
mod/monkey/lib/cardio/pry/commands.rb

Overview

These commands are available in the console when using binding.pry for breakpoints.

Defined Under Namespace

Modules: Commands

Instance Method Summary collapse

Methods included from Commands

alias_command, block_command

Instance Method Details

#_aObject



99
100
101
# File 'mod/monkey/lib/cardio/pry.rb', line 99

def _a
  @_array ||= (1..6).to_a
end

#_hObject



103
104
105
# File 'mod/monkey/lib/cardio/pry.rb', line 103

def _h
  @_hash ||= { hello: "world", free: "of charge" }
end

#_uObject



107
108
109
# File 'mod/monkey/lib/cardio/pry.rb', line 107

def _u
  @_user ||= Card.fetch "Joe User"
end

#abObject



56
57
58
# File 'mod/monkey/lib/cardio/pry.rb', line 56

def ab
  Card::Auth.as_bot
end

#cr(name = nil, content = "some content", type = "basic") ⇒ Object



48
49
50
51
52
53
54
# File 'mod/monkey/lib/cardio/pry.rb', line 48

def cr name=nil, content="some content", type="basic"
  if name
    @cr = create name, content, type
  else
    @cr ||= create
  end
end

#create(name = "test card", content = "some content", type = "basic") ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'mod/monkey/lib/cardio/pry.rb', line 11

def create name="test card", content="some content", type="basic"
  if name.is_a? Hash
    Card.create! name
  elsif content.is_a? Hash
    Card.create! content.merge(name: name)
  else
    Card.create! name: name, content: content, type: type
  end
end

#fe(name = nil) ⇒ Object

Shortcut for fetching cards. You can continue to work with the last fetched card by calling fe without arguments. If the first call of fe is without argument, fe points to the card “Home” Example: fe.name # => “Home” fe “Basic” fe.name # => “Basic” fe.type # => “cardtype”



40
41
42
43
44
45
46
# File 'mod/monkey/lib/cardio/pry.rb', line 40

def fe name=nil
  if name
    @fe = Card.fetch name
  else
    @fe ||= Card.fetch "home"
  end
end

#hputs(text) ⇒ Object



93
94
95
96
97
# File 'mod/monkey/lib/cardio/pry.rb', line 93

def hputs text
  text = Nokogiri::XML(text, &:noblanks).root.to_s
  print CodeRay.scan(text, :html).term
  print "\n"
end

#htmlish?(text) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'mod/monkey/lib/cardio/pry.rb', line 69

def htmlish? text
  text.is_a?(String) && (text.match?(%r{</\w+>}) || text.include?("\e"))
end

#puts(*args) ⇒ Object

use syntax highlighting if html is detected



61
62
63
64
65
66
67
# File 'mod/monkey/lib/cardio/pry.rb', line 61

def puts *args
  text = args.first
  return super unless args.size == 1 && htmlish?(text)

  html = Nokogiri::XML text, &:noblanks
  puts_html(html, text) { |*super_args| super(*super_args) }
end

#puts_highlighted_html(html) {|CodeRay.scan(html.root.to_s, :html).term| ... } ⇒ Object

Yields:

  • (CodeRay.scan(html.root.to_s, :html).term)


88
89
90
91
# File 'mod/monkey/lib/cardio/pry.rb', line 88

def puts_highlighted_html html
  # yield "with syntax highlighting:\n"
  yield CodeRay.scan(html.root.to_s, :html).term
end

#puts_html(html, text, &block) ⇒ Object



73
74
75
76
77
78
79
# File 'mod/monkey/lib/cardio/pry.rb', line 73

def puts_html html, text, &block
  if html.errors.present?
    puts_html_errors html, text, &block
  else
    puts_highlighted_html html, &block
  end
end

#puts_html_errors(html, text) {|text| ... } ⇒ Object

Yields:

  • (text)


81
82
83
84
85
86
# File 'mod/monkey/lib/cardio/pry.rb', line 81

def puts_html_errors html, text
  yield text
  puts
  yield "WARNING: detected invalid html".red
  yield html.errors
end

#update(name = "test card", *args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'mod/monkey/lib/cardio/pry.rb', line 21

def update name="test card", *args
  card_attr = {}
  if args.first.is_a? String
    card_attr[:content] = args.shift
    card_attr.merge!(args.first)
  else
    card_attr = args.first
  end
  Card.fetch(name).update_attributes card_attr
end