jabysoft-rails_patterns 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/app/controllers/jabysoft/base_controller.rb +118 -0
- data/app/helpers/base_helper.rb +51 -0
- data/app/helpers/links_helper.rb +80 -0
- data/app/helpers/render_helper.rb +17 -0
- data/app/models/concerns/jabysoft/extension_model_behaviour.rb +17 -0
- data/app/models/concerns/jabysoft/searchable_behaviour.rb +48 -0
- data/app/services/jabysoft/authorisation_service.rb +16 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jabysoft-rails_patterns.gemspec +39 -0
- data/lib/jabysoft/rails_patterns/configuration.rb +14 -0
- data/lib/jabysoft/rails_patterns/version.rb +5 -0
- data/lib/jabysoft/rails_patterns.rb +23 -0
- metadata +177 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: b2470e2107d58b28d1b100f6e9083751da1c6637
|
|
4
|
+
data.tar.gz: 2cfadf39d16f53d6baffaf1bc724b8731bb57506
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e29b57f82a36a538c79260c58a631a4852c8817384010778126fe4b795e6a420e245d13c9d00519b31beda9a334aeea6eaf57c31bf827f99a8a8518b0f5c2752
|
|
7
|
+
data.tar.gz: e18985a06944262a02ddd2e9858caf318df470182dcd57db51058b51f2ed8af93e8a2ade001f2d1c013b82fc063c30418e7d22f3adabcbbf274759c4e059d4e2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at msxavii@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Emerson Xavier
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Jabysoft::RailsPatterns
|
|
2
|
+
|
|
3
|
+
[ ](https://app.codeship.com/projects/189588)
|
|
4
|
+
[](https://www.codacy.com/app/CQ-JABYSOFT/jabysoft-rails_patterns?utm_source=github.com&utm_medium=referral&utm_content=jabysoft/jabysoft-rails_patterns&utm_campaign=Badge_Grade)
|
|
5
|
+
[](https://www.codacy.com/app/CQ-JABYSOFT/jabysoft-rails_patterns?utm_source=github.com&utm_medium=referral&utm_content=jabysoft/jabysoft-rails_patterns&utm_campaign=Badge_Coverage)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'jabysoft-rails_patterns'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install jabysoft-rails_patterns
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jabysoft-rails_patterns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
41
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
module Jabysoft
|
|
2
|
+
class BaseController < ApplicationController
|
|
3
|
+
# This class works as a Restfull CRUD Controller to provide the same crud functions to all subcontrollers
|
|
4
|
+
protect_from_forgery with: :exception
|
|
5
|
+
respond_to :json, :html, :xml
|
|
6
|
+
|
|
7
|
+
# Callbacks here
|
|
8
|
+
before_action :set_resource, only: [:show, :edit, :update, :destroy]
|
|
9
|
+
before_action :disable_edition, only: [:show]
|
|
10
|
+
before_action :load_form_resources, except: [:index, :destroy]
|
|
11
|
+
|
|
12
|
+
PER_PAGE = 8
|
|
13
|
+
|
|
14
|
+
def index
|
|
15
|
+
if included_attributes
|
|
16
|
+
instance_variable_set(collection_instance_variable, model_class.includes(included_attributes).paginate(page: params[:page], per_page: PER_PAGE))
|
|
17
|
+
else
|
|
18
|
+
instance_variable_set(collection_instance_variable, model_class.paginate(page: params[:page], per_page: PER_PAGE))
|
|
19
|
+
end
|
|
20
|
+
search
|
|
21
|
+
respond_with collection_variable
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def show; end
|
|
25
|
+
def edit; end
|
|
26
|
+
|
|
27
|
+
def new
|
|
28
|
+
instance_variable_set(instance_variable, model_class.new)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create
|
|
32
|
+
instance_variable_set(instance_variable, model_class.new(permit_params))
|
|
33
|
+
flash[:success] = I18n.t('created', model: model_class.model_name.human) if variable.save
|
|
34
|
+
responds
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def update
|
|
38
|
+
flash[:success] = I18n.t('updated', model: model_class.model_name.human) if variable.update(permit_params)
|
|
39
|
+
responds
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def destroy
|
|
43
|
+
flash[:success] = I18n.t('destroyed', model: model_class.model_name.human) if variable.destroy
|
|
44
|
+
redirect_to index_path
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
protected
|
|
48
|
+
# to be used by subclasses
|
|
49
|
+
def included_attributes
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# to be used by subclasses
|
|
54
|
+
def load_form_resources
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def model_class
|
|
58
|
+
get_model_name.singularize.constantize
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def index_path
|
|
62
|
+
Rails.application.routes.url_helpers.send("#{get_model_name.underscore}_path")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def get_model_name
|
|
66
|
+
model_name = self.class.name
|
|
67
|
+
model_name.slice! 'Controller'
|
|
68
|
+
model_name
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def disable_edition
|
|
72
|
+
@readonly = true
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def template_not_found
|
|
76
|
+
redirect_to '/404.html'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
def search
|
|
81
|
+
return unless params[:search].present?
|
|
82
|
+
result = collection_variable.search(params[:search])
|
|
83
|
+
instance_variable_set(collection_instance_variable, result)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def variable
|
|
87
|
+
instance_variable_get(instance_variable)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def collection_variable
|
|
91
|
+
instance_variable_get(collection_instance_variable)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def controller_namespace
|
|
95
|
+
params[:controller].split('/').first if params[:controller].include?('/')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def instance_variable
|
|
99
|
+
"@#{model_class.name.underscore}"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def collection_instance_variable
|
|
103
|
+
"@#{model_class.name.underscore.pluralize}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def set_resource
|
|
107
|
+
instance_variable_set(instance_variable, model_class.find(params[:id]))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def responds
|
|
111
|
+
if controller_namespace
|
|
112
|
+
respond_with controller_namespace.to_sym, variable
|
|
113
|
+
else
|
|
114
|
+
respond_with variable
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module BaseHelper
|
|
2
|
+
def translate_attribute(model, attribute = nil)
|
|
3
|
+
return model.human_attribute_name(attribute) if attribute
|
|
4
|
+
model.model_name.human
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
alias ta translate_attribute
|
|
8
|
+
|
|
9
|
+
def edit_url_for(model, namespace: nil)
|
|
10
|
+
if model.id
|
|
11
|
+
_namespace_ = namespace ? namespace.concat('_') : namespace
|
|
12
|
+
path = "edit_#{_namespace_}#{model.model_name.to_s.underscore}_path"
|
|
13
|
+
Rails.application.routes.url_helpers.send(path.to_sym, id: model.id)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def remote_request(type, path, params={}, target_tag_id = nil)
|
|
18
|
+
if target_tag_id
|
|
19
|
+
"$.#{type}('#{path}',
|
|
20
|
+
{ #{collect_request_params(params)} },
|
|
21
|
+
function(data) {$('##{target_tag_id}').html(data);}
|
|
22
|
+
);"
|
|
23
|
+
else
|
|
24
|
+
"$.#{type}('#{path}',
|
|
25
|
+
{ #{collect_request_params(params)} }
|
|
26
|
+
);"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def boolean_image(boolean)
|
|
31
|
+
if boolean
|
|
32
|
+
"<span class='glyphicon glyphicon-ok green'>".html_safe
|
|
33
|
+
else
|
|
34
|
+
"<span class='glyphicon glyphicon-remove red'>".html_safe
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def short_date(date)
|
|
39
|
+
return "" unless date
|
|
40
|
+
l(date, format: :short)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def price(value)
|
|
44
|
+
number_to_currency(value)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
def collect_request_params(params)
|
|
49
|
+
params.collect { |param| "#{param[0]}: #{param[1]}" }.join(", ")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module LinksHelper
|
|
2
|
+
include Jabysoft::AuthorisationService
|
|
3
|
+
|
|
4
|
+
def link_to_new(model, url, html_options = {})
|
|
5
|
+
authorise_link(:create, model: model, style: 'btn btn-primary btn-lg', options: html_options) do |authorised|
|
|
6
|
+
if authorised
|
|
7
|
+
link_to t('new', model: model.model_name.human), url, html_options
|
|
8
|
+
else
|
|
9
|
+
content_tag(:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
|
|
10
|
+
link_to t('new', model: model.model_name.human), url, html_options
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def link_to_edit(model, url, html_options = {})
|
|
17
|
+
authorise_link(:update, model: model,
|
|
18
|
+
style: 'btn btn-default glyphicon glyphicon-pencil', options: html_options) do |authorised|
|
|
19
|
+
if authorised
|
|
20
|
+
link_to '', url, html_options
|
|
21
|
+
else
|
|
22
|
+
content_tag(:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
|
|
23
|
+
link_to t('edit'), url, html_options
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def link_to_show(model, url, html_options = {})
|
|
30
|
+
style = 'btn btn-default glyphicon glyphicon-zoom-in'
|
|
31
|
+
authorise_link(:show, model: model, style: style, options: html_options) do |authorised|
|
|
32
|
+
if authorised
|
|
33
|
+
link_to '', url, html_options
|
|
34
|
+
else
|
|
35
|
+
content_tag(:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
|
|
36
|
+
link_to t('show'), url, html_options
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def link_to_destroy(model, url, html_options = {})
|
|
43
|
+
style = 'btn btn-danger glyphicon glyphicon-trash'
|
|
44
|
+
html_options.reverse_merge!({"data-target" => "#delete-confirmation", "data-toggle" => "modal"})
|
|
45
|
+
authorise_link(:destroy, model: model, style: style, options: html_options) do |authorised|
|
|
46
|
+
if authorised
|
|
47
|
+
link_to '', url, html_options
|
|
48
|
+
else
|
|
49
|
+
content_tag(:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
|
|
50
|
+
link_to t('destroy'), url, html_options
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def link_to_back(url, html_options = {})
|
|
57
|
+
html_options.reverse_merge!(class: 'btn btn-default btn-lg')
|
|
58
|
+
link_to t('back'), url, html_options
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def link_to_menu(model, url)
|
|
62
|
+
link_to model.model_name.human.pluralize, url
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def submit_or_edit_button(form, edit_path, is_edition)
|
|
66
|
+
if is_edition && params[:action] != 'new'
|
|
67
|
+
link_to_edit form.object, edit_path, class: "btn btn-primary glyphicon glyphicon-pencil"
|
|
68
|
+
else
|
|
69
|
+
submit_button(form)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def submit_button(form, value = nil)
|
|
74
|
+
if value
|
|
75
|
+
form.submit value, class: "btn btn-primary btn-lg"
|
|
76
|
+
else
|
|
77
|
+
form.submit t('save'), class: "btn btn-primary btn-lg"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module RenderHelper
|
|
2
|
+
def render_flash_messages
|
|
3
|
+
render 'shared/messages'
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def render_errors_from(resource)
|
|
7
|
+
render partial: 'shared/form/error_messages', locals: { resource: resource }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def datepicker_field_for(form, field)
|
|
11
|
+
render 'shared/datepicker_field', f: form, field: field
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def search_form(url)
|
|
15
|
+
render 'shared/search_form', url: url
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Jabysoft
|
|
2
|
+
module ExtensionModelBehaviour
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
# It gives model additional scope active and scoped.
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
scope :active, -> { where(active: true) }
|
|
8
|
+
scope :scoped, -> { select(:id, scoped_attribute) }
|
|
9
|
+
|
|
10
|
+
def self.scoped_attribute
|
|
11
|
+
return :title if column_names.include? 'title'
|
|
12
|
+
return :code if column_names.include? 'code'
|
|
13
|
+
:name
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Jabysoft
|
|
2
|
+
module SearchableBehaviour
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
# It gives models search behaviour
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
def self.search(params)
|
|
8
|
+
if has_joins?
|
|
9
|
+
joins(get_joins).where(query, p: "%#{params}%")
|
|
10
|
+
else
|
|
11
|
+
where(query, p: "%#{params}%")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.look_for(*attrs)
|
|
16
|
+
@attrs_to_search = attrs
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.query
|
|
20
|
+
return unless @attrs_to_search.any?
|
|
21
|
+
each_attr = @attrs_to_search.map { |a| handle_attribute(a) + " LIKE :p "}
|
|
22
|
+
each_attr.join("OR ")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.has_joins?
|
|
26
|
+
select_hash_attributes.any?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.select_hash_attributes
|
|
30
|
+
@attrs_to_search.select { |attribute| attribute.is_a? Hash }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.get_joins
|
|
34
|
+
keys = []
|
|
35
|
+
select_hash_attributes.each do |hash_attribute|
|
|
36
|
+
keys |= hash_attribute.keys
|
|
37
|
+
end
|
|
38
|
+
keys
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.handle_attribute(attribute)
|
|
42
|
+
return "#{self.name.downcase.pluralize}.#{attribute}" unless attribute.is_a? Hash
|
|
43
|
+
attribute.map {|k, v| "#{k.to_s.pluralize}.#{v}" }.first
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Jabysoft
|
|
2
|
+
module AuthorisationService
|
|
3
|
+
def authorise_link(action, model:, style:, options:)
|
|
4
|
+
options.reverse_merge!(class: style)
|
|
5
|
+
authorised = link_authorised?(action, model) if model.present?
|
|
6
|
+
options.merge!(class: style + " disabled ") unless authorised
|
|
7
|
+
return yield authorised
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
def link_authorised?(action, model)
|
|
12
|
+
return true if Jabysoft.configuration.authorisation_skipped?
|
|
13
|
+
can? action, model
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "jabysoft/rails_patterns"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'jabysoft/rails_patterns/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "jabysoft-rails_patterns"
|
|
8
|
+
spec.version = Jabysoft::RailsPatterns::VERSION
|
|
9
|
+
spec.authors = ["Emerson Xavier"]
|
|
10
|
+
spec.email = ["msxavii@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{RailsPatterns set of patterns}
|
|
13
|
+
spec.description = %q{RailsPatterns contains a bunch of useful classes for a great Rails project}
|
|
14
|
+
spec.homepage = "https://github.com/jabysoft/jabysoft-rails_patterns"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org/"
|
|
21
|
+
else
|
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
23
|
+
"public gem pushes."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
27
|
+
spec.bindir = "exe"
|
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ["lib"]
|
|
30
|
+
|
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
34
|
+
spec.add_development_dependency 'rails', '~> 5.0'
|
|
35
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.5'
|
|
36
|
+
spec.add_development_dependency 'simplecov', '~> 0.12.0'
|
|
37
|
+
spec.add_runtime_dependency 'codacy-coverage', '~> 1.1'
|
|
38
|
+
spec.add_dependency 'devise', '~> 4.2'
|
|
39
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "jabysoft/rails_patterns/version"
|
|
2
|
+
require "jabysoft/rails_patterns/configuration"
|
|
3
|
+
require 'rails/engine'
|
|
4
|
+
require 'devise'
|
|
5
|
+
|
|
6
|
+
module Jabysoft
|
|
7
|
+
class << self
|
|
8
|
+
attr_writer :configuration
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.configuration
|
|
12
|
+
@configuration ||= Jabysoft::RailsPatterns::Configuration.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.configure
|
|
16
|
+
yield configuration if block_given?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module RailsPatterns
|
|
20
|
+
class Engine < ::Rails::Engine
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jabysoft-rails_patterns
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Emerson Xavier
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rails
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '5.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '5.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec-rails
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.5'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.5'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: simplecov
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 0.12.0
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 0.12.0
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: codacy-coverage
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '1.1'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '1.1'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: devise
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '4.2'
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '4.2'
|
|
125
|
+
description: RailsPatterns contains a bunch of useful classes for a great Rails project
|
|
126
|
+
email:
|
|
127
|
+
- msxavii@gmail.com
|
|
128
|
+
executables: []
|
|
129
|
+
extensions: []
|
|
130
|
+
extra_rdoc_files: []
|
|
131
|
+
files:
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".rspec"
|
|
134
|
+
- CODE_OF_CONDUCT.md
|
|
135
|
+
- Gemfile
|
|
136
|
+
- LICENSE.txt
|
|
137
|
+
- README.md
|
|
138
|
+
- Rakefile
|
|
139
|
+
- app/controllers/jabysoft/base_controller.rb
|
|
140
|
+
- app/helpers/base_helper.rb
|
|
141
|
+
- app/helpers/links_helper.rb
|
|
142
|
+
- app/helpers/render_helper.rb
|
|
143
|
+
- app/models/concerns/jabysoft/extension_model_behaviour.rb
|
|
144
|
+
- app/models/concerns/jabysoft/searchable_behaviour.rb
|
|
145
|
+
- app/services/jabysoft/authorisation_service.rb
|
|
146
|
+
- bin/console
|
|
147
|
+
- bin/setup
|
|
148
|
+
- jabysoft-rails_patterns.gemspec
|
|
149
|
+
- lib/jabysoft/rails_patterns.rb
|
|
150
|
+
- lib/jabysoft/rails_patterns/configuration.rb
|
|
151
|
+
- lib/jabysoft/rails_patterns/version.rb
|
|
152
|
+
homepage: https://github.com/jabysoft/jabysoft-rails_patterns
|
|
153
|
+
licenses:
|
|
154
|
+
- MIT
|
|
155
|
+
metadata:
|
|
156
|
+
allowed_push_host: https://rubygems.org/
|
|
157
|
+
post_install_message:
|
|
158
|
+
rdoc_options: []
|
|
159
|
+
require_paths:
|
|
160
|
+
- lib
|
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
|
+
requirements:
|
|
163
|
+
- - ">="
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0'
|
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
|
+
requirements:
|
|
168
|
+
- - ">="
|
|
169
|
+
- !ruby/object:Gem::Version
|
|
170
|
+
version: '0'
|
|
171
|
+
requirements: []
|
|
172
|
+
rubyforge_project:
|
|
173
|
+
rubygems_version: 2.6.8
|
|
174
|
+
signing_key:
|
|
175
|
+
specification_version: 4
|
|
176
|
+
summary: RailsPatterns set of patterns
|
|
177
|
+
test_files: []
|