Skip to content

Commit

Permalink
add table
Browse files Browse the repository at this point in the history
  • Loading branch information
technohippy committed Nov 15, 2013
1 parent 932d2d3 commit 7427a1a
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 23 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pry::Parsecom
# pry-parsecom

TODO: Write a gem description

Expand All @@ -18,21 +18,29 @@ Or install it yourself as:

## Usage

$ pry
$ pry-parsecom
[1] pry(main)> show-applications
Input parse.com email: [email protected]
Input parse.com password:
Name
========
FakeApp
FakeApp2
[2] pry(main)> use FakeApp
The current app is FakeApp.
[3] pry(main)> show-classes
[3] pry(main)> show-credentials
Key | Value
=========================================================
APPLICATION_ID | abcdefghijklmnopqrstuvwxyzabcdefghijklmn
REST_API_KEY | abcdefghijklmnopqrstuvwxyzabcdefghijklmn
MASTER_KEY | abcdefghij******************************
[4] pry(main)> show-classes
Comment
Post
_User
[4] pry(main)> Comment.find :all
[5] pry(main)> Comment.find :all
=> [<Comment: {"author"=>#<Parse::Pointer:0x007fc6796dbba8 @r...
[5] pry(main)> exit
[6] pry(main)> exit

## Contributing

Expand Down
9 changes: 6 additions & 3 deletions bin/pry-parsecom
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env ruby

$0 = 'pry'

begin
require 'parse/console'
require 'pry'
rescue LoadError
require 'rubygems'
require 'parse/console'
require ''
end

Parse::Console.start
ENV['ENABLE_PRY_PARSECOM'] = 'on'
Pry::CLI.parse_options
2 changes: 1 addition & 1 deletion lib/pry-parsecom.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'pry'
require 'pry-parsecom/version'

unless ENV['DISABLE_PRY_PARSECOM']
if ENV['ENABLE_PRY_PARSECOM']
require 'io/console'
require 'parsecom'
require 'mechanize'
Expand Down
6 changes: 4 additions & 2 deletions lib/pry-parsecom/commands/show_applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def options opt

def process
PryParsecom::Setting.setup_if_needed
PryParsecom::Setting.app_names.each do |app|
output.puts app
table = PryParsecom::Table.new %w(Name)
PryParsecom::Setting.app_names.each do |name|
table.add_row [name]
end
output.puts table
end
end
2 changes: 1 addition & 1 deletion lib/pry-parsecom/commands/show_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def options opt

def process
PryParsecom::Setting.setup_if_needed
table = Table.new %w(Key Value), [
table = PryParsecom::Table.new %w(Key Value), [
['APPLICATION_ID', Parse.application_id],
['REST_API_KEY', Parse.api_key],
['MASTER_KEY', (Parse.master_key || '').sub(/.{30}$/, '*' * 30)]
Expand Down
2 changes: 1 addition & 1 deletion lib/pry-parsecom/commands/use.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def options opt
end

def process
PryParsecom::Setting.setup_if_needed
unless args.size == 1
output.puts opt
return
Expand All @@ -23,7 +24,6 @@ def process
return
end

PryParsecom::Setting.setup_if_needed
unless PryParsecom::Setting.current_app.to_s.empty?
prev_setting = PryParsecom::Setting.current_setting
prev_setting.reset if prev_setting
Expand Down
6 changes: 5 additions & 1 deletion lib/pry-parsecom/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def by_name app_name
@@apps[app_name.to_s]
end
alias [] by_name

def each &block
@@apps.each &block
end
end

attr_accessor :app_name, :app_id, :api_key, :master_key, :schema
Expand All @@ -138,7 +142,7 @@ def initialize app_name, app_id, api_key, master_key, schema
end

def set
Parse.credentials :application_id => @app_id, :api_key => @api_key, :mater_key => @master_key
Parse.credentials :application_id => @app_id, :api_key => @api_key, :master_key => @master_key
Parse::Client.default.application_id = @app_id
Parse::Client.default.api_key = @api_key
Parse::Client.default.master_key = @master_key
Expand Down
20 changes: 12 additions & 8 deletions lib/pry-parsecom/table.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module PryPersecom
module PryParsecom
class Table
def initialize heads, rows=[]
@heads = heads
@rows = []
@col_widths = Hash.new 0
@heads.each do |head|
@col_widths[head] = head.size
end
self.rows = rows
end

def rows= rows
@rows.clear
@rows = []
rows.each do |row|
add_row row
end
Expand All @@ -22,26 +22,30 @@ def add_row row
@heads.each do |head|
cols << row[head]
end
else
cols = row
end

cols.each.with_index do |col, i|
if @col_widths[i] < col.size
@col_widths[i] = col.size
end
end
@rows << cols
end

def to_s
ret = @heads.map.with_index do |head, i|
head.center @col_width[i]
heads = @heads.map.with_index do |head, i|
head.center @col_widths[i]
end.join " | "
ret = heads
ret += "\n"
ret += '=' * heads.size
ret += "\n"
@rows.each do |row|
ret += row.map.with_index do |col, i|
col.left @col_width[i]
end.join " | "
ret += row.map.with_index { |col, i|
col.ljust @col_widths[i]
}.join " | "
ret += "\n"
end
ret
Expand Down
2 changes: 1 addition & 1 deletion lib/pry-parsecom/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8

module PryParsecom
VERSION = "0.0.0"
VERSION = "0.0.2"
end

0 comments on commit 7427a1a

Please sign in to comment.