Module: Cardio::Pry

Includes:
Commands, Rails::ConsoleMethods
Defined in:
card-mod-monkey/lib/cardio/pry.rb,
card-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



97
98
99
# File 'card-mod-monkey/lib/cardio/pry.rb', line 97

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

#_hObject



101
102
103
# File 'card-mod-monkey/lib/cardio/pry.rb', line 101

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

#_uObject



105
106
107
# File 'card-mod-monkey/lib/cardio/pry.rb', line 105

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

#abObject



54
55
56
# File 'card-mod-monkey/lib/cardio/pry.rb', line 54

def ab
  Card::Auth.as_bot
end

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



46
47
48
49
50
51
52
# File 'card-mod-monkey/lib/cardio/pry.rb', line 46

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



9
10
11
12
13
14
15
16
17
# File 'card-mod-monkey/lib/cardio/pry.rb', line 9

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”



38
39
40
41
42
43
44
# File 'card-mod-monkey/lib/cardio/pry.rb', line 38

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

#hputs(text) ⇒ Object



91
92
93
94
95
# File 'card-mod-monkey/lib/cardio/pry.rb', line 91

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)


67
68
69
# File 'card-mod-monkey/lib/cardio/pry.rb', line 67

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



59
60
61
62
63
64
65
# File 'card-mod-monkey/lib/cardio/pry.rb', line 59

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)


86
87
88
89
# File 'card-mod-monkey/lib/cardio/pry.rb', line 86

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



71
72
73
74
75
76
77
# File 'card-mod-monkey/lib/cardio/pry.rb', line 71

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)


79
80
81
82
83
84
# File 'card-mod-monkey/lib/cardio/pry.rb', line 79

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



19
20
21
22
23
24
25
26
27
28
# File 'card-mod-monkey/lib/cardio/pry.rb', line 19

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