apipie-rails 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -2,10 +2,16 @@
2
2
  Changelog
3
3
  ===========
4
4
 
5
+ v0.0.17
6
+ -------
7
+
8
+ * support for multiple see links at action and ability to provide
9
+ description of see links
10
+
5
11
  v0.0.16
6
12
  -------
7
13
 
8
- * Fix getting started being rendered even when documentation was available.
14
+ * Fix getting started being rendered even when documentation was available
9
15
 
10
16
  v0.0.15
11
17
  -------
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apipie-rails (0.0.13)
4
+ apipie-rails (0.0.16)
5
+ rails (>= 3.0.10)
5
6
 
6
7
  GEM
7
8
  remote: http://rubygems.org/
@@ -51,7 +52,6 @@ GEM
51
52
  mime-types (1.19)
52
53
  minitest (3.2.0)
53
54
  multi_json (1.3.6)
54
- oauth (0.4.6)
55
55
  polyglot (0.3.3)
56
56
  rack (1.4.1)
57
57
  rack-cache (1.2)
@@ -78,8 +78,6 @@ GEM
78
78
  rake (0.9.2.2)
79
79
  rdoc (3.12)
80
80
  json (~> 1.4)
81
- rest-client (1.6.7)
82
- mime-types (>= 1.16)
83
81
  rspec (2.11.0)
84
82
  rspec-core (~> 2.11.0)
85
83
  rspec-expectations (~> 2.11.0)
@@ -101,10 +99,10 @@ GEM
101
99
  syntax (1.0.0)
102
100
  thor (0.15.4)
103
101
  tilt (1.3.3)
104
- treetop (1.4.10)
102
+ treetop (1.4.12)
105
103
  polyglot
106
104
  polyglot (>= 0.3.1)
107
- tzinfo (0.3.33)
105
+ tzinfo (0.3.35)
108
106
 
109
107
  PLATFORMS
110
108
  ruby
@@ -114,9 +112,6 @@ DEPENDENCIES
114
112
  apipie-rails!
115
113
  maruku
116
114
  minitest
117
- oauth
118
- rails (>= 3.0.10)
119
115
  rake
120
- rest-client
121
116
  rspec-rails
122
117
  sqlite3
data/README.rst CHANGED
@@ -224,7 +224,8 @@ Example:
224
224
  description "method description"
225
225
  formats ['json', 'jsonp', 'xml']
226
226
  example " 'user': {...} "
227
- see "users#showme"
227
+ see "users#showme", "link description"
228
+ see :link => "users#update", :desc => "another link description"
228
229
  def show
229
230
  #...
230
231
  end
@@ -23,8 +23,8 @@
23
23
  <% end %>
24
24
 
25
25
  <div>
26
- <% unless @method[:see_url].blank? %>
27
- Also see <%= link_to @method[:see], @method[:see_url] %>.
26
+ <% unless @method[:see].empty? %>
27
+ Also see <%= @method[:see].map { |s| link_to(s[:description], "#{s[:link]}.html") }.to_sentence.html_safe %>.
28
28
  <% end %>
29
29
 
30
30
  <%= raw @method[:full_description] %>
@@ -47,8 +47,8 @@
47
47
  <% end %>
48
48
  </div>
49
49
 
50
- <% unless m[:see_url].blank? %>
51
- Also see <%= link_to m[:see], m[:see_url] %>
50
+ <% unless m[:see].empty? %>
51
+ Also see <%= m[:see].map { |s| link_to(s[:description], "#{s[:link]}.html") }.to_sentence.html_safe %>.
52
52
  <% end %>
53
53
 
54
54
  <div id='description-<%= m[:name] %>' class='collapse accordion-body'>
@@ -7,6 +7,7 @@ require "apipie/resource_description"
7
7
  require "apipie/param_description"
8
8
  require "apipie/errors"
9
9
  require "apipie/error_description"
10
+ require "apipie/see_description"
10
11
  require "apipie/validator"
11
12
  require "apipie/dsl_definition"
12
13
  require "apipie/railtie"
@@ -212,7 +212,7 @@ module Apipie
212
212
  :short_description => nil,
213
213
  :description => nil,
214
214
  :examples => [],
215
- :see => nil,
215
+ :see => [],
216
216
  :formats => nil,
217
217
  :api_versions => []
218
218
  }
@@ -125,10 +125,9 @@ module Apipie
125
125
  # api :PUT, '/articles/:id'
126
126
  # see "articles#create"
127
127
  # def update; end
128
- def see(method_key)
128
+ def see(*args)
129
129
  return unless Apipie.active_dsl?
130
- raise "'See' method called twice." if Apipie.last_dsl_data[:see]
131
- Apipie.last_dsl_data[:see] = method_key
130
+ Apipie.last_dsl_data[:see] << Apipie::SeeDescription.new(args)
132
131
  end
133
132
 
134
133
  # Show some example of what does the described
@@ -105,16 +105,6 @@ module Apipie
105
105
  end
106
106
  end
107
107
 
108
- def see_url
109
- if @see
110
- method_description = Apipie[@see]
111
- if method_description.nil?
112
- raise ArgumentError.new("Method #{@see} referenced in 'see' does not exist.")
113
- end
114
- method_description.doc_url
115
- end
116
- end
117
-
118
108
  def see
119
109
  @see
