redminerb 0.6.0 → 0.7.0

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: 347a49accfc5f3a6e6d4eea8e48976443773c6ab
4
- data.tar.gz: 1352e7491d1e6675829e95e2b1c94ade493a9aa3
3
+ metadata.gz: 747f0c97c7d76ba854ec38522436b28472ff06cf
4
+ data.tar.gz: c865d6012d0e98fd83509f123271d7e384e203ea
5
5
  SHA512:
6
- metadata.gz: a98f2a26498d4a7a1fce4b1f160901d755114b4b9d62d855389648657152144a06967688029fca52e0894e6b541e5bbb45761ca80c5490ba08a9c7717a0df600
7
- data.tar.gz: e5958d2ad1fa6406815482acfb90068fa68e0f7eff5f3e925fdedc8d3248f7ef4c12df4e7c2b525be4696e392b2cbbd1575d448f31854fd38038d026c5107cfc
6
+ metadata.gz: 575252af1e2233e0743ca70a6324e4a0f2457756775c3c6836ab68c6f1e1ca1ece024653e1d136f79e4eeefbd1380aa016e787ccb6ae50d9c57252e823f5f4d4
7
+ data.tar.gz: 4a81b7ab83059a60cfd08e9228f38b4fbbccca846a10e03c31d9da07b95df84b3f9d29f181671a9b9bc1f72c888cf3c2eb4cd5a7933e8d46c3e1ae70d8257f52
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ = CHANGELOG
2
+ == 0.7, released 2015-10-05
3
+
4
+ * Show subcommand's +--template+ option for user/issue command to indicate the .erb template to render.
5
+ * Optimized & unified the default subcommand (list/show).
6
+ * ASCII box chars "helpers" added to the Redminerb module singleton functions.
7
+ * Two alternative views (*issue_boxie.erb* and *user_in_a_box.erb*).
8
+
1
9
  == 0.6, released 2015-09-28
2
10
 
3
11
  * +templates/issue.erb+ uses a recursive OStruct for internal objects -letting us for example say +issue.author.name+ instead of +issue.author['name']+
data/README.md CHANGED
@@ -36,7 +36,6 @@ Or install it yourself as:
36
36
 
37
37
  In order to use `redminerb` the URL and the API key of your Redmine REST API must be available in one of the following places:
38
38
 
39
-
40
39
  1. **In your environment**: using *REDMINERB_URL* and *REDMINERB_API_KEY* env. vars.
41
40
  2. **In `~/.redminerb.yml`**: as values of *url* and *api_key*.
42
41
 
