aepic 0.0.2 → 0.0.4

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: e0b84ed455960e7c9b19f9406984a7dc49f14529
4
- data.tar.gz: 48ca4c4d21750b579bb7f1498fb6aa1a146bc432
3
+ metadata.gz: 971b3b0f35e7ea9e4d72c4d41dd4e12a3e3137c5
4
+ data.tar.gz: 8de792fc9d7a30eb486a2f55acaa095c0f4a0ed2
5
5
  SHA512:
6
- metadata.gz: b7bd2a420c029dbb10e07ef2becf4815c20abd010c2d3ca01edcf044f7ed9b14f2c824316ec21f2b8f3b115e8bcfd1b78fedb10b75717ba8df2cdd2d12d21974
7
- data.tar.gz: c6fdd4a3987f7772476e693f7def5eff5c081b66dfc5f6656e0b3c9677f0d343c3f4527ffd7959b603d67a9d4521cc76ec1833c39f3f19e4bba8f7fd14da3def
6
+ metadata.gz: 9c189a9c8b35d0aa93ff4c820e71b8ebf7c5c6a2d89888e0648cbbf69cba618c14292d85b595ab75e851009d78d818641ed7f93ebfecd4b8a0524e3aaba61d73
7
+ data.tar.gz: e8b28d75408909a18b944ffde972f3e9329c9b3fecfc9df78295ce0ab2124a381e18479b798b238a56c890d9df9cf1e227959d00eeb9b85629702adf0fe82b9e
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in aepic.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec', '~> 3.4.0'
8
+ gem 'simplecov', '~> 0.11.0'
9
+ end
data/README.md CHANGED
@@ -46,3 +46,7 @@ TODO: Write usage instructions here
46
46
  [WADL]: http://en.wikipedia.org/wiki/WADL
47
47
  [RSDL]: http://en.wikipedia.org/wiki/RSDL
48
48
  [Swagger]: https://developers.helloreverb.com/swagger/
49
+
50
+
51
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/alsemyonov/aepic/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
52
+
@@ -18,15 +18,16 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = %w(lib)
20
20
 
21
- spec.add_runtime_dependency 'actionpack', '>= 3.2'
22
- spec.add_runtime_dependency 'active_model_serializers'
23
- spec.add_runtime_dependency 'inherited_resources'
24
- spec.add_runtime_dependency 'has_scope'
25
- spec.add_runtime_dependency 'responders'
26
- spec.add_runtime_dependency 'draper'
27
- spec.add_runtime_dependency 'kaminari'
21
+ spec.add_runtime_dependency 'actionpack', '~> 4.2.5'
22
+ spec.add_runtime_dependency 'active_model_serializers', '~> 0.10.0.rc3'
23
+ spec.add_runtime_dependency 'inherited_resources', '~> 1.6.0'
24
+ spec.add_runtime_dependency 'has_scope', '~> 0.6.0'
25
+ spec.add_runtime_dependency 'responders', '~> 2.1.0'
26
+ spec.add_runtime_dependency 'draper', '~> 2.1.0'
27
+ spec.add_runtime_dependency 'kaminari', '~> 0.16.3'
28
28
 
29
29
  spec.add_development_dependency 'bundler', '~> 1.3'
30
30
  spec.add_development_dependency 'rake'
31
31
  spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'apipie-rails'
32
33
  end
@@ -0,0 +1,24 @@
1
+ h1= page_title(resource_class: resource_class.model_name.human)
2
+
3
+ h2 JSON-LD Context:
4
+ p
5
+ | Link:
6
+ code= link_to(collection_url(format: :jsonld))
7
+ pre
8
+ | JSON:
9
+ code= JSON.pretty_generate resource_serializer.jsonld
10
+
11
+ h2 Resources:
12
+ ul
13
+ - if controller.respond_to?(:index)
14
+ li: code GET # collection_path(format: :json)
15
+ - if controller.respond_to?(:create)
16
+ li: code POST # collection_path(format: :json)
17
+ - if controller.respond_to?(:show)
18
+ li: code GET # resource_path(':id', format: :json)
19
+ - if controller.respond_to?(:update)
20
+ li: code PUT # resource_path(':id', format: :json)
21
+ - if controller.respond_to?(:update)
22
+ li: code PATCH # resource_path(':id', format: :json)
23
+ - if controller.respond_to?(:destroy)
24
+ li: code DELETE # resource_path(':id', format: :json)
@@ -1,3 +1,11 @@
1
+ # Dependencies
2
+ require 'inherited_resources'
3
+ require 'responders'
4
+ require 'kaminari'
5
+ require 'has_scope'
6
+ require 'apipie-rails'
7
+
8
+ # AEpic
1
9
  require 'aepic/version'
