rails_admin_extra_field_types 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc03a6c9eb14e92fc2db75fac4385039df61bc86
4
+ data.tar.gz: 9dd97e72001062fdd86eebe458fc51922fcf9422
5
+ SHA512:
6
+ metadata.gz: 0ef62c0e92f9449b6bbb2dbb3e0caa420da0322383ed189cb9dfbfa59f518c85e4609814bd10ef7272e3ea17038d18c34f0df0c69ddf11973b67fd1311191a64
7
+ data.tar.gz: ff8a9bbd70b3a1cae52e9a15e352a1e1f25b91adcc0e4a7027d8219d5b79d8cf73503c45a306289aefb77615a667087c79313426b139cd37302f01c2a6a5f0dc
@@ -0,0 +1,20 @@
1
+ Copyright 2016 wiseallie
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsAdminExtraFieldTypes'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,62 @@
1
+ require 'rails_admin/adapters/active_record'
2
+ module RailsAdmin
3
+ module Adapters
4
+ module ActiveRecord
5
+ module StatementBuilderWithExtraTypesExtension
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias_method_chain :build_statement_for_type, :extra_types
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def build_statement_for_type_with_extra_types
15
+ case @type
16
+ when :boolean then build_statement_for_boolean
17
+ when :integer, :decimal, :float then build_statement_for_integer_decimal_or_float
18
+ when :string, :text then build_statement_for_string_or_text
19
+ when :citext then build_statement_for_string_or_text
20
+ when :uuid then build_statement_for_uuid
21
+ when :enum then build_statement_for_enum
22
+ when :belongs_to_association then build_statement_for_belongs_to_association
23
+ end
24
+ end
25
+
26
+ def build_statement_for_type
27
+ build_statement_for_type_with_extra_types
28
+ end
29
+
30
+ def build_statement_for_uuid
31
+ return if @value.blank?
32
+ @value = begin
33
+ case @operator
34
+ when 'default', 'like'
35
+ "%#{@value.downcase}%"
36
+ when 'starts_with'
37
+ "#{@value.downcase}%"
38
+ when 'ends_with'
39
+ "%#{@value.downcase}"
40
+ when 'is', '='
41
+ "#{@value.downcase}"
42
+ else
43
+ return
44
+ end
45
+ end
46
+
47
+ if ar_adapter == 'postgresql'
48
+ ["(#{@column}::text ILIKE ?)", @value]
49
+ else
50
+ ["(LOWER(CAST(#{@column} AS VARCHAR(50))) LIKE ?)", @value.to_s.downcase]
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ if RUBY_VERSION >= '2.0.0'
59
+ RailsAdmin::Adapters::ActiveRecord::StatementBuilder.send(:prepend, RailsAdmin::Adapters::ActiveRecord::StatementBuilderWithExtraTypesExtension)
60
+ else
61
+ RailsAdmin::Adapters::ActiveRecord::StatementBuilder.send(:include, RailsAdmin::Adapters::ActiveRecord::StatementBuilderWithExtraTypesExtension)
62
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'adapters/active_record/statement_builder_with_extra_types_extension'
2
+ require_relative 'config/fields/types/citext'
3
+ require_relative 'config/fields/types/uuid'
@@ -0,0 +1,7 @@
1
+ require 'rails_admin/config/fields/base'
2
+
3
+ module RailsAdmin::Config::Fields::Types
4
+ class Citext < RailsAdmin::Config::Fields::Types::String
5
+ RailsAdmin::Config::Fields::Types::register(:citext, self)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails_admin/config/fields/base'
2
+
3
+ module RailsAdmin::Config::Fields::Types
4
+ class Uuid < RailsAdmin::Config::Fields::Types::String
5
+ RailsAdmin::Config::Fields::Types::register(:uuid, self)
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ require "rails_admin_extra_field_types/engine"
2
+ require 'rails_admin'
3
+ require_relative 'rails_admin/all'
4
+
5
+ module RailsAdminExtraFieldTypes
6
+ end
@@ -0,0 +1,4 @@
1
+ module RailsAdminExtraFieldTypes
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminExtraFieldTypes
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_admin_extra_field_types do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_extra_field_types
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - wiseallie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails_admin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: 'Support for rails_admin field types UUID and Citext '
56
+ email:
57
+ - wiseallie@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - Rakefile
64
+ - config/routes.rb
65
+ - lib/rails_admin/adapters/active_record/statement_builder_with_extra_types_extension.rb
66
+ - lib/rails_admin/all.rb
67
+ - lib/rails_admin/config/fields/types/citext.rb
68
+ - lib/rails_admin/config/fields/types/uuid.rb
69
+ - lib/rails_admin_extra_field_types.rb
70
+ - lib/rails_admin_extra_field_types/engine.rb
71
+ - lib/rails_admin_extra_field_types/version.rb
72
+ - lib/tasks/rails_admin_extra_field_types_tasks.rake
73
+ homepage: https://github.com/wiseallie/rails_admin_extra_field_types
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.8
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Support for rails_admin field types UUID and Citext
97
+ test_files: []