bc-middleware 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +67 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bc-middleware.gemspec +21 -0
- data/lib/bc-middleware/base.rb +3 -0
- data/lib/bc-middleware/search_api.rb +54 -0
- data/lib/bc-middleware/version.rb +5 -0
- data/lib/bc-middleware.rb +12 -0
- metadata +91 -0
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bc-middleware (0.0.1)
|
5
|
+
inherited_resources (~> 1.3.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (3.2.8)
|
11
|
+
activemodel (= 3.2.8)
|
12
|
+
activesupport (= 3.2.8)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
erubis (~> 2.7.0)
|
15
|
+
journey (~> 1.0.4)
|
16
|
+
rack (~> 1.4.0)
|
17
|
+
rack-cache (~> 1.2)
|
18
|
+
rack-test (~> 0.6.1)
|
19
|
+
sprockets (~> 2.1.3)
|
20
|
+
activemodel (3.2.8)
|
21
|
+
activesupport (= 3.2.8)
|
22
|
+
builder (~> 3.0.0)
|
23
|
+
activesupport (3.2.8)
|
24
|
+
i18n (~> 0.6)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
builder (3.0.3)
|
27
|
+
erubis (2.7.0)
|
28
|
+
has_scope (0.5.1)
|
29
|
+
hike (1.2.1)
|
30
|
+
i18n (0.6.1)
|
31
|
+
inherited_resources (1.3.1)
|
32
|
+
has_scope (~> 0.5.0)
|
33
|
+
responders (~> 0.6)
|
34
|
+
journey (1.0.4)
|
35
|
+
json (1.7.5)
|
36
|
+
multi_json (1.3.6)
|
37
|
+
rack (1.4.1)
|
38
|
+
rack-cache (1.2)
|
39
|
+
rack (>= 0.4)
|
40
|
+
rack-ssl (1.3.2)
|
41
|
+
rack
|
42
|
+
rack-test (0.6.2)
|
43
|
+
rack (>= 1.0)
|
44
|
+
railties (3.2.8)
|
45
|
+
actionpack (= 3.2.8)
|
46
|
+
activesupport (= 3.2.8)
|
47
|
+
rack-ssl (~> 1.3.2)
|
48
|
+
rake (>= 0.8.7)
|
49
|
+
rdoc (~> 3.4)
|
50
|
+
thor (>= 0.14.6, < 2.0)
|
51
|
+
rake (0.9.2.2)
|
52
|
+
rdoc (3.12)
|
53
|
+
json (~> 1.4)
|
54
|
+
responders (0.9.3)
|
55
|
+
railties (~> 3.1)
|
56
|
+
sprockets (2.1.3)
|
57
|
+
hike (~> 1.2)
|
58
|
+
rack (~> 1.0)
|
59
|
+
tilt (~> 1.1, != 1.3.0)
|
60
|
+
thor (0.16.0)
|
61
|
+
tilt (1.3.3)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
bc-middleware!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Vasco
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Bc::Middleware
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bc-middleware'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bc-middleware
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bc-middleware/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Byclosure"]
|
6
|
+
gem.email = ["info@byclosure.com"]
|
7
|
+
gem.description = %q{Library to get a middleware implementation (REST api), with support a search, etc. fast}
|
8
|
+
gem.summary = %q{Library to get a middleware implementation (REST api), with support a search, etc. fast}
|
9
|
+
gem.homepage = "http://github.com/Byclosure/bc-middleware"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "bc-middleware"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Bc::Middleware::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency("inherited_resources", "~> 1.3.1")
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "bc-middleware/base"
|
2
|
+
|
3
|
+
module BcMiddleware
|
4
|
+
module SearchApi
|
5
|
+
def collection
|
6
|
+
get_collection_ivar || begin
|
7
|
+
c = end_of_association_chain
|
8
|
+
if respond_to?(:search_terms) && (terms = search_terms).present?
|
9
|
+
c = c.search(terms)
|
10
|
+
end
|
11
|
+
set_collection_ivar(c.respond_to?(:scoped) ? c.scoped : c.all)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def search_terms
|
16
|
+
params[:search]
|
17
|
+
end
|
18
|
+
|
19
|
+
def attribute_fields
|
20
|
+
params[:fields].present? ? params[:fields] : resource_class_attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
def relationship_fields
|
24
|
+
@relationship_fields ||= begin
|
25
|
+
include_params = params[:include].present? ? params[:include] : {}
|
26
|
+
raise(ArgumentError.new("wrong format for include parameter")) unless include_params.is_a?(Hash)
|
27
|
+
|
28
|
+
result = {}
|
29
|
+
include_params.each do |(relationship_name, relationship_value)|
|
30
|
+
# TODO verificar as relacoes
|
31
|
+
if relationship_value.present?
|
32
|
+
result[relationship_name] = relationship_value
|
33
|
+
else
|
34
|
+
relationship = resource_class.reflect_on_all_associations.detect {|r| r.name == relationship_name.to_sym}
|
35
|
+
if relationship.nil?
|
36
|
+
raise(InvalidRelationship.new("Relationship with name #{relationship_name} not found for #{resource_class}"))
|
37
|
+
end
|
38
|
+
result[relationship_name] = extract_attributes(relationship.klass)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def resource_class_attributes
|
47
|
+
@resource_class_attributes ||= extract_attributes(resource_class)
|
48
|
+
end
|
49
|
+
|
50
|
+
def extract_attributes(klass)
|
51
|
+
klass.accessible_attributes.select(&:present?) + [klass.primary_key]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bc-middleware
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Byclosure
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-10-09 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 25
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 3
|
30
|
+
- 1
|
31
|
+
version: 1.3.1
|
32
|
+
prerelease: false
|
33
|
+
type: :runtime
|
34
|
+
name: inherited_resources
|
35
|
+
requirement: *id001
|
36
|
+
description: Library to get a middleware implementation (REST api), with support a search, etc. fast
|
37
|
+
email:
|
38
|
+
- info@byclosure.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .rspec
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- bc-middleware.gemspec
|
53
|
+
- lib/bc-middleware.rb
|
54
|
+
- lib/bc-middleware/base.rb
|
55
|
+
- lib/bc-middleware/search_api.rb
|
56
|
+
- lib/bc-middleware/version.rb
|
57
|
+
homepage: http://github.com/Byclosure/bc-middleware
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Library to get a middleware implementation (REST api), with support a search, etc. fast
|
90
|
+
test_files: []
|
91
|
+
|