2
10
  require 'active_support'
3
11
  require 'active_support/concern'
@@ -14,6 +22,7 @@ module Aepic
14
22
  module Concerns
15
23
  extend ActiveSupport::Autoload
16
24
 
25
+ autoload :ApiController
17
26
  autoload :Controller
18
27
  autoload :Decorator
19
28
  autoload :Responder
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+ require 'aepic'
3
+ require 'active_support/concern'
4
+ require 'apipie-rails'
5
+ require 'apipie/validator/integer_validator'
6
+
7
+ module Aepic
8
+ module Concerns
9
+ module ApiController
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ has_api!
14
+ end
15
+
16
+ module ClassMethods
17
+ def has_api!
18
+ human_name = resource_class.model_name.human
19
+ param_group_id = "#{resource_class.model_name.singular}_id".to_sym
20
+ param_group_resource = resource_class.model_name.singular.to_sym
21
+ param_group_id_resource = "#{resource_class.model_name.singular}_resource".to_sym
22
+
23
+ resource_description do
24
+ formats ['json']
25
+ error 404, 'Missing'
26
+ error 500, 'Server crashed for some reason'
27
+ end
28
+
29
+ if block_given?
30
+ yield
31
+ else
32
+ def_param_group(param_group_id) do
33
+ param :id, Integer, "ID of #{human_name}"
34
+ end
35
+ columns = resource_class.columns_hash
36
+ def_param_group(param_group_resource) do
37
+ param param_group_resource, Hash, action_aware: true do
38
+ columns.each do |name, column|
39
+ param name.to_sym, column.sql_type.classify.safe_constantize || String, required: !column.null unless name == 'id'
40
+ # STDERR.puts "params :#{name}, #{column.sql_type.classify.safe_constantize || String}"
41
+ end
42
+ end
43
+ end
44
+ def_param_group(param_group_id_resource) do
45
+ param_group(param_group_id)
46
+ param_group(param_group_resource)
47
+ end
48
+ end
49
+
50
+ class_eval do
51
+ api! "List #{human_name.pluralize}"
52
+ formats %w(json jsonld)
53
+
54
+ def index
55
+ super
56
+ end
57
+
58
+ api! "Show #{human_name}"
59
+ param_group(param_group_id)
60
+
61
+ def show
62
+ super
63
+ end
64
+
65
+ api! "Create #{human_name}"
66
+ param_group(param_group_resource)
67
+
68
+ def create
69
+ super
70
+ end
71
+
72
+ api! "Update #{human_name}"
73
+ param_group(param_group_id_resource)
74
+
75
+ def update
76
+ super
77
+ end
78
+
79
+ api! "Delete #{human_name}"
80
+ param_group(param_group_id)
81
+
82
+ def destroy
83
+ super
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -30,6 +30,8 @@ module Aepic
30
30
  include Overrides
31
31
 
32
32
  api_schema << self
33
+
34
+ include ApiController
33
35
  end
34
36
 
35
37
  module ClassMethods
@@ -11,7 +11,7 @@ module Aepic
11
11
  private
12
12
 
13
13
  def do_http_cache?
14
- get? && (@http_cache != false) && persisted? && resourceful? && resource_item.respond_to?(:updated_at)
14
+ get? && (@http_cache != false) && persisted? && resource_item.respond_to?(:updated_at)
15
15
  end
16
16
 
