card-mod-monkey 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dd42d4f0bc0d9579387e2ea1635f65a4b3eda7a9a652133c12e4d9c1946f70cf
4
+ data.tar.gz: 935dcf7306c5cbc030875a27120694be45b96178fa9ccaa01e7dfdd2e4d85a0a
5
+ SHA512:
6
+ metadata.gz: 041023b89d990c023a10f44c940c07d9e568fe2e0ce43e3db7ed71674f62819d781756cba231aaf950ff0adc7aaaede6ae2bb5aba55293784b43ea6d6ca0140c
7
+ data.tar.gz: 0762cacbac60d29f7d83a89b2c95b74e4a1d140573afa6b6f44b45e5b01fc3e499d526b52f02898292ab7d4af0f94415f4755c1835fbf3215c4cc58eb02e23d3
@@ -0,0 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class AddDeveloperCards < Cardio::Migration
4
+ def up
5
+ ensure_card name: "*debug",
6
+ codename: "debug"
7
+ ensure_card name: "*debug+*right+*read",
8
+ type_id: Card::PointerID,
9
+ content: "[[Administrator]]"
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require "colorize"
2
+ require "html2haml"
3
+ # require "sprockets"
4
+ # require "phantomjs"
5
+ require "better_errors"
6
+ require "binding_of_caller"
7
+ require "pry-byebug"
8
+ require "pry-rescue"
9
+ require "pry-rails"
10
+ require "pry-stack_explorer"
@@ -0,0 +1,111 @@
1
+ module Cardio
2
+ # These commands are available in the console when using binding.pry for breakpoints.
3
+ module Pry
4
+ require "rails/console/app"
5
+ require "cardio/pry/commands"
6
+ include Rails::ConsoleMethods
7
+ include Commands
8
+
9
+ def create name="test card", content="some content", type="basic"
10
+ if name.is_a? Hash
11
+ Card.create! name
12
+ elsif content.is_a? Hash
13
+ Card.create! content.merge(name: name)
14
+ else
15
+ Card.create! name: name, content: content, type: type
16
+ end
17
+ end
18
+
19
+ def update name="test card", *args
20
+ card_attr = {}
21
+ if args.first.is_a? String
22
+ card_attr[:content] = args.shift
23
+ card_attr.merge!(args.first)
24
+ else
25
+ card_attr = args.first
26
+ end
27
+ Card.fetch(name).update_attributes card_attr
28
+ end
29
+
30
+ # Shortcut for fetching cards. You can continue to work with the
31
+ # last fetched card by calling `fe` without arguments.
32
+ # If the first call of `fe` is without argument, fe points to the card "Home"
33
+ # Example:
34
+ # fe.name # => "Home"
35
+ # fe "Basic"
36
+ # fe.name # => "Basic"
37
+ # fe.type # => "cardtype"
38
+ def fe name=nil
39
+ if name
40
+ @fe = Card.fetch name
41
+ else
42
+ @fe ||= Card.fetch "home"
43
+ end
44
+ end
45
+
46
+ def cr name=nil, content="some content", type="basic"
47
+ if name
48
+ @cr = create name, content, type
49
+ else
50
+ @cr ||= create
51
+ end
52
+ end
53
+
54
+ def ab
55
+ Card::Auth.as_bot
56
+ end
57
+
58
+ # use syntax highlighting if html is detected
59
+ def puts *args
60
+ text = args.first
61
+ return super unless args.size == 1 && htmlish?(text)
62
+ html = Nokogiri::XML text, &:noblanks
63
+ puts_html(html, text) { |*super_args| super(*super_args) }
64
+ end
65
+
66
+ def htmlish? text
67
+ text.is_a?(String) && (text.match?(%r{</\w+>}) || text.include?("\e"))
68
+ end
69
+
70
+ def puts_html html, text, &block
71
+ if html.errors.present?
72
+ puts_html_errors html, text, &block
73
+ else
74
+ puts_highlighted_html html, &block
75
+ end
76
+ end
77
+
78
+ def puts_html_errors html, text
79
+ yield text
80
+ puts
81
+ yield "WARNING: detected invalid html".red
82
+ yield html.errors
83
+ end
84
+
85
+ def puts_highlighted_html html
86
+ # yield "with syntax highlighting:\n"
87
+ yield CodeRay.scan(html.root.to_s, :html).term
88
+ end
89
+
90
+ def hputs text
91
+ text = Nokogiri::XML(text, &:noblanks).root.to_s
92
+ print CodeRay.scan(text, :html).term
93
+ print "\n"
94
+ end
95
+
96
+ def _a
97
+ @_array ||= (1..6).to_a
98
+ end
99
+
100
+ def _h
101
+ @_hash ||= { hello: "world", free: "of charge" }
102
+ end
103
+
104
+ def _u
105
+ @_user ||= Card.fetch "Joe User"
106
+ end
107
+
108
+ intro = File.read File.expand_path("../pry/intro.txt", __FILE__)
109
+ puts intro
110
+ end
111
+ end
@@ -0,0 +1,63 @@
1
+ module Cardio
2
+ module Pry
3
+ # Pry command configuration
4
+ module Commands
5
+ class << self
6
+ def alias_command *args
7
+ ::Pry.config.commands.alias_command(*args)
8
+ end
9
+
10
+ def block_command *args
11
+ ::Pry.commands.block_command(*args)
12
+ end
13
+ end
14
+
15
+ ::Pry.config.editor = proc { |file, line| "mine #{file}:#{line}" }
16
+
17
+ alias_command "h", "hist -T 20", desc: "Last 20 commands"
18
+ alias_command "hg", "hist -T 20 -G", desc: "Up to 20 commands matching expression"
19
+ alias_command "hG", "hist -G", desc: "Commands matching expression ever used"
20
+ alias_command "hr", "hist -r", desc: "hist -r <command number> to run a command"
21
+ alias_command "clear", "break --delete-all", desc: "remove all break points"
22
+
23
+ # Hit Enter to repeat last command
24
+ ::Pry::Commands.command(/^$/, "repeat last command") do
25
+ pry_instance.run_command ::Pry.history.to_a.last
26
+ end
27
+
28
+ if defined?(PryByebug)
29
+ ::Pry.commands.alias_command "c", "continue"
30
+ ::Pry.commands.alias_command "s", "step"
31
+ ::Pry.commands.alias_command "n", "next"
32
+ ::Pry.commands.alias_command "f", "finish"
33
+ end
34
+
35
+ # breakpoint commands
36
+ block_command "try", "play expression in current line" do |offset|
37
+ line = target.eval("__LINE__")
38
+ line = line.to_i + offset.to_i if offset
39
+ run "play -e #{line}"
40
+ end
41
+
42
+ block_command "breakview",
43
+ "set break point where view is rendered" do |view_name, cardish|
44
+ breakpoint = "break #{Cardio.gem_root}/lib/card/format/render.rb:43"
45
+
46
+ breakpoint += " if view.to_sym == \\'#{view_name}\\'.to_sym" if view_name
47
+ breakpoint += " && card.key == \\'#{cardish}\\'.to_name.key" if cardish
48
+ run breakpoint
49
+ end
50
+
51
+ block_command "breaknest", "set break point where nest is rendered" do |card_key|
52
+ breakpoint = "break #{Cardio.gem_root}/lib/card/format/nest.rb:19"
53
+ if card_key
54
+ breakpoint += " if cardish.to_name.key == \\'#{card_key}\\'.to_name.key"
55
+ end
56
+ run breakpoint
57
+ end
58
+
59
+ alias_command "bv", "breakview"
60
+ alias_command "bn", "breaknest"
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,34 @@
1
+ == Command history ==
2
+ h : hist -T 20 Last 20 commands
3
+ hg : hist -T 20 -G Up to 20 commands matching expression
4
+ hG : hist -G Commands matching expression ever used
5
+ hr : hist -r hist -r <command number> to run a command
6
+ Hit Enter to repeat last command
7
+
8
+ == Variables ==
9
+ _u : Card["Joe User"]
10
+ _a : [1, 2, 3, 4, 5, 6]
11
+ _h : { hello: "world", free: "of charge" }
12
+
13
+ == Card commands ==
14
+ create : Card.create :name=>$1, :content=>($2||"some content"), :type=>($3||"basic")
15
+ update : Card.update :name=>$1, :content=>($2||"some content"), :type=>($3||"basic")
16
+ ab : Card::Auth.as_bot
17
+ cr : create card and assign it to cr
18
+ (default: name=>"test card", content=>"some content", type=>"basic")
19
+ fe : fetch card and assign it to fe (default: "Home")
20
+
21
+ == Breakpoints ==
22
+ breakview (bv) : set break point where view is rendered
23
+ (takes a view name and a card mark as optional argument)
24
+ breaknest (bn) : set break point where nest is rendered
25
+ (takes a card mark as optional argument)
26
+ clear : remove all break points
27
+
28
+ == Helpful debugger shortcuts ==
29
+ hputs : puts with html syntax highlighting
30
+ n : next
31
+ s : step
32
+ c : continue
33
+ f : finish
34
+ try : execute current line (without stepping forward)
@@ -0,0 +1,64 @@
1
+ # the events method is a developer's tool for visualizing the event order
2
+ # for a given card.
3
+ # For example, from a console you might run
4
+ #
5
+ # puts mycard.events :update
6
+ #
7
+ # to see the order of events that will be executed on mycard.
8
+ # The indention and arrows (^v) indicate event dependencies.
9
+ #
10
+ # Note: as of yet, the functionality is a bit rough. It does not display events
11
+ # that are called directly from within other events,
12
+ # and certain event requirements (like the presence of an 'act') may
13
+ # prevent events from showing up in the tree.
14
+ def events action
15
+ @action = action
16
+ events = Director::Stages::STAGES.map { |stage| events_tree "#{stage}_stage" }
17
+ @action = nil
18
+ print_events events
19
+ end
20
+
21
+ def events_tree filt
22
+ try("_#{filt}_callbacks")&.each_with_object({ name: filt }) do |callback, hash|
23
+ events_branch hash, callback.kind, callback.filter if callback.applies? self
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def print_events events, prefix="", depth=0
30
+ depth += 1
31
+ space = " " * (depth * 2)
32
+ text = ""
33
+ events.each do |event|
34
+ text += print_event_pre event, depth, space
35
+ text += print_event_main event, prefix
36
+ text += print_event_post event, depth, space
37
+ end
38
+ text
39
+ end
40
+
41
+ def print_event_pre event, depth, space
42
+ if event[:before]
43
+ print_events event[:before], space + "v ", depth
44
+ elsif event[:around]
45
+ print_events event[:around], space + "vv ", depth
46
+ else
47
+ ""
48
+ end
49
+ end
50
+
51
+ def print_event_main event, prefix
52
+ "#{prefix}#{event[:name]}\n"
53
+ end
54
+
55
+ def print_event_post event, depth, space
56
+ return "" unless event[:after]
57
+
58
+ print_events event[:after], space + "^ ", depth
59
+ end
60
+
61
+ def events_branch hash, kind, filter
62
+ hash[kind] ||= []
63
+ hash[kind] << events_tree(filter)
64
+ end
@@ -0,0 +1,23 @@
1
+ format :html do
2
+ view :views_by_format do
3
+ format_views =
4
+ self.class.ancestors.each_with_object({}) do |format_class, hash|
5
+ views =
6
+ format_class.instance_methods.map do |method|
7
+ next unless method.to_s =~ /^_view_(.+)$/
8
+ Regexp.last_match(1)
9
+ end.compact
10
+ next unless views.present?
11
+ format_class.name =~ /^Card(::Set)?::(.+?)$/ #::(\w+Format)
12
+ hash[Regexp.last_match(2)] = views
13
+ end
14
+ accordion_group format_views
15
+ end
16
+
17
+ view :views_by_name do
18
+ views = methods.map do |method|
19
+ Regexp.last_match(1) if method.to_s.match?(/^_view_(.+)$/)
20
+ end.compact.sort
21
+ list_group views
22
+ end
23
+ end
@@ -0,0 +1,88 @@
1
+ def virtual?
2
+ new?
3
+ end
4
+
5
+ format :html do
6
+ view :core do
7
+ core_section_config(card.left).map do |item|
8
+ section(*item)
9
+ end
10
+ end
11
+
12
+ def core_section_config subject
13
+ [["Sets", tabs("set modules" => set_modules_accordion(subject),
14
+ "all modules" => singleton_modules_list(subject),
15
+ "patterns" => set_patterns_breadcrumb(subject))],
16
+ ["Views", tabs("by format" => subformat(subject)._render_views_by_format,
17
+ "by name" => subformat(subject)._render_views_by_name)],
18
+ ["Events", tabs(create: "<pre>#{subject.events(:create)}</pre>",
19
+ update: "<pre>#{subject.events(:update)}</pre>",
20
+ delete: "<pre>#{subject.events(:delete)}</pre>")],
21
+ ["Cache/DB Comparison", cache_comparison_table(subject)]]
22
+ end
23
+
24
+ # rubocop:disable AccessorMethodName
25
+ def set_modules_accordion subject
26
+ sets = subject.set_modules.each_with_object({}) do |sm, hash|
27
+ ans = sm.ancestors
28
+ ans.shift
29
+ hash[sm.to_s] = ans
30
+ end
31
+ accordion_group sets
32
+ end
33
+
34
+ def set_patterns_breadcrumb subject
35
+ links = subject.patterns.reverse.map { |pattern| link_to_card pattern.to_s }
36
+ breadcrumb links
37
+ end
38
+ # rubocop:enable AccessorMethodName
39
+
40
+ def singleton_modules_list subject
41
+ all_mods = subject.singleton_class.ancestors.map(&:to_s)
42
+ all_mods.shift
43
+ list_group all_mods
44
+ end
45
+
46
+ def cache_comparison_table subject
47
+ cache_card = Card.fetch(subject.key)
48
+ db_card = Card.find_by_key(subject.key)
49
+ return unless cache_card && db_card
50
+ table(
51
+ %i[name updated_at updater_id content inspect].map do |field|
52
+ [field.to_s,
53
+ h(cache_card.send(field)),
54
+ h(db_card.send(field))]
55
+ end,
56
+ header: ["Field", "Cache Val", "Database Val"]
57
+ )
58
+ end
59
+
60
+ def section title, content
61
+ %(
62
+ <h2>#{title}</h2>
63
+ #{content}
64
+ )
65
+ end
66
+
67
+ def class_locations klass
68
+ methods = defined_methods(klass)
69
+ file_groups = methods.group_by { |sl| sl[0] }
70
+ file_counts = file_groups.map do |file, sls|
71
+ lines = sls.map { |sl| sl[1] }
72
+ count = lines.size
73
+ line = lines.min
74
+ { file: file, count: count, line: line }
75
+ end
76
+ file_counts.sort_by! { |fc| fc[:count] }
77
+ file_counts.map { |fc| [fc[:file], fc[:line]] }
78
+ end
79
+
80
+ def defined_methods klass
81
+ methods =
82
+ klass.methods(false).map { |m| klass.method(m) } +
83
+ klass.instance_methods(false).map { |m| klass.instance_method(m) }
84
+ methods.map!(&:source_location)
85
+ methods.compact!
86
+ methods
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: card-mod-monkey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
+ platform: ruby
6
+ authors:
7
+ - Ethan McCutchen
8
+ - Philipp Kühl
9
+ - Gerry Gleason
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2020-12-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: card
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.101.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '='
27
+ - !ruby/object:Gem::Version
28
+ version: 1.101.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: colorize
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: html2haml
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rubocop
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '='
62
+ - !ruby/object:Gem::Version
63
+ version: '0.88'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '='
69
+ - !ruby/object:Gem::Version
70
+ version: '0.88'
71
+ - !ruby/object:Gem::Dependency
72
+ name: better_errors
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: pry-rails
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: pry-rescue
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: pry-stack_explorer
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :runtime
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: pry-byebug
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ description: ''
142
+ email:
143
+ - info@decko.org
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - db/migrate_core_cards/20160812112513_add_developer_cards.rb
149
+ - lib/card/mod/monkey.rb
150
+ - lib/cardio/pry.rb
151
+ - lib/cardio/pry/commands.rb
152
+ - lib/cardio/pry/intro.txt
153
+ - set/all/event_viz.rb
154
+ - set/all/view_viz.rb
155
+ - set/right/debug.rb
156
+ homepage: http://decko.org
157
+ licenses:
158
+ - GPL-3.0
159
+ metadata:
160
+ card-mod: monkey
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '2.5'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubygems_version: 3.0.3
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: dev support for mod developers (monkeys)
180
+ test_files: []