@@ -50,19 +49,56 @@ Would be the same as having the following in your environment (declared in `~/.b
50
49
  export REDMINERB_URL=http://localhost:3000/
51
50
  export REDMINERB_API_KEY=69b47d74e36a6757bac5d45f8398dd23bfa8f52c
52
51
 
53
- If both present environment variables have priority.
52
+ If both present **environment variables have priority**.
53
+
54
+ As a general rule, the `list` subcomand is the one assumed when omitted, but if a number is given instead of a subcomand, then the `show` subcommand will be call using that number as param. For example `redminerb users 1` will show us the info of the first user of our Redmine. Notice that also the singular can be used for the command, which is nice for these cases (i.e. `redminerb user 1`, thanks Thor!)
55
+
56
+ ### Pagination
54
57
 
55
58
  Collections of resources will give us the results as indicated by the
56
59
  [Redmine pagination documentation](http://www.redmine.org/projects/redmine/wiki/Rest_api#Collection-resources-and-pagination) and the *--limit (-l)* and *--offset (-o)* options can be used.
57
60
 
58
61
  For example, you could see the third user of your Redmine with:
59
62
 
63
+ $ redminerb users list --offset 3 --limit 1
64
+
65
+ That is the same than asking for:
66
+
60
67
  $ redminerb users -o 3 -l 1
61
68
 
62
- The output of particular resources can be customized creating the corresponding `.erb` file in the *.redminerb/templates* directory (the default templates could be found in the *templates* directory).
69
+ Because `list` is the default subcommand for the `users` command.
70
+
71
+ ### Custom ERB templates
72
+
73
+ The output of **a single resource** obtained with **the `show` subcommand can be customized creating the corresponding `.erb` file** in the *.redminerb/templates* directory. In the template we can access to the resource using its generic name, e.g. `user` or `issue`.
74
+
75
+ The default templates could be found in the *templates* directory.
76
+
77
+ For example, to customize the output of an issue, we could write the following content in the `.redminerb/issue.erb`:
78
+
79
+ Number: <%= issue.id %>
80
+ Title: <%= issue.subject %>
63
81
 
64
82
  The *.redminerb* directory will be search in your current directory first, and then in your home directory.
65
83
 
84
+ We can also create other templates and use them through **the `--template` option**. For example:
85
+
86
+ $ redminerb users show 34 --template user_in_a_box
87
+
88
+ Will use the file `.redminerb/user_in_a_box.erb` as template, whose content could be the following:
89
+
90
+ <%= Redminerb.top %>
91
+ <%= Redminerb.line user.login %>
92
+ <%= Redminerb.bottom %>
93
+
94
+ As you can see Redminerb give us also some functions to draw its output using old-school boxes. These functions are:
95
+
96
+ * **Redminerb.top**: shows the top of the box (i.e. `┌──────┐`).
97
+ * **Redminerb.middle**: shows a line in the middle of the box (i.e. `├──────┤`).
98
+ * **Redminerb.bottom**: shows the bottom of the box (i.e. `└──────┘`).
99
+ * **Redminerb.line** *string*: content into the box (i.e. `│ Example │`).
100
+ * **Redminerb.separator**: a line from left to right (like *middle* wo/ box borders).
101
+
66
102
  ### Configuration (config)
67
103
 
68
104
  To see the current configuration used by Redminerb we have the `config` command:
@@ -110,7 +146,7 @@ the API key used to access the Rest API (hopefully your data :).
110
146
 
111
147
  #### Show user's data
112
148
 
113
- $ redminerb users show <id>
149
+ $ redminerb users [show] <id> # aka "redminerb users <id>"
114
150
 
115
151
  Will give us the info associated with the user with the given *id*.
116
152
 
@@ -141,7 +177,7 @@ The **issues** command is the wrapper for part of the [Issues resource](http://w
141
177
 
142
178
  #### List issues
143
179
 
144
- $ redminerb issues list
180
+ $ redminerb issues list # aka "redminerb issues"
145
181
 
146
182
  #### Show an issue
147
183
 
@@ -151,10 +187,6 @@ Shows the info of an issue with a number or id.
151
187
 
152
188
  For example, to see the info of the issue #12532 we'd launch:
153
189
 
154
- $ redminerb issues show 12539
155
-
156
- *show* is the default subcommand, so the following order has the same output as the following:
157
-
158
190
  $ redminerb issues 12539
159
191
 
160
192
  ## Development
@@ -5,22 +5,27 @@ module Redminerb
5
5
  module Cli
6
6
  # Thor's 'issues' subcommand definition
7
7
  class Issues < Thor
8
- default_command :show
8
+ default_command :list
9
9
 
10
10
  desc 'list', 'Shows open issues in our Redmine'
11
11
  option :offset, aliases: :o
12
12
  option :limit, aliases: :l
13
- def list
14
- Redminerb.init!
15
- Redminerb::Issues.list(options).each do |issue|
16
- puts "[#{issue.id}] ".blue + issue.subject.green
13
+ def list(issue_id = nil)
14
+ if issue_id
15
+ show(issue_id)
16
+ else
17
+ Redminerb.init!
18
+ Redminerb::Issues.list(options).each do |issue|
19
+ puts "[#{issue.id}] ".blue + issue.subject.green
20
+ end
17
21
  end
18
22
  end
19
23
 
20
- desc 'show <number>', 'Shows the data of the issue which id match with #<number>'
24
+ desc 'show <number>', 'Shows an issue (SHORTCUT: "redminerb issues <number>")'
25
+ option :template, aliases: :t
21
26
  def show(issue_id)
22
27
  Redminerb.init!
23
- puts Redminerb::Template.render(:issue, Redminerb::Issues.read(issue_id))
28
+ puts Redminerb::Template.render(:issue, Redminerb::Issues.read(issue_id), options)
24
29
  end
25
30
  end
26
31
  end
@@ -12,11 +12,15 @@ module Redminerb
12
12
  option :name, aliases: [:q, '--query'], banner: '<FILTER>'
13
13
  option :offset, aliases: :o
14
14
  option :limit, aliases: :l
15
- def list
16
- Redminerb.init!
17
- fields = options.delete(:fields) || 'id:login:mail'
18
- Redminerb::Users.list(options).each do |user|
19
- puts fields.split(':').map {|f| user.send(f)}.join("\t").green
15
+ def list(user_id = nil)
16
+ if user_id
17
+ show user_id
18
+ else
19
+ Redminerb.init!
20
+ fields = options.delete(:fields) || 'id:login:mail'
21
+ Redminerb::Users.list(options).each do |user|
22
+ puts fields.split(':').map {|f| user.send(f)}.join("\t").green
23
+ end
20
24
  end
21
25
  end
22
26
 
@@ -39,10 +43,11 @@ module Redminerb
39
43
  end
40
44
  end
41
45
 
42
- desc 'show <id>', 'Shows the info of the user with id <id>.'
46
+ desc 'show <id>', 'Shows a user (SHORTCUT: "redminerb users <id>").'
47
+ option :template, aliases: :t
43
48
  def show(user_id)
44
49
  Redminerb.init!
45
- puts Redminerb::Template.render(:user, Redminerb::Users.read(user_id))
50
+ puts Redminerb::Template.render(:user, Redminerb::Users.read(user_id), options)
46
51
  end
47
52
  end
48
53
  end
@@ -7,8 +7,6 @@ module Redminerb
7
7
  class Client
8
8
  class UnprocessableEntity < StandardError; end
9
9
 
10
- attr_reader :connection
11
-
12
10
  def initialize(cfg)
13
11
  @connection = Faraday.new(url: cfg.url) do |f|
14
12
  f.adapter Faraday.default_adapter
@@ -31,10 +31,10 @@ module Redminerb
31
31
  # Redminerb::Template.render(:issue, {subject: 'Fixme!'})
32
32
  #
33
33
 
34
- def render(name, resource)
34
+ def render(name, resource, options = {})
35
35
  b = binding
36
36
  b.local_variable_set(name, resource)
37
- template = _read_template(name)
37
+ template = _read_template(options['template'] || name)
38
38
  ERB.new(template).result(b)
39
39
  end
40
40
 
@@ -1,4 +1,4 @@
1
1
  # Copyright (c) The Cocktail Experience S.L. (2015)
2
2
  module Redminerb
3
- VERSION = '0.6.0'
3
+ VERSION = '0.7.0'
4
4
  end
data/lib/redminerb.rb CHANGED
@@ -43,14 +43,45 @@ module Redminerb
43
43
  end
44
44
 
45
45
  def config
46
+ init_required!
46
47
  @config
47
48
  end
48
49
 
49
50
  def client
51
+ init_required!
50
52
  @client
51
53
  end
52
54
 
55
+ # ASCII old-school box's part output functions
53
56
  def separator
54
- @separator ||= ('─' * TermInfo.screen_columns).green
57
+ @separator ||= '─' * TermInfo.screen_columns
58
+ end
59
+
60
+ def top
61
+ '┌' + separator[0..-3] + '┐'
62
+ end
63
+
64
+ def middle
65
+ '├' + separator[0..-3] + '┤'
66
+ end
67
+
68
+ def bottom
69
+ '└' + separator[0..-3] + '┘'
70
+ end
71
+
72
+ def max_length
73
+ TermInfo.screen_columns - 4
74
+ end
75
+
76
+ def line(string)
77
+ if string.size > max_length
78
+ "│ #{string[0..(max_length - 1)]} │\n#{line(string[max_length..-1])}" if string
79
+ else
80
+ "│ #{string}#{extra_espaces_for(string)} │"
81
+ end
82
+ end
83
+
84
+ def extra_espaces_for(string)
85
+ ' ' * (max_length - string.size)
55
86
  end
56
87
  end
data/redminerb.gemspec CHANGED
@@ -41,6 +41,8 @@ Gem::Specification.new do |spec|
41
41
 
42
42
  spec.add_development_dependency 'minitest'
43
43
  spec.add_development_dependency 'climate_control' # fake ENV
44
+ spec.add_development_dependency 'minitest-vcr'
45
+ spec.add_development_dependency 'webmock'
44
46
 
45
47
  spec.add_development_dependency 'rubocop'
46
48
 
data/templates/issue.erb CHANGED
@@ -1,12 +1,12 @@
1
- <%= Redminerb.separator %>
1
+ <%= Redminerb.separator.green %>
2
2
  <%= "[#{issue.tracker.name}]".blue + "[#{issue.project.name}:##{issue.id}]".green %> <%= issue.subject %>
3
- <%= Redminerb.separator %>
3
+ <%= Redminerb.separator.green %>
4
4
  Author: <%= issue.author.name.red %>
5
5
  Assigned to: <%= issue.assigned_to.name.red %>
6
6
  Status: <%= issue.status.name.red %>
7
7
  Priority: <%= issue.priority.name.red %>
8
- <%= Redminerb.separator %>
8
+ <%= Redminerb.separator.green %>
9
9
  <%= issue.description %>
10
- <%= Redminerb.separator %>
10
+ <%= Redminerb.separator.green %>
11
11
  <%= Redminerb.config.url + "issues/#{issue.id}" %>
12
- <%= Redminerb.separator %>
12
+ <%= Redminerb.separator.green %>
@@ -0,0 +1,18 @@
1
+ <%=
2
+ [
3
+ Redminerb.top,
4
+ Redminerb.line("[#{issue.tracker.name}][#{issue.project.name}:##{issue.id}] #{issue.subject}"),
5
+ Redminerb.middle,
6
+ [
7
+ "Author: #{issue.author.name}",
8
+ "Assigned to: #{issue.assigned_to.name}",
9
+ "Status: #{issue.status.name}",
10
+ "Priority: #{issue.priority.name}"
11
+ ].map{|l| Redminerb.line l },
12
+ Redminerb.middle,
13
+ issue.description.lines.map {|raw_line| Redminerb.line raw_line.chomp },
14
+ Redminerb.middle,
15
+ Redminerb.line(Redminerb.config.url + "issues/#{issue.id}"),
16
+ Redminerb.bottom
17
+ ].flatten.join.green
18
+ %>
data/templates/user.erb CHANGED
@@ -1,13 +1,13 @@
1
- <%= Redminerb.separator %>
1
+ <%= Redminerb.separator.green %>
2
2
  <%= user.login.upcase.green %>
3
- <%= Redminerb.separator %>
4
- <%= "Id: #{user.id}".blue %>
3
+ <%= Redminerb.separator.green %>
4
+ Id: <%= "##{user.id}" %>
5
5
  * Firstname: <%= user.firstname.red %>
6
6
  * Lastname: <%= user.lastname.red %>
7
7
  * Login: <%= user.login.red %>
8
8
  * E-Mail: <%= user.mail.red %>
9
- <%= Redminerb.separator %>
9
+ <%= Redminerb.separator.green %>
10
10
  * Created: <%= user.created_on.blue %>
11
11
  * Last login: <%= user.last_login_on.blue %>
12
12
  * Status: <%= user.status.to_s.blue %>
13
- <%= Redminerb.separator %>
13
+ <%= Redminerb.separator.green %>
@@ -0,0 +1,21 @@
1
+ <%=
2
+ [
3
+ Redminerb.top,
4
+ Redminerb.line(user.login.upcase),
5
+ Redminerb.middle,
6
+ [
7
+ "* Id: #{user.id}",
8
+ "* Firstname: #{user.firstname}",
9
+ "* Lastname: #{user.lastname}",
10
+ "* Login: #{user.login}",
11
+ "* E-Mail: #{user.mail}"
12
+ ].map{|l| Redminerb.line l },
13
+ Redminerb.middle,
14
+ [
15
+ "* Created: #{user.created_on}",
16
+ "* Last login: #{user.last_login_on}",
17
+ "* Status: #{user.status}"
18
+ ].map{|l| Redminerb.line l },
19
+ Redminerb.bottom
20
+ ].join.green
21
+ %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redminerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Garcia Samblas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: minitest-vcr
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: rubocop
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -198,7 +226,9 @@ files:
198
226
  - lib/redminerb/version.rb
199
227
  - redminerb.gemspec
200
228
  - templates/issue.erb
229
+ - templates/issue_boxie.erb
201
230
  - templates/user.erb
231
+ - templates/user_in_a_box.erb
202
232
  homepage: http://github.com/nando/redminerb
203
233
  licenses: []
204
234
  metadata: {}