17
17
  # @return [Boolean]
@@ -1,3 +1,3 @@
1
1
  module Aepic
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,25 @@
1
+ module Apipie
2
+ module Validator
3
+ class IntegerValidator < Apipie::Validator::BaseValidator
4
+ def initialize(param_description, argument)
5
+ super(param_description)
6
+ @type = argument
7
+ end
8
+
9
+ def validate(value)
10
+ return false if value.nil?
11
+ !!(value.to_s =~ /^[-+]?[0-9]+$/)
12
+ end
13
+
14
+ def self.build(param_description, argument, options, block)
15
+ if argument == Integer || argument == Fixnum
16
+ self.new(param_description, argument)
17
+ end
18
+ end
19
+
20
+ def description
21
+ "Must be #{@type}."
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,8 +4,4 @@ describe Aepic do
4
4
  it 'should have a version number' do
5
5
  Aepic::VERSION.should_not be_nil
6
6
  end
7
-
8
- it 'should do something useful' do
9
- false.should be_true
10
- end
11
7
  end
@@ -1,2 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'aepic'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
6
+ end
metadata CHANGED
@@ -1,153 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aepic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Semyonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-18 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: 4.2.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: 4.2.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: active_model_serializers
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.10.0.rc3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.10.0.rc3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: inherited_resources
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.6.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.6.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: has_scope
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.6.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: responders
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.1.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: draper
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 2.1.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 2.1.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: kaminari
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 0.16.3
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 0.16.3
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '1.3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
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: apipie-rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
144
158
  - !ruby/object:Gem::Version
145
159
  version: '0'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - '>='
164
+ - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
167
  description: Build your epic APIs same time you are building your website. Docs included
@@ -157,19 +171,20 @@ executables: []
157
171
  extensions: []
158
172
  extra_rdoc_files: []
159
173
  files:
160
- - .gitignore
161
- - .rspec
162
- - .ruby-version
163
- - .travis.yml
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".travis.yml"
164
177
  - Gemfile
165
178
  - LICENSE.txt
166
179
  - README.md
167
180
  - Rakefile
168
181
  - aepic.gemspec
169
182
  - app/views/application/api.html.haml
183
+ - app/views/application/api.html.slim
170
184
  - app/views/application/api.xml.builder
171
185
  - app/views/application/index.jsonld.erb
172
186
  - lib/aepic.rb
187
+ - lib/aepic/concerns/api_controller.rb
173
188
  - lib/aepic/concerns/controller.rb
174
189
  - lib/aepic/concerns/decorator.rb
175
190
  - lib/aepic/concerns/responder.rb
@@ -180,6 +195,7 @@ files:
180
195
  - lib/aepic/schema.rb
181
196
  - lib/aepic/serializer.rb
182
197
  - lib/aepic/version.rb
198
+ - lib/apipie/validator/integer_validator.rb
183
199
  - spec/aepic_spec.rb
184
200
  - spec/spec_helper.rb
185
201
  homepage: http://github.com/alsemyonov/aepic
@@ -192,20 +208,20 @@ require_paths:
192
208
  - lib
193
209
  required_ruby_version: !ruby/object:Gem::Requirement
194
210
  requirements:
195
- - - '>='
211
+ - - ">="
196
212
  - !ruby/object:Gem::Version
197
213
  version: '0'
198
214
  required_rubygems_version: !ruby/object:Gem::Requirement
199
215
  requirements:
200
- - - '>='
216
+ - - ">="
201
217
  - !ruby/object:Gem::Version
202
218
  version: '0'
203
219
  requirements: []
204
220
  rubyforge_project:
205
- rubygems_version: 2.0.7
221
+ rubygems_version: 2.5.0
206
222
  signing_key:
207
223
  specification_version: 4
208
- summary: Æpic is for your epic APIs
224
+ summary: "Æpic is for your epic APIs"
209
225
  test_files:
210
226
  - spec/aepic_spec.rb
211
227
  - spec/spec_helper.rb
@@ -1 +0,0 @@
1
- 2.0.0-p247