kirgudu_common 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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/kirgudu_common/application.js +13 -0
  6. data/app/assets/stylesheets/kirgudu_common/application.css +15 -0
  7. data/app/helpers/kirgudu_common/application_helper.rb +4 -0
  8. data/app/models/kirgudu_common/concerns/models/administrated_by.rb +27 -0
  9. data/app/models/kirgudu_common/concerns/models/created_at.rb +36 -0
  10. data/app/models/kirgudu_common/concerns/models/created_by.rb +25 -0
  11. data/app/models/kirgudu_common/concerns/models/deletion_status_id.rb +28 -0
  12. data/app/models/kirgudu_common/concerns/models/id.rb +24 -0
  13. data/app/models/kirgudu_common/concerns/models/is_active.rb +24 -0
  14. data/app/models/kirgudu_common/concerns/models/managed_by.rb +25 -0
  15. data/app/models/kirgudu_common/concerns/models/name.rb +36 -0
  16. data/app/models/kirgudu_common/concerns/models/order_by.rb +21 -0
  17. data/app/models/kirgudu_common/concerns/models/owned_by.rb +26 -0
  18. data/app/models/kirgudu_common/concerns/models/person_age.rb +49 -0
  19. data/app/models/kirgudu_common/concerns/models/person_full_name.rb +41 -0
  20. data/app/models/kirgudu_common/concerns/models/portal_id.rb +26 -0
  21. data/app/models/kirgudu_common/concerns/models/portal_user_id.rb +26 -0
  22. data/app/models/kirgudu_common/concerns/models/slug.rb +43 -0
  23. data/app/models/kirgudu_common/concerns/models/status_id.rb +28 -0
  24. data/app/models/kirgudu_common/concerns/models/title.rb +40 -0
  25. data/app/models/kirgudu_common/concerns/models/updated_at.rb +41 -0
  26. data/app/models/kirgudu_common/concerns/models/updated_by.rb +29 -0
  27. data/app/models/kirgudu_common/concerns/models/user_id.rb +35 -0
  28. data/app/models/kirgudu_common/portal.rb +78 -0
  29. data/app/models/kirgudu_common/portal_user.rb +54 -0
  30. data/app/models/kirgudu_common/user.rb +104 -0
  31. data/app/models/kirgudu_common/view_template.rb +6 -0
  32. data/app/models/kirgudu_common/view_template_element.rb +6 -0
  33. data/app/views/layouts/kirgudu_common/application.html.erb +14 -0
  34. data/config/routes.rb +2 -0
  35. data/db/migrate/20130913084129_create_kirgudu_common_users.rb +55 -0
  36. data/db/migrate/20131114161828_create_kirgudu_common_view_templates.rb +30 -0
  37. data/db/migrate/20131114165013_create_kirgudu_common_view_template_elements.rb +34 -0
  38. data/db/migrate/20140208133148_create_kirgudu_common_portals.rb +37 -0
  39. data/db/migrate/20140208134642_create_kirgudu_common_portal_users.rb +23 -0
  40. data/lib/kirgudu_common/engine.rb +5 -0
  41. data/lib/kirgudu_common.rb +4 -0
  42. data/lib/tasks/kirgudu_common_tasks.rake +4 -0
  43. data/test/dummy/README.rdoc +28 -0
  44. data/test/dummy/Rakefile +6 -0
  45. data/test/dummy/app/assets/javascripts/application.js +13 -0
  46. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  47. data/test/dummy/app/controllers/application_controller.rb +5 -0
  48. data/test/dummy/app/helpers/application_helper.rb +2 -0
  49. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/test/dummy/bin/bundle +3 -0
  51. data/test/dummy/bin/rails +4 -0
  52. data/test/dummy/bin/rake +4 -0
  53. data/test/dummy/config/application.rb +23 -0
  54. data/test/dummy/config/boot.rb +5 -0
  55. data/test/dummy/config/database.yml +25 -0
  56. data/test/dummy/config/environment.rb +5 -0
  57. data/test/dummy/config/environments/development.rb +37 -0
  58. data/test/dummy/config/environments/production.rb +82 -0
  59. data/test/dummy/config/environments/test.rb +39 -0
  60. data/test/dummy/config/initializers/assets.rb +8 -0
  61. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  63. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/test/dummy/config/initializers/inflections.rb +16 -0
  65. data/test/dummy/config/initializers/mime_types.rb +4 -0
  66. data/test/dummy/config/initializers/session_store.rb +3 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +23 -0
  69. data/test/dummy/config/routes.rb +4 -0
  70. data/test/dummy/config/secrets.yml +22 -0
  71. data/test/dummy/config.ru +4 -0
  72. data/test/dummy/public/404.html +67 -0
  73. data/test/dummy/public/422.html +67 -0
  74. data/test/dummy/public/500.html +66 -0
  75. data/test/dummy/public/favicon.ico +0 -0
  76. data/test/integration/navigation_test.rb +10 -0
  77. data/test/kirgudu_common_test.rb +7 -0
  78. data/test/test_helper.rb +15 -0
  79. metadata +199 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c5ceee6988ceb7945d68f41bf1cb1eeb6e384a2
