microservice 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 (50) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/microservice_manifest.js +2 -0
  6. data/app/assets/images/microservice/favicon.ico +0 -0
  7. data/app/assets/images/microservice/logo.svg +51 -0
  8. data/app/assets/javascripts/microservice/application.js +21 -0
  9. data/app/assets/javascripts/microservice/microservice.js +0 -0
  10. data/app/assets/stylesheets/microservice/application.css +16 -0
  11. data/app/assets/stylesheets/microservice/microservice.css +0 -0
  12. data/app/controllers/microservice/application_controller.rb +58 -0
  13. data/app/controllers/microservice/entities_controller.rb +138 -0
  14. data/app/controllers/microservice/omniauth_callbacks_controller.rb +36 -0
  15. data/app/controllers/microservice/welcome_controller.rb +8 -0
  16. data/app/helpers/microservice/application_helper.rb +216 -0
  17. data/app/helpers/microservice/breadcrumbs_helper.rb +89 -0
  18. data/app/jobs/microservice/application_job.rb +5 -0
  19. data/app/mailers/microservice/application_mailer.rb +13 -0
  20. data/app/mailers/microservice/devise_mailer.rb +13 -0
  21. data/app/models/microservice/concerns/entity_cloneable.rb +40 -0
  22. data/app/models/microservice/concerns/entity_model.rb +118 -0
  23. data/app/models/microservice/concerns/entity_movable.rb +27 -0
  24. data/app/models/microservice/concerns/entity_naming.rb +95 -0
  25. data/app/models/microservice/concerns/user_model.rb +36 -0
  26. data/app/views/layouts/microservice/application.html.erb +26 -0
  27. data/app/views/layouts/microservice/mailer.html.erb +13 -0
  28. data/app/views/layouts/microservice/mailer.text.erb +1 -0
  29. data/app/views/microservice/common/_no_data.html.erb +6 -0
  30. data/app/views/microservice/common/error.html.erb +7 -0
  31. data/app/views/microservice/common/error.json.jbuilder +3 -0
  32. data/app/views/microservice/entities/_card.html.erb +17 -0
  33. data/app/views/microservice/entities/_form.html.erb +0 -0
  34. data/app/views/microservice/entities/edit.html.erb +16 -0
  35. data/app/views/microservice/entities/index.html.erb +7 -0
  36. data/app/views/microservice/entities/new.html.erb +19 -0
  37. data/app/views/microservice/entities/show.html.erb +3 -0
  38. data/app/views/microservice/welcome/index.html.erb +1 -0
  39. data/config/initializers/devise.rb +270 -0
  40. data/config/initializers/microservice.rb +5 -0
  41. data/config/initializers/sso.rb +78 -0
  42. data/config/locales/en.yml +55 -0
  43. data/config/routes.rb +5 -0
  44. data/db/migrate/20170618202500_create_users.rb +51 -0
  45. data/lib/microservice.rb +27 -0
  46. data/lib/microservice/engine.rb +16 -0
  47. data/lib/microservice/settings.rb +62 -0
  48. data/lib/microservice/version.rb +3 -0
  49. data/lib/tasks/microservice_tasks.rake +4 -0
  50. metadata +330 -0
