wpcli 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fca8942bc3ffe4f2bee63bea736a9889b2decbd7
4
- data.tar.gz: 72f4f7b44419d0b882bc803ff2fd91b7fbc32a27
3
+ metadata.gz: 560f99a2ca9a0c5b2045fa77d4bf89853802c9b5
4
+ data.tar.gz: 44257dfbf43d531180b5149ace6f2728d1304947
5
5
  SHA512:
6
- metadata.gz: e0bc2796da39c0b1a7d77206335a791fe87fbbab0fc5d24715e68c41d458f7792000deef98f98fb5b5b47616cc9e809c70343c9af123be1451159d3a9c6e2b4a
7
- data.tar.gz: 0c90178543388a1bd3048edff0e2a98d27f4dbfa1c62061f41848b5847095aac318ab2fd3849824679db35361cf7a7d6e96b1420491203f46937a00cb11a2cff
6
+ metadata.gz: f73bcc7de07cba8cd5df628b7a989d5583009fc989c929922aab4437a31c545fe7416c0987f700a577b64c745d9c0352c1327bd68ecbed337aa17225ef786679
7
+ data.tar.gz: 0ed2030655252ca8972364cfee879cd9c81d5116723ecb4fff73f84bebe67d2e5ec284fd347bcba510fdd36ca7fc7215f9b8089daafe12071e094b9a17929e6a
data/README.md CHANGED
@@ -8,7 +8,7 @@ Just pass commands (http://wp-cli.org/commands/) to run method and use returned
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'wpcli', "~> 0.1.0"
11
+ gem 'wpcli', "~> 0.1.2"
12
12
 
13
13
  And then execute:
14
14
 
@@ -11,35 +11,37 @@ module Wpcli
11
11
  private
12
12
 
13
13
  def parse text
14
+ first_data_row = starts_with_plus?(text) ? 3 : 1
14
15
  rows = []
15
16
  text.split("\n").each_with_index do |line, index|
16
- unless separator? line
17
- if index < 3
18
- @columns = parse_header line
17
+ unless starts_with_plus? line
18
+ separator = line.include?('|') ? '|' : "\t"
19
+ if index < first_data_row
20
+ @columns = parse_header line, separator
19
21
  else
20
- rows << parse_line(line)
22
+ rows << parse_line(line, separator)
21
23
  end
22
24
  end
23
25
  end
24
26
  rows
25
27
  end
26
28
 
27
- def parse_header line
29
+ def parse_header line, separator
28
30
  columns = []
29
- line.split('|').each_with_index do |column, index|
31
+ line.split(separator).each_with_index do |column, index|
30
32
  columns[index] = column.strip.downcase unless column.strip.empty?
31
33
  end
32
34
  columns
33
35
  end
34
- def parse_line line
36
+ def parse_line line, separator
35
37
  hash = {}
36
- line.split('|').each_with_index do |column, index|
38
+ line.split(separator).each_with_index do |column, index|
37
39
  hash[@columns[index].to_sym] = column.strip unless @columns[index].nil?
38
40
  end
39
41
  hash
40
42
  end
41
43
 
42
- def separator? line
44
+ def starts_with_plus? line
43
45
  line.start_with? "+"
44
46
  end
45
47
  end
@@ -1,3 +1,3 @@
1
1
  module Wpcli
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -10,6 +10,8 @@ describe Wpcli::Client do
10
10
  +----+--------------------------+----------------+------------------------------+---------------------+------------------------------------+
11
11
  EOF
12
12
  end
13
+ let(:wp_user_list_tabs_newlines) { "ID\tuser_login\tdisplay_name\tuser_email\tuser_registered\troles\n1\tadmin\tadmin\tadmin@domain.tld\t2014-01-07 09:04:08\tadministrator\n" }
14
+
13
15
 
14
16
  let(:wp_role_list) do <<EOF
15
17
  +------------------+------------------------------------+
@@ -69,32 +71,62 @@ EOF
69
71
  end
70
72
 
71
73
  context 'user list' do
72
- before :each do
73
- @wpcli.stub(:`).with("wp user list").and_return(wp_user_list)
74
- @array = @wpcli.run "user list"
75
- end
74
+ context 'pretty format' do
75
+ before :each do
76
+ @wpcli.stub(:`).with("wp user list").and_return(wp_user_list)
77
+ @array = @wpcli.run "user list"
78
+ end
76
79
 
77
- describe 'returns array' do
78
- it { @array.kind_of?(Array).should be(true) }
80
+ describe 'returns array' do
81
+ it { @array.kind_of?(Array).should be(true) }
79
82
 
80
- it 'which contains hashes' do
81
- @array.first.kind_of?(Hash).should be(true)
82
- end
83
+ it 'which contains hashes' do
84
+ @array.first.kind_of?(Hash).should be(true)
85
+ end
83
86
 
84
- it 'which has two hashes' do
85
- @array.size.should eq(2)
87
+ it 'which has two hashes' do
88
+ @array.size.should eq(2)
89
+ end
90
+
91
+ it 'first hash has correct columns' do
92
+ @array.first.has_key?(:id).should be(true)
93
+ @array.first.has_key?(:display_name).should be(true)
94
+ @array.first.has_key?(:user_email).should be(true)
95
+ @array.first.has_key?(:user_registered).should be(true)
96
+ @array.first.has_key?(:user_login).should be(true)
97
+ @array.first.has_key?(:roles).should be(true)
98
+ @array.first.keys.size.should eq(6)
99
+ end
100
+ end
101
+ end
102
+ context 'tabs and newlines' do
103
+ before :each do
104
+ @wpcli.stub(:`).with("wp user list").and_return(wp_user_list_tabs_newlines)
105
+ @array = @wpcli.run "user list"
86
106
  end
87
107
 
88
- it 'first hash has correct columns' do
89
- @array.first.has_key?(:id).should be(true)
90
- @array.first.has_key?(:display_name).should be(true)
91
- @array.first.has_key?(:user_email).should be(true)
92
- @array.first.has_key?(:user_registered).should be(true)
93
- @array.first.has_key?(:user_login).should be(true)
94
- @array.first.has_key?(:roles).should be(true)
95
- @array.first.keys.size.should eq(6)
108
+ describe 'returns array' do
109
+ it { @array.kind_of?(Array).should be(true) }
110
+
111
+ it 'which contains hashes' do
112
+ @array.first.kind_of?(Hash).should be(true)
113
+ end
114
+
115
+ it 'which has two hashes' do
116
+ @array.size.should eq(1)
117
+ end
118
+
119
+ it 'first hash has correct columns' do
120
+ @array.first.has_key?(:id).should be(true)
121
+ @array.first.has_key?(:display_name).should be(true)
122
+ @array.first.has_key?(:user_email).should be(true)
123
+ @array.first.has_key?(:user_registered).should be(true)
124
+ @array.first.has_key?(:user_login).should be(true)
125
+ @array.first.has_key?(:roles).should be(true)
126
+ @array.first.keys.size.should eq(6)
127
+ end
96
128
  end
97
129
  end
98
130
  end
99
131
  end
100
- end
132
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wpcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joni Hasanen