4
+ data.tar.gz: f6dd2d73f5e83aab47d74259351f63179d754da8
5
+ SHA512:
6
+ metadata.gz: 73cb2ec19a56a8e5f500a6cd91b14cfbe1ca1e8d01c2c88e22901af3c98a6a0ae50948e24a58052aa6f8ce46071b0478304a9ddd67e4755da51da49373869a40
7
+ data.tar.gz: 600e0bf3dff7cf425078a2b3b378afb32fb2a8ba2eb32e31f471a6137b5660ceb7ad880b7a520fa03d3e641dda3d2816513c488847ec216d710b330b5b7fc4ca
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
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.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = KirguduCommon
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
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 = 'KirguduCommon'
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("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module KirguduCommon
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,27 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::AdministratedBy
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_query :query_add_administrated_by
7
+
8
+ belongs_to :administrator, class_name: "::KirguduCommon::User", foreign_key: :administrated_by
9
+
10
+ scope :by_administrator, lambda { |value| where(administrated_by: value) if value }
11
+ end
12
+
13
+
14
+ def administrator_name
15
+ self.administrator.full_name if self.administrator
16
+ end
17
+
18
+ module ClassMethods
19
+ def query_add_administrated_by(query, filters)
20
+ query.by_updated_by(filters[:updated_by])
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+
@@ -0,0 +1,36 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::CreatedAt
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_query :query_add_created_at
7
+
8
+ base.scope :with_created_at_me, lambda { |value| base.where { created_at >= value } if value }
9
+ base.scope :with_created_at_le, lambda { |value| base.where { created_at <= value } if value }
10
+
11
+ base.scope :with_created_at_m, lambda { |value| base.where { created_at > value } if value }
12
+ base.scope :with_created_at_l, lambda { |value| base.where { created_at < value } if value }
13
+ end
14
+
15
+ def created_at_formatted
16
+ #time_ago_in_words()
17
+ time_distance_in_words = distance_of_time_in_words(self.created_at, DateTime.now.utc, true)
18
+ time_dt_format = self.created_at.strftime("%d.%m.%Y %H:%M")
19
+
20
+ #"#{time_distance_in_words} (#{time_dt_format})"
21
+ end
22
+
23
+
24
+ module ClassMethods
25
+ def query_add_created_at(query, filters)
26
+ query
27
+ .with_created_at_me(filters[:created_at_me])
28
+ .with_created_at_le(filters[:created_at_le])
29
+ .with_created_at_m(filters[:created_at_m])
30
+ .with_created_at_l(filters[:created_at_l])
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,25 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::CreatedBy
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_query :query_add_created_by
7
+
8
+ belongs_to :creator, class_name: "::KirguduCommon::User", foreign_key: :created_by
9
+ scope :by_created_by, lambda { |value| where(created_by: value) if value }
10
+ end
11
+
12
+ def creator_name
13
+ self.creator.full_name if self.creator
14
+ end
15
+
16
+
17
+ module ClassMethods
18
+ def query_add_created_by(query, filters)
19
+ query.by_created_by(filters[:created_by])
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+
@@ -0,0 +1,28 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::DeletionStatusId
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_query :query_add_deletion_status_id
7
+
8
+ enum :deletion_status_id, [:unknown, :actual, :deleted, :purged]
9
+
10
+
11
+ scope :by_deletion_status, lambda { |value| where(deletion_status_id: value) if value }
12
+ end
13
+
14
+
15
+ def deletion_status_name
16
+ I18n.t("kirgudu_base.common.enums.deletion_status.#{self.deletion_status_id}")
17
+ end
18
+
19
+
20
+ module ClassMethods
21
+ def query_add_deletion_status_id(query, filters)
22
+ query.by_deletion_status(filters[:deletion_status_id])
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+
@@ -0,0 +1,24 @@
1
+ module KirguduCommon
2
+ #module Concerns::Models::Name
3
+ module Concerns::Models::Id
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_query :query_add_id
8
+
9
+ scope :by_id, lambda { |value| where(name: value) if value }
10
+ end
11
+
12
+
13
+
14
+ module ClassMethods
15
+ def query_add_id(query, filters)
16
+ query.by_id(filters[:id])
17
+
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+
@@ -0,0 +1,24 @@
1
+ module KirguduCommon
2
+ #module Concerns::Models::Name
3
+ module Concerns::Models::IsActive
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_query :query_add_id_active
8
+
9
+ scope :by_is_active, lambda { |value| where(is_active: value) if value }
10
+ end
11
+
12
+
13
+
14
+ module ClassMethods
15
+ def query_add_id_active(query, filters)
16
+ query.by_is_active(filters[:is_active])
17
+
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+
@@ -0,0 +1,25 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::ManagedBy
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_query :query_add_managed_by
7
+
8
+ belongs_to :manager, class_name: "::KirguduCommon::User", foreign_key: :managed_by
9
+ scope :by_managed_by, lambda { |value| where(managed_by: value) if value }
10
+ end
11
+
12
+
13
+ def manager_name
14
+ self.manager.full_name if self.manager
15
+ end
16
+
17
+ module ClassMethods
18
+ def query_add_managed_by(query, filters)
19
+ query.by_managed_by(filters[:managed_by])
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+
@@ -0,0 +1,36 @@
1
+ module KirguduCommon
2
+ #module Concerns::Models::Name
3
+ module Concerns::Models::Name
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_validation :normalize_name
8
+ before_query :query_add_name
9
+
10
+ validates_presence_of :name
11
+ validates_length_of :name, maximum: 128, allow_blank: true
12
+
13
+
14
+ scope :with_name, lambda {
15
+ |value|
16
+ like_value = "%#{value.gsub('%', ' ').strip}%" rescue nil
17
+ where { (name.like like_value) } if like_value
18
+ }
19
+ scope :by_name, lambda { |value| where(name: value) if value }
20
+ end
21
+
22
+ def normalize_name
23
+ self.name.strip! if self.name
24
+ end
25
+
26
+ module ClassMethods
27
+ def query_add_name(query, filters)
28
+ query.with_name(filters[:name])
29
+
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,21 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::OrderBy
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_query :query_add_order_by
7
+
8
+ scope :order_by, lambda { |value| order(value) if value }
9
+ end
10
+
11
+
12
+ module ClassMethods
13
+ def query_add_order_by(query, filters)
14
+ query.order_by(filters[:order])
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+
@@ -0,0 +1,26 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::OwnedBy
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_query :query_add_owned_by
7
+
8
+ belongs_to :owner, class_name: "::KirguduCommon::User", foreign_key: :owned_by
9
+ scope :by_owned_by, lambda { |value| where(owned_by: value) if value }
10
+ end
11
+
12
+
13
+ def owner_name
14
+ self.owner.full_name if self.owner
15
+ end
16
+
17
+ module ClassMethods
18
+ def query_add_owned_by(query, filters)
19
+ query.by_owned_by(filters[:owned_by])
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+
@@ -0,0 +1,49 @@
1
+ module KirguduCommon
2
+ module Concerns::Models::PersonAge
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ end
8
+
9
+
10
+ def age
11
+ today = DateTime.now.utc.to_date
12
+
13
+ bd = if self.respond_to?(:birth_date)
14
+ self.birth_date.to_date
15
+ elsif self.respond_to?(:birthdate)
16
+ self.birthdate.to_date
17
+ else
18
+ nil
19
+ end rescue nil
20
+
21
+ bd.nil? ? nil : today.year - bd.year - (bd.change(:year => today.year) > today ? 1 : 0)
22
+ end
23
+
24
+ def next_birth_date
25
+ ag = self.age
26
+ if ag
27
+ bd = if self.respond_to?(birth_date)
28
+ self.birth_date.to_date
29
+ elsif self.respond_to?(birthdate)
30
+ self.birthdate.to_date
31
+ else
32
+ nil
33
+ end
34
+ bd.nil? ? nil : bd + (ag+1).years
35
+ else
36
+ nil
37
+ end
38
+ end
39
+
40
+ def days_to_next_birth_date
41
+ nbd = self.next_birth_date
42
+ nbd.nil? ? -1 : nbd - DateTime.now.utc.to_date
43
+ end
44
+
45
+
46
+ end
47
+ end
48
+
49
+