120
110
  end
@@ -133,8 +123,7 @@ module Apipie
133
123
  :errors => errors.map(&:to_json),
134
124
  :params => params_ordered.map(&:to_json).flatten,
135
125
  :examples => @examples,
136
- :see => @see,
137
- :see_url => see_url
126
+ :see => see.map(&:to_json)
138
127
  }
139
128
  end
140
129
 
@@ -0,0 +1,39 @@
1
+ module Apipie
2
+
3
+ class SeeDescription
4
+
5
+ attr_reader :link, :description
6
+
7
+ def initialize(args)
8
+ if args.first.is_a? Hash
9
+ args = args.first
10
+ elsif args.count == 2
11
+ if args.last.is_a? Hash
12
+ args = {:link => args.first}.merge(args.last)
13
+ else
14
+ args = {:link => args.first, :description => args.second}
15
+ end
16
+ elsif args.count == 1 && args.first.is_a?(String)
17
+ args = {:link => args.first, :description => args.first}
18
+ else
19
+ raise ArgumentError "ApipieError: Bad use of see method."
20
+ end
21
+ @link = args[:link] || args['link']
22
+ @description = args[:desc] || args[:description] || args['desc'] || args['description']
23
+ end
24
+
25
+ def to_json
26
+ {:link => see_url, :description => description}
27
+ end
28
+
29
+ def see_url
30
+ method_description = Apipie[@link]
31
+ if method_description.nil?
32
+ raise ArgumentError.new("Method #{@link} referenced in 'see' does not exist.")
33
+ end
34
+ method_description.doc_url
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
  end
@@ -234,20 +234,28 @@ describe UsersController do
234
234
  context "the key is valid" do
235
235
  it "should contain reference to another method" do
236
236
  api = Apipie[UsersController, :see_another]
237
- api.see.should eq('development#users#create')
237
+ see = api.see.first
238
+ see.see_url.should == Apipie[UsersController, :create].doc_url
239
+ see.link.should == 'development#users#create'
240
+ see.description.should == 'development#users#create'
241
+
242
+ see_with_desc = api.see.last
243
+ see_with_desc.see_url.should == Apipie[UsersController, :index].doc_url
244
+ see_with_desc.link.should == 'development#users#index'
245
+ see_with_desc.description.should == 'very interesting method reference'
246
+
238
247
  Apipie['development#users#see_another'].should eq(Apipie[UsersController, :see_another])
239
- api.see_url.should eq(Apipie[UsersController, :create].doc_url)
240
248
  end
241
249
  end
242
250
 
243
251
  context "the key is not valid" do
244
252
  it "should raise exception" do
245
253
  api = Apipie[UsersController, :see_another]
246
- api.instance_variable_set :@see, 'doesnot#exist'
254
+ api.instance_variable_set :@see, [Apipie::SeeDescription.new(['doesnot#exist'])]
247
255
  lambda {
248
- api.see_url
256
+ api.see.first.see_url
249
257
  }.should raise_error(ArgumentError, /does not exist/)
250
- api.instance_variable_set :@see, nil
258
+ api.instance_variable_set :@see, []
251
259
  end
252
260
  end
253
261
  end
@@ -220,6 +220,7 @@ class UsersController < ApplicationController
220
220
 
221
221
  api :GET, '/users/see_another', 'Boring method'
222
222
  see 'development#users#create'
223
+ see 'development#users#index', "very interesting method reference"
223
224
  desc 'This method is boring, look at users#create'
224
225
  def see_another
225
226
  render :text => 'This is very similar to create action'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipie-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-06 00:00:00.000000000Z
13
+ date: 2013-02-13 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &22093740 !ruby/object:Gem::Requirement
17
+ requirement: &21190160 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.10
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *22093740
25
+ version_requirements: *21190160
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec-rails
28
- requirement: &22093320 !ruby/object:Gem::Requirement
28
+ requirement: &21189740 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *22093320
36
+ version_requirements: *21189740
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3
39
- requirement: &22092860 !ruby/object:Gem::Requirement
39
+ requirement: &21189280 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *22092860
47
+ version_requirements: *21189280
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: minitest
50
- requirement: &22092440 !ruby/object:Gem::Requirement
50
+ requirement: &21188860 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *22092440
58
+ version_requirements: *21188860
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: maruku
61
- requirement: &22118600 !ruby/object:Gem::Requirement
61
+ requirement: &21215040 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *22118600
69
+ version_requirements: *21215040
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: RedCloth
72
- requirement: &22118180 !ruby/object:Gem::Requirement
72
+ requirement: &21214620 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *22118180
80
+ version_requirements: *21214620
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rake
83
- requirement: &22117760 !ruby/object:Gem::Requirement
83
+ requirement: &21214200 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,7 +88,7 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *22117760
91
+ version_requirements: *21214200
92
92
  description: Maintain your API documentation up to date!
93
93
  email:
94
94
  - pajkycz@gmail.com
@@ -150,6 +150,7 @@ files:
150
150
  - lib/apipie/railtie.rb
151
151
  - lib/apipie/resource_description.rb
152
152
  - lib/apipie/routing.rb
153
+ - lib/apipie/see_description.rb
153
154
  - lib/apipie/static_dispatcher.rb
154
155
  - lib/apipie/validator.rb
155
156
  - lib/apipie/version.rb