opale 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '014438d6dfe054aa0cc478682b55c58a42b686bec88910670b18de63ea166b99'
4
+ data.tar.gz: 3e80d72ea1e3f2d74b450de5818ca24bd7ceb97c2b6eb2cf396e16864fd66478
5
+ SHA512:
6
+ metadata.gz: ea946d9608ffa121c693bbb3d5cf09bcb9eac9a51180122a3fe87bfcdc09a08c4462e317f8bef78ce3004bac632c65504fde4a731c71eee47c7f235aed5e365f
7
+ data.tar.gz: c31e609edbca18c574c7fb3f4ac0822ffb680b9509975883edcc6b2b74d54422d59dfe7b1fb38d26c4e40aec233138f0da4b4d5be82ee5926cfa24911eb65d62
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.1
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in opale.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Opale
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/opale`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'opale'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install opale
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]/opale.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ function sortable(event, column) {
2
+ var direction = $("#direction").val();
3
+
4
+ $("#sort").val(column);
5
+ $("#direction").val(direction == "desc" ? "asc" : "desc");
6
+
7
+ $('#direction').parent().submit();
8
+
9
+ event.preventDefault();
10
+ }
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "opale"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,80 @@
1
+ # Concern for sorting models
2
+ module Sort
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :sort
7
+ end
8
+
9
+ private
10
+
11
+ def sort
12
+ return if params['searching'].nil?
13
+
14
+ @search_hash = Array.new
15
+ objects = Array.new
16
+
17
+ params.each do |k, v|
18
+ unless v.class.eql? String
19
+ objects << k
20
+ @search_hash << v
21
+ end
22
+ end
23
+
24
+ # If the object is inside a namespace
25
+ if objects[0].include? '::'
26
+ to_capitalize = objects[0].split('::')
27
+ # We split the string with '::' and camelize the two words
28
+ # Then we have to join again with '::' the capitalized words
29
+ results = (to_capitalize.map { |o| o.camelize.singularize }).join('::').constantize.unscoped
30
+ else
31
+ results = objects[0].camelize.constantize.unscoped
32
+ end
33
+
34
+ @search_hash.each_with_index do |object_params, index|
35
+ table_name = objects[index].pluralize
36
+ table_name = params[:table_name] if params[:table_name]
37
+
38
+ object_params.each do |k, v|
39
+ next unless v.present?
40
+
41
+ if v.eql? 'null'
42
+ if index != 0
43
+ results = results.joins(table_name.to_sym).where("#{table_name}.#{k} is null")
44
+ else
45
+ results = results.where("#{table_name}.#{k} is null")
46
+ end
47
+ elsif !v.nil?
48
+ if index != 0
49
+ if k.eql?('created_at') || k.eql?('updated_at')
50
+ results = results.where("created_at::date = to_date(?, 'YYYY/MM/DD')", v)
51
+ else
52
+ results = results.joins(table_name.to_sym).where("#{table_name}.#{k}::varchar ILIKE '%#{v}%'")
53
+ end
54
+ else
55
+ results = results.where("#{table_name}.#{k}::varchar ILIKE ?", "%#{v}%")
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ objects_per_page = (params.select { |k, v| k.match /per_page$/ }).values.first
63
+ objects_per_page ||= 20
64
+ @result = results.distinct.paginate(page: params[:page], per_page: objects_per_page).order(sort_options)
65
+ end
66
+
67
+ private
68
+
69
+ def sort_options
70
+ "#{sort_column} #{sort_direction}"
71
+ end
72
+
73
+ def sort_column
74
+ params[:sort] ? params[:sort] : 'updated_at'
75
+ end
76
+
77
+ def sort_direction
78
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
79
+ end
80
+ end
@@ -0,0 +1,25 @@
1
+ module SortableHelper
2
+ def search_form_fields(table_name = nil, &block)
3
+ searching_field = hidden_field_tag :searching, true
4
+ table_name_field = hidden_field_tag :table_name, table_name unless table_name.nil?
5
+ sort_field = hidden_field_tag :sort, params[:sort] || :updated_at
6
+ direction_field = hidden_field_tag :direction, params[:direction] || :desc
7
+
8
+ searching_field.concat(sort_field)
9
+ searching_field.concat(direction_field)
10
+ searching_field.concat(table_name_field)
11
+
12
+ searching_field
13
+ end
14
+
15
+ def th(options, &block)
16
+ css_class = options[:table_name] == sort_column ? "current #{sort_direction}" : nil
17
+ # direction = options[:table_name] == sort_column && sort_direction == 'asc' ? 'desc' : 'asc'
18
+
19
+ content_tag :th, class: options[:class], style: options[:style] do
20
+ link_to '#', { class: css_class, onclick: "sortable(event, '#{options[:table_name]}')" } do
21
+ block.call unless block.nil?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Opale
2
+ VERSION = '0.1.0'
3
+ end
data/opale.gemspec ADDED
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "opale/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opale"
8
+ spec.version = Opale::VERSION
9
+ spec.authors = ["Poulpy"]
10
+ spec.email = ["paul.repain@yahoo.com"]
11
+ spec.homepage = "http://rubygems.org/gems/opale"
12
+
13
+ spec.summary = "Summary"
14
+ spec.description = "Description"
15
+ spec.homepage = "http://www.opale.fr"
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"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ #spec.metadata["homepage_uri"] = spec.homepage
23
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+ spec.files = `git ls-files`.split("\n")
39
+
40
+ spec.add_development_dependency "bundler", "~> 2.0"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rspec", "~> 3.0"
43
+ spec.add_dependency 'rails', '~> 5.2.2'
44
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.describe Opale do
2
+ it "has a version number" do
3
+ expect(Opale::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "opale"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opale
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Poulpy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-16 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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.2.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.2.2
69
+ description: Description
70
+ email:
71
+ - paul.repain@yahoo.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - assets/javascripts/sortable.js
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/controllers/concerns/sortable.rb
86
+ - lib/helpers/sortables_helper.rb
87
+ - lib/opale/version.rb
88
+ - opale.gemspec
89
+ - spec/opale_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: http://www.opale.fr
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.7.9
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Summary
114
+ test_files: []