@@ -0,0 +1,89 @@
1
+ module Microservice
2
+ module BreadcrumbsHelper
3
+
4
+ def render_breadcrumb(*args)
5
+ flatten_args = args.flatten.compact
6
+ content_tag :div, class: 'ui huge breadcrumb' do
7
+ flatten_args.map.with_index do |element, idx|
8
+ if flatten_args.size == idx + 1
9
+ content_tag(:span, element.html_safe, class: 'section active')
10
+ else
11
+ content_tag(:span, element.html_safe, class: 'section') +
12
+ content_tag(:i, '', class: 'right chevron icon divider')
13
+ end
14
+ end.join.html_safe
15
+ end
16
+ end
17
+
18
+ def render_entity_breadcrumb
19
+ if @entity
20
+ case action_name
21
+ when 'show'
22
+ render_breadcrumb_show @entity
23
+ when 'new', 'create'
24
+ render_breadcrumb_new @entity
25
+ when 'edit', 'update'
26
+ render_breadcrumb_edit @entity
27
+ end
28
+ elsif controller.entity_class
29
+ render_breadcrumb_index controller.entity_class
30
+ end
31
+ end
32
+
33
+ def render_breadcrumb_index(entity_class)
34
+ links = [home_link(entity_class.namespace)]
35
+
36
+ if @parent_entity
37
+ links << link_to_entity(@parent_entity.class, :index, no_icon: true)
38
+ links << link_to_entity(@parent_entity, :show, no_icon: true)
39
+ end
40
+
41
+ links << link_to_entity(entity_class, :index, no_icon: true)
42
+
43
+ render_breadcrumb links
44
+ end
45
+
46
+ def render_breadcrumb_show(entity)
47
+ links = [home_link(entity.namespace)]
48
+
49
+ if @parent_entity
50
+ links << link_to_entity(@parent_entity.class, :index, no_icon: true)
51
+ links << link_to_entity(@parent_entity, :show, no_icon: true)
52
+ end
53
+
54
+ links << link_to_entity(entity.class, :index, no_icon: true)
55
+ links << link_to_entity(entity, :show, no_icon: true)
56
+
57
+ render_breadcrumb links
58
+ end
59
+
60
+ def render_breadcrumb_new(entity)
61
+ links = [home_link(entity.namespace)]
62
+
63
+ if @parent_entity
64
+ links << link_to_entity(@parent_entity.class, :index, no_icon: true)
65
+ links << link_to_entity(@parent_entity, :show, no_icon: true)
66
+ end
67
+
68
+ links << link_to_entity(entity.class, :index, no_icon: true)
69
+ links << link_to_entity(entity.class, :new, no_icon: true)
70
+
71
+ render_breadcrumb links
72
+ end
73
+
74
+ def render_breadcrumb_edit(entity)
75
+ links = [home_link(entity.namespace)]
76
+
77
+ if @parent_entity
78
+ links << link_to_entity(@parent_entity.class, :index, no_icon: true)
79
+ links << link_to_entity(@parent_entity, :show, no_icon: true)
80
+ end
81
+
82
+ links << link_to_entity(entity.class, :index, no_icon: true)
83
+ links << link_to_entity(entity, :edit, no_icon: true)
84
+
85
+ render_breadcrumb links
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,5 @@
1
+ module Microservice
2
+ class ApplicationJob < ::ActiveJob::Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ module Microservice
2
+ class ApplicationMailer < ::ActionMailer::Base
3
+
4
+ default from: Microservice::Settings.email_default_from
5
+
6
+ layout 'microservice/mailer'
7
+
8
+ def self.default_url_options
9
+ {host: Microservice::Settings.host_name, protocol: Microservice::Settings.protocol}
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Microservice
2
+ class DeviseMailer < ::Devise::Mailer
3
+
4
+ default from: Microservice::Settings.email_default_from
5
+
6
+ layout 'microservice/mailer'
7
+
8
+ def self.default_url_options
9
+ {host: Microservice::Settings.host_name, protocol: Microservice::Settings.protocol}
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ module Microservice
2
+ module Concerns
3
+ module EntityCloneable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+
8
+ after_create :copy_associations, if: -> {self.copied_from.present?}
9
+
10
+ attr_accessor :copied_from, :copy_options
11
+
12
+ end
13
+
14
+ class_methods do
15
+
16
+ def copy_from(arg, options = {})
17
+ source = arg.is_a?(::ApplicationRecord) ? arg : self.class.find(arg)
18
+
19
+ copy = self.new
20
+ copy.attributes = source.attributes.dup.except(*copy_attributes_exceptions)
21
+ copy.copied_from = source
22
+ copy.copy_options = options
23
+
24
+ copy
25
+ end
26
+
27
+ def copy_attributes_exceptions
28
+ %w(id created_at updated_at)
29
+ end
30
+
31
+ end
32
+
33
+ protected
34
+
35
+ def copy_associations
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,118 @@
1
+ module Microservice
2
+ module Concerns
3
+
4
+ # Example of migration:
5
+ #
6
+ # create_table :table_name, force: true do |t|
7
+ # t.string :name, null: false
8
+ # t.text :description, null: true
9
+ # t.boolean :active, null: false, default: true
10
+ #
11
+ # t.references :author, null: false
12
+ # t.references :updated_by, null: true
13
+ # t.timestamps null: false
14
+ # end
15
+ #
16
+
17
+ module EntityModel
18
+ extend ActiveSupport::Concern
19
+
20
+ included do
21
+
22
+ class_attribute :namespace, :search_fields, :sort_field, :parent_entity_symbol
23
+ class_attribute :hide_top_menu_new, :hide_top_menu_search
24
+
25
+ scope :sorted, -> {order(sort_field || :name)}
26
+ scope :search, -> (text) {where(Array(search_fields || default_search_fields).map {|f| arel_table[f].matches("%#{text}%")}.inject(:or))}
27
+ scope :active, -> {where(active: true) if column_names.include?('active')}
28
+
29
+ belongs_to :author, optional: true, class_name: 'User'
30
+ belongs_to :updated_by, optional: true, class_name: 'User'
31
+
32
+ end
33
+
34
+ class_methods do
35
+
36
+ def belongs_to_parent(name, options={})
37
+ self.parent_entity_symbol = name
38
+ belongs_to(name, options={})
39
+ end
40
+
41
+ def default_search_fields
42
+ f = []
43
+ f << :name if self.column_names.include?('name')
44
+ f << :description if self.column_names.include?('description')
45
+ f
46
+ end
47
+
48
+ def css_class(_options = {})
49
+ ''
50
+ end
51
+
52
+ def description
53
+ I18n.t(self.model_name.i18n_key, scope: [:text_entity_description])
54
+ end
55
+
56
+ def parent_entity_id_symbol
57
+ @parent_entity_id_symbol ||= (parent_entity_symbol.to_s + '_id').to_sym if parent_entity_symbol
58
+ end
59
+
60
+ def parent_entity_class
61
+ @parent_entity_class ||= self.reflect_on_association(parent_entity_symbol).klass if parent_entity_symbol
62
+ end
63
+
64
+ def class_route_array(parent_entity = nil)
65
+ if parent_entity_symbol
66
+ [parent_entity, self.namespace, self.base_class]
67
+ else
68
+ [self.namespace, self.base_class]
69
+ end
70
+ end
71
+
72
+ def _to_form_path #:nodoc:
73
+ @_to_form_path ||= begin
74
+ n = ''
75
+ n = "#{self.namespace}/" if self.namespace
76
+ collection = ActiveSupport::Inflector.tableize(name)
77
+
78
+ "#{n}#{collection}/form".freeze
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ def css_class(options = {})
85
+ self.class.css_class(options)
86
+ end
87
+
88
+ def parent_entity
89
+ send(parent_entity_symbol) if parent_entity_symbol
90
+ end
91
+
92
+ def parent_entity=(value)
93
+ send(parent_entity_symbol.to_s + '=', value) if parent_entity_symbol
94
+ end
95
+
96
+ def polymorphic_class
97
+ self.becomes(self.class.base_class)
98
+ end
99
+
100
+ def model_route_array
101
+ [self.namespace, self.parent_entity, polymorphic_class]
102
+ end
103
+
104
+ def class_route_array
105
+ self.class.class_route_array
106
+ end
107
+
108
+ def to_form_path
109
+ self.class._to_form_path
110
+ end
111
+
112
+ def last_touch_by
113
+ updated_by || author
114
+ end
115
+
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,27 @@
1
+ module Microservice
2
+ module Concerns
3
+ module EntityMovable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+
8
+ after_save :do_move, if: -> {self.move_attributes.present?}
9
+
10
+ attr_accessor :move_attributes
11
+
12
+ end
13
+
14
+ protected
15
+
16
+ def do_move
17
+ end
18
+
19
+ def create_target_entity_from(move_to_params)
20
+ return nil if move_to_params.blank?
21
+
22
+ move_to_params['target_class'].constantize.find(move_to_params['target_id'])
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,95 @@
1
+ module Microservice
2
+ module Concerns
3
+ module EntityNaming
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ end
8
+
9
+ class_methods do
10
+
11
+ def heading_index
12
+ I18n.t(:heading_entity_index, entities: self.base_class.model_name.plural.humanize)
13
+ end
14
+
15
+ def button_index
16
+ I18n.t(:button_entity_index, entities: self.base_class.model_name.plural.humanize)
17
+ end
18
+
19
+ def title_index
20
+ I18n.t(:title_entity_index, entities: self.base_class.model_name.plural)
21
+ end
22
+
23
+ def heading_show
24
+ self.model_name.human
25
+ end
26
+
27
+ def heading_new
28
+ I18n.t(:heading_entity_new, entity: self.model_name.human)
29
+ end
30
+
31
+ def button_new
32
+ I18n.t(:button_entity_new, entity: self.model_name.human)
33
+ end
34
+
35
+ def title_new
36
+ I18n.t(:title_entity_new, entity: self.model_name.human)
37
+ end
38
+
39
+ end
40
+
41
+ def heading_index
42
+ self.class.heading_index
43
+ end
44
+
45
+ def button_index
46
+ self.class.button_index
47
+ end
48
+
49
+ def title_index
50
+ self.class.title_index
51
+ end
52
+
53
+ def heading_show
54
+ I18n.t(:heading_entity_show, entity: self.name)
55
+ end
56
+
57
+ def button_show
58
+ name
59
+ end
60
+
61
+ def title_show
62
+ I18n.t(:title_entity_show, entity: self.name)
63
+ end
64
+
65
+ def heading_new
66
+ self.class.heading_new
67
+ end
68
+
69
+ def button_new
70
+ self.class.button_new
71
+ end
72
+
73
+ def title_new
74
+ self.class.title_new
75
+ end
76
+
77
+ def heading_edit
78
+ I18n.t(:heading_entity_edit, entity: self.class.model_name.human)
79
+ end
80
+
81
+ def button_edit
82
+ I18n.t(:button_entity_edit, entity: self.class.model_name.human)
83
+ end
84
+
85
+ def title_edit
86
+ I18n.t(:title_entity_edit, entity: self.name)
87
+ end
88
+
89
+ def title_delete
90
+ I18n.t(:title_entity_delete, entity: self.name)
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,36 @@
1
+ module Microservice
2
+ module Concerns
3
+ module UserModel
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+
8
+ enum status: [:active]
9
+
10
+ devise :database_authenticatable, :trackable, :validatable,
11
+ :registerable, :recoverable, :rememberable, :confirmable, :lockable, :timeoutable,
12
+ :token_authenticatable,
13
+ :omniauthable, omniauth_providers: Microservice::Settings.omniauth_providers_keys
14
+
15
+ scope :admins, -> {where(admin: true)}
16
+
17
+ store :preferences, coder: JSON
18
+
19
+ thread_mattr_accessor :current
20
+
21
+ before_save :ensure_name
22
+
23
+ end
24
+
25
+ class_methods do
26
+ end
27
+
28
+ protected
29
+
30
+ def ensure_name
31
+ self.name = "#{first_name} #{last_name}"
32
+ end
33
+
34
+ end
35
+ end
36
+ end