Module: Scryglass

Defined in:
lib/scryglass.rb,
lib/scryglass/ro.rb,
lib/example_material.rb,
lib/scryglass/config.rb,
lib/scryglass/version.rb,
lib/scryglass/lens_panel.rb,
lib/scryglass/ro_builder.rb,
lib/scryglass/tree_panel.rb,
lib/scryglass/view_panel.rb,
lib/scryglass/lens_helper.rb,
lib/scryglass/view_wrapper.rb,
lib/scryglass/binding_tracker.rb,
lib/scryglass/session_manager.rb

Overview

test

Defined Under Namespace

Modules: LensHelper, RoBuilder Classes: BindingTracker, Config, LensPanel, Ro, Session, SessionManager, TreePanel, ViewPanel, ViewWrapper

Constant Summary collapse

HELP_SCREEN =
<<~"HELPSCREENPAGE"
        \e[36mq\e[0m : Quit Scry                               \e[36m?\e[0m : Cycle help panels (1/2)

  BASIC NAVIGATION: · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
    ·                                                                               ·
    ·   \e[36mUP / DOWN\e[0m : Navigate (To move further, type a number first or use \e[36mSHIFT\e[0m)    ·
    ·   \e[36mRIGHT\e[0m     : Expand   current or selected row(s)                             ·
    ·   \e[36mLEFT\e[0m      : Collapse current or selected row(s)                             ·
    ·                                                                               ·
    ·               (\e[36mh/j/k/l\e[0m  on the home row can also serve as arrow keys)         ·
    ·                                                                               ·
    ·   \e[36mENTER\e[0m : Close Scry, returning current or selected object(s) (Key or Value)  ·
    ·                                                                               ·
    · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·

  INSPECTING WITH LENS VIEW:  · · · · · · · · · · · · · ·
    ·                                                   ·
    ·   \e[36mSPACEBAR\e[0m : Toggle Lens View                     ·
    ·   \e[36m     >  \e[0m : Cycle through lens types             ·
    ·   \e[36m   <    \e[0m : Toggle subject  (Key/Value of row)   ·
    ·                                                   ·
    · · · · · · · · · · · · · · · · · · · · · · · · · · ·

  MORE NAVIGATION:  · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
    ·                                                                       ·
    ·   \e[36m   [w]   \e[0m :  Move view window           \e[36m0\e[0m : Reset view location     ·
    ·   \e[36m[a][s][d]\e[0m   (\e[36mALT\e[0m increases speed)      (Press again: reset cursor)  ·
    ·                                                                       ·
    · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
HELPSCREENPAGE
HELP_SCREEN_ADVANCED =
<<~"HELPSCREENADVANCEDPAGE"
        \e[36mq\e[0m : Quit Scry                               \e[36m?\e[0m : Cycle help panels (2/2)

  ADVANCED: · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
    ·  DIGGING DEEPER:                                                                    ·
    ·    For current or selected row(s)...                                                ·
    ·      \e[36m@\e[0m : Build instance variable sub-rows                                           ·
    ·      \e[36m.\e[0m : Build ActiveRecord association sub-rows                                    ·
    ·      \e[36m(\e[0m : Attempt to smart-build sub-rows, if Enumerable. Usually '@' is preferable. ·
    ·      \e[36mo\e[0m : Quick Open: builds the most likely helpful sub-rows ( '.' || '@' || '(' )  ·
    ·                                                                                     ·
    ·  SELECTING ROWS:                                                                    ·
    ·    \e[36m*\e[0m : Select/Deselect ALL rows                                                     ·
    ·    \e[36m|\e[0m : Select/Deselect every sibling row under the same parent row                  ·
    ·    \e[36m-\e[0m : Select/Deselect current row                                                  ·
    ·                                                                                     ·
    ·  MANAGING MULTIPLE SESSION TABS:                                                    ·
    ·    \e[36mTab\e[0m : Change session tab (to the right)  (\e[36mShift+Tab\e[0m moves left)                  ·
    ·      \e[36mQ\e[0m : Close current session tab                                                  ·
    ·                                                                                     ·
    ·  TEXT SEARCH:                                                                       ·
    ·    \e[36m/\e[0m : Begin a text search (in tree view)                                           ·
    ·    \e[36mn\e[0m : Move to next search result                                                   ·
    ·                                                                                     ·
    ·                                                                                     ·
    ·  \e[36m=\e[0m   : Open prompt to type a console handle for current or selected row(s)            ·
    ·                                                                                     ·
    ·  \e[36mEsc\e[0m : Resets selection, last search, and number-to-move. (or returns to Tree View) ·
    ·                                                                                     ·
    · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
HELPSCREENADVANCEDPAGE
VERSION =
"2.0.2"

Class Method Summary collapse

Class Method Details

.configObject



103
104
105
# File 'lib/scryglass.rb', line 103

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



111
112
113
# File 'lib/scryglass.rb', line 111

def self.configure
  yield(config)
end

.demo_hashObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/example_material.rb', line 65

def self.demo_hash
  {
    :time => Time.now,
    :temperature => 'Just right',
    :data => [
      [
        ScryExampleClass.new,
        ScryExampleClass.new,
      ],
      [
        ScryExampleClass.new,
        ScryExampleClass.new,
      ],
      [
        ScryExampleClass.new,
        ScryExampleClass.new,
      ],
      [
        ScryExampleClass.new,
        ScryExampleClass.new,
      ],
      [
        ScryExampleClass.new,
        ScryExampleClass.new,
      ],
      [
        ScryExampleClass.new,
        ScryExampleClass.new,
      ],
    ]
  }
end

.helpObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/scryglass.rb', line 140

def self.help
  console_help = <<~"CONSOLE_HELP" # Bolded with \e[1m
    \e[1m
    |  To prep Scryglass, call `Scryglass.load`
    |  (Or add it to .irbrc & .pryrc)
    |
    |  To start a Scry Session, call:
    |  >   scry my_object   OR
    |  >   my_object.scry
    |
    |  To resume the previous session:   (in same console session)
    |  >   scry
    \e[0m
  CONSOLE_HELP

  puts console_help
end

.loadObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/scryglass.rb', line 125

def self.load
  caller_path = caller_locations.first.path

  silent_load_result = Scryglass.load_silently

  if silent_load_result[:success]
    puts "(Scryglass is loaded, from `#{caller_path}`. Use `Scryglass.help` for help getting started)"
  else
    puts "(Scryglass failed to load, from `#{caller_path}` " \
         "getting `#{silent_load_result[:error].message}`)"
  end

  silent_load_result
end

.load_silentlyObject



115
116
117
118
119
120
121
122
123
# File 'lib/scryglass.rb', line 115

def self.load_silently
  begin
    add_kernel_method
    create_scryglass_session_manager
    { success: true, error: nil }
  rescue => e
    { success: false, error: e }
  end
end

.reset_configObject



107
108
109
# File 'lib/scryglass.rb', line 107

def self.reset_config
  @config = Config.new
end

.test_hashObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/example_material.rb', line 16

def self.test_hash
  {
    :move_into_this_sub_item_with_down_arrow => "I'm just a string",
    :disclaimer => 'This giant playground object is still no substitute for just pressing `?`...',
    :an_empty_array => [],
    :an_array_you_can_open_with_right_arrow => [
      1,
      1.0,
      'You can close this array, anywhere here, with left arrow',
      :an_empty_hash => {},
      :some_more_advanced_stuff => {
        'What about lens view?' => [
          "I'm a string, but you can prove it by pressing spacebar to toggle lens view",
          "There's lots to do with lens view, but the help screens ('?') are really best."
        ],
        'What is my cursor telling me about this Range object?' => (1...12),
        nil => "this line is so long you should use the w/a/s/d ('d' in particular) to see more. If you can see the whole line all at once, your text/screen ratio might need some balancing..." * 10,
        [1,2,3] => "Can't expand/collapse keys, sorry...",
        Scryglass::ViewWrapper.new('the actual string', string: 'This key appears differently in the tree view!') => Scryglass::ViewWrapper.new(24601, string: 'So do this integer!'),
        "A lambda" => ->(o) { puts o.inspect.upcase.reverse },
        "\n\n\n" => "If you want to know what that lambda does, move your cursor to it, press ENTER, and it will be returned to your console for you to play with!",
        'Allll the coolest stuff' => [
          Scryglass::ViewWrapper.new('https://github.com/annkissam/scryglass', string: '...Is really in the help screens (`?`) and the README. Press spacebar for README link in lens view'),
        ],
        :delicious_data => {
          :whoa_now => ([1]*800).map { rand(2) }.insert($stdout.winsize.first, 'Press zero to reset view position, then again to reset cursor there!'),
          999 => {
          4.1 => [4,1],
          5.1 => [5,1],
          6.1 => [6,1],
          7.1 => [7,1],
          8.1 => [8,1],
          9.1 => [9,1],
          0.1 => [0,1],
          1.1 => [1,1],
        },
          Array => [1,2, [1,2,[3]], [3, 88, [99, 100]], 0],
          'Some test classes with instance variables' => [
            ScryExampleClass.new,
            ScryExampleClass.new,
            ScryExampleClass.new,
            ScryExampleClass.new,
          ],
        },
      },
    ],
  }
end