arpa 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -0
- data/Rakefile +2 -0
- data/arpa.gemspec +33 -0
- data/lib/arpa.rb +91 -0
- data/lib/arpa/additions/resource.rb +29 -0
- data/lib/arpa/assets/stylesheets/ar_accordion.scss +80 -0
- data/lib/arpa/controllers/profiles_controller.rb +106 -0
- data/lib/arpa/controllers/resources_controller.rb +47 -0
- data/lib/arpa/controllers/roles_controller.rb +106 -0
- data/lib/arpa/data_mappers/action_mapper.rb +13 -0
- data/lib/arpa/data_mappers/base.rb +117 -0
- data/lib/arpa/data_mappers/profile_mapper.rb +14 -0
- data/lib/arpa/data_mappers/resource_mapper.rb +11 -0
- data/lib/arpa/data_mappers/role_mapper.rb +14 -0
- data/lib/arpa/entities/action.rb +24 -0
- data/lib/arpa/entities/permissions.rb +35 -0
- data/lib/arpa/entities/profile.rb +22 -0
- data/lib/arpa/entities/resource.rb +58 -0
- data/lib/arpa/entities/role.rb +28 -0
- data/lib/arpa/exceptions/record_invalid.rb +13 -0
- data/lib/arpa/repositories/actions/creator.rb +18 -0
- data/lib/arpa/repositories/actions/finder.rb +23 -0
- data/lib/arpa/repositories/actions/remover.rb +22 -0
- data/lib/arpa/repositories/actions/repository_action.rb +15 -0
- data/lib/arpa/repositories/base.rb +15 -0
- data/lib/arpa/repositories/profiles/creator.rb +18 -0
- data/lib/arpa/repositories/profiles/finder.rb +29 -0
- data/lib/arpa/repositories/profiles/remover.rb +29 -0
- data/lib/arpa/repositories/profiles/repository_profile.rb +12 -0
- data/lib/arpa/repositories/profiles/updater.rb +23 -0
- data/lib/arpa/repositories/registrator.rb +44 -0
- data/lib/arpa/repositories/resources/creator.rb +18 -0
- data/lib/arpa/repositories/resources/finder.rb +45 -0
- data/lib/arpa/repositories/resources/remover.rb +22 -0
- data/lib/arpa/repositories/resources/repository_resource.rb +12 -0
- data/lib/arpa/repositories/roles/creator.rb +18 -0
- data/lib/arpa/repositories/roles/finder.rb +29 -0
- data/lib/arpa/repositories/roles/remover.rb +29 -0
- data/lib/arpa/repositories/roles/repository_role.rb +13 -0
- data/lib/arpa/repositories/roles/updater.rb +23 -0
- data/lib/arpa/services/actions/create/action_creator.rb +50 -0
- data/lib/arpa/services/actions/remove/action_remover.rb +24 -0
- data/lib/arpa/services/base.rb +41 -0
- data/lib/arpa/services/profiles/create/profile_creator.rb +32 -0
- data/lib/arpa/services/profiles/profile_manager_creator.rb +22 -0
- data/lib/arpa/services/profiles/profile_manager_remover.rb +24 -0
- data/lib/arpa/services/profiles/profile_manager_updater.rb +22 -0
- data/lib/arpa/services/profiles/remove/profile_remover.rb +25 -0
- data/lib/arpa/services/profiles/update/profile_updater.rb +32 -0
- data/lib/arpa/services/resources/create/resource_creator.rb +42 -0
- data/lib/arpa/services/resources/remove/resource_remover.rb +31 -0
- data/lib/arpa/services/resources/resource_manager_creator.rb +50 -0
- data/lib/arpa/services/roles/create/role_creator.rb +33 -0
- data/lib/arpa/services/roles/remove/role_remover.rb +25 -0
- data/lib/arpa/services/roles/role_manager_creator.rb +23 -0
- data/lib/arpa/services/roles/role_manager_remover.rb +23 -0
- data/lib/arpa/services/roles/role_manager_updater.rb +22 -0
- data/lib/arpa/services/roles/update/role_updater.rb +32 -0
- data/lib/arpa/services/verifier.rb +24 -0
- data/lib/arpa/validators/action_validator.rb +17 -0
- data/lib/arpa/validators/profile_validator.rb +19 -0
- data/lib/arpa/validators/resource_validator.rb +17 -0
- data/lib/arpa/validators/role_validator.rb +20 -0
- data/lib/arpa/version.rb +3 -0
- data/lib/arpa/views/profiles/_form.html.erb +41 -0
- data/lib/arpa/views/profiles/edit.html.erb +6 -0
- data/lib/arpa/views/profiles/index.html.erb +29 -0
- data/lib/arpa/views/profiles/new.html.erb +5 -0
- data/lib/arpa/views/profiles/show.html.erb +37 -0
- data/lib/arpa/views/resources/index.html.erb +27 -0
- data/lib/arpa/views/resources/show.html.erb +33 -0
- data/lib/arpa/views/roles/_form.html.erb +55 -0
- data/lib/arpa/views/roles/edit.html.erb +6 -0
- data/lib/arpa/views/roles/index.html.erb +29 -0
- data/lib/arpa/views/roles/new.html.erb +5 -0
- data/lib/arpa/views/roles/show.html.erb +37 -0
- data/lib/config/locales/arpa.en.yml +38 -0
- data/lib/generators/ar/install_generator.rb +74 -0
- data/lib/generators/ar/templates/migration.rb +48 -0
- data/spec/factories/repository_actions.rb +19 -0
- data/spec/factories/repository_profiles.rb +11 -0
- data/spec/factories/repository_resources.rb +15 -0
- data/spec/factories/repository_roles.rb +11 -0
- data/spec/lib/ar/additions/resource_spec.rb +34 -0
- data/spec/lib/ar/data_mappers/action_mapper_spec.rb +46 -0
- data/spec/lib/ar/data_mappers/base_spec.rb +47 -0
- data/spec/lib/ar/data_mappers/profile_mapper_spec.rb +43 -0
- data/spec/lib/ar/data_mappers/resource_mapper_spec.rb +38 -0
- data/spec/lib/ar/data_mappers/role_mapper_spec.rb +47 -0
- data/spec/lib/ar/entities/action_spec.rb +19 -0
- data/spec/lib/ar/entities/permissions_spec.rb +61 -0
- data/spec/lib/ar/entities/resource_spec.rb +35 -0
- data/spec/lib/ar/repositories/actions/finder_spec.rb +40 -0
- data/spec/lib/ar/repositories/base_spec.rb +37 -0
- data/spec/lib/ar/repositories/profiles/finder_spec.rb +43 -0
- data/spec/lib/ar/repositories/profiles/remover_spec.rb +31 -0
- data/spec/lib/ar/repositories/resources/finder_spec.rb +92 -0
- data/spec/lib/ar/repositories/resources/remover_spec.rb +38 -0
- data/spec/lib/ar/repositories/roles/finder_spec.rb +43 -0
- data/spec/lib/ar/repositories/roles/remover_spec.rb +31 -0
- data/spec/lib/ar/requests/profiles/create_request_spec.rb +51 -0
- data/spec/lib/ar/requests/profiles/remove_request_spec.rb +36 -0
- data/spec/lib/ar/requests/resources/create_request_spec.rb +107 -0
- data/spec/lib/ar/requests/roles/create_request_spec.rb +40 -0
- data/spec/lib/ar/requests/roles/remove_request_spec.rb +23 -0
- data/spec/lib/ar/requests/roles/update_request_spec.rb +50 -0
- data/spec/lib/ar/services/actions/create/action_creator_spec.rb +88 -0
- data/spec/lib/ar/services/actions/remove/action_remover_spec.rb +36 -0
- data/spec/lib/ar/services/base_spec.rb +94 -0
- data/spec/lib/ar/services/profiles/create/profile_creator_spec.rb +68 -0
- data/spec/lib/ar/services/profiles/profile_manager_creator_spec.rb +31 -0
- data/spec/lib/ar/services/profiles/profile_manager_remover_spec.rb +44 -0
- data/spec/lib/ar/services/profiles/profile_manager_updater_spec.rb +31 -0
- data/spec/lib/ar/services/profiles/remove/profile_remover_spec.rb +45 -0
- data/spec/lib/ar/services/profiles/update/profile_updater_spec.rb +68 -0
- data/spec/lib/ar/services/resources/create/resource_creator_spec.rb +87 -0
- data/spec/lib/ar/services/resources/remove/resource_remover_spec.rb +50 -0
- data/spec/lib/ar/services/resources/resource_manager_creator_spec.rb +71 -0
- data/spec/lib/ar/services/roles/create/role_creator_spec.rb +68 -0
- data/spec/lib/ar/services/roles/remove/role_remover_spec.rb +50 -0
- data/spec/lib/ar/services/roles/role_manager_creator_spec.rb +31 -0
- data/spec/lib/ar/services/roles/role_manager_remover_spec.rb +32 -0
- data/spec/lib/ar/services/roles/role_manager_updater_spec.rb +31 -0
- data/spec/lib/ar/services/roles/update/role_updater_spec.rb +68 -0
- data/spec/lib/ar/services/verifier_spec.rb +44 -0
- data/spec/lib/ar/validators/action_validator_spec.rb +15 -0
- data/spec/lib/ar/validators/profile_validator_spec.rb +16 -0
- data/spec/lib/ar/validators/resource_validator_spec.rb +15 -0
- data/spec/lib/ar/validators/role_validator_spec.rb +16 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/repositories/test_repository.rb +2 -0
- data/spec/support/schema.rb +58 -0
- metadata +380 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
module Arpa
|
2
|
+
class ProfilesController < ApplicationController
|
3
|
+
before_action :set_profile, only: [:show, :edit, :update, :remove]
|
4
|
+
|
5
|
+
# GET /profiles
|
6
|
+
def index
|
7
|
+
@profiles = profile_finder.all
|
8
|
+
respond_with(@profiles)
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /profiles/1
|
12
|
+
def show
|
13
|
+
respond_with(@profile)
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /profiles/new
|
17
|
+
def new
|
18
|
+
@profile = Arpa::Entities::Profile.new
|
19
|
+
all_roles
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /profiles/1/edit
|
23
|
+
def edit
|
24
|
+
all_roles
|
25
|
+
end
|
26
|
+
|
27
|
+
# POST /profiles
|
28
|
+
def create
|
29
|
+
profile_creator.create({profile: profile_params}, {
|
30
|
+
success: -> (profile) {
|
31
|
+
redirect_to profile_path(profile.id), notice: I18n.t('flash.actions.create_profile.notice')
|
32
|
+
},
|
33
|
+
fail: -> (error) {
|
34
|
+
@profile = Arpa::Entities::Profile.new(profile_params)
|
35
|
+
@error = error
|
36
|
+
all_roles
|
37
|
+
render :new
|
38
|
+
}
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
# PATCH/PUT /profiles/1
|
43
|
+
def update
|
44
|
+
profile_updater.update({profile: profile_params}, {
|
45
|
+
success: -> (profile) {
|
46
|
+
redirect_to profile_path(profile.id), notice: I18n.t('flash.actions.update_profile.notice')
|
47
|
+
},
|
48
|
+
fail: -> (error) {
|
49
|
+
@profile = Arpa::Entities::Profile.new(profile_params)
|
50
|
+
@error = error
|
51
|
+
all_roles
|
52
|
+
render :edit
|
53
|
+
}
|
54
|
+
})
|
55
|
+
end
|
56
|
+
|
57
|
+
# DELETE /profiles/1
|
58
|
+
def remove
|
59
|
+
profile_remover.remove({profile: @profile}, {
|
60
|
+
success: -> (profile) {
|
61
|
+
redirect_to profiles_path, notice: I18n.t('flash.actions.remove_profile.notice')
|
62
|
+
},
|
63
|
+
fail: -> (error) {
|
64
|
+
redirect_to profiles_path, notice: I18n.t('flash.actions.remove_profile.alert')
|
65
|
+
}
|
66
|
+
})
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def profile_creator
|
73
|
+
@profile_creator ||= Arpa::Services::Profiles::ProfileManagerCreator.new
|
74
|
+
end
|
75
|
+
|
76
|
+
def profile_updater
|
77
|
+
@profile_updater ||= Arpa::Services::Profiles::ProfileManagerUpdater.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def profile_remover
|
81
|
+
@profile_remover ||= Arpa::Services::Profiles::ProfileManagerRemover.new
|
82
|
+
end
|
83
|
+
|
84
|
+
def profile_finder
|
85
|
+
@profile_finder ||= Arpa::Repositories::Profiles::Finder.new
|
86
|
+
end
|
87
|
+
|
88
|
+
def role_finder
|
89
|
+
@role_finder ||= Arpa::Repositories::Roles::Finder.new
|
90
|
+
end
|
91
|
+
|
92
|
+
def all_roles
|
93
|
+
@roles = role_finder.all
|
94
|
+
end
|
95
|
+
|
96
|
+
def set_profile
|
97
|
+
@profile = profile_finder.find(params[:id])
|
98
|
+
end
|
99
|
+
|
100
|
+
def profile_params
|
101
|
+
params.require(:profile).
|
102
|
+
permit(:id, :name, :description, role_ids: [])
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Arpa
|
2
|
+
class ResourcesController < ApplicationController
|
3
|
+
before_action :set_resource, only: [:show]
|
4
|
+
|
5
|
+
# GET /resources
|
6
|
+
def index
|
7
|
+
@resources = resource_finder.all
|
8
|
+
respond_with(@resources)
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /resources/1
|
12
|
+
def show
|
13
|
+
respond_with(@resource)
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /generate_resources_and_actions
|
17
|
+
def generate_resources_and_actions
|
18
|
+
Rails.application.eager_load!
|
19
|
+
|
20
|
+
resource_creator.create({resourceables: ApplicationController.descendants}, {
|
21
|
+
success: -> (resource) {
|
22
|
+
flash[:notice] = I18n.t('flash.actions.generate_resources_and_actions.notice')
|
23
|
+
},
|
24
|
+
fail: -> (error) {
|
25
|
+
flash[:alert] = I18n.t('flash.actions.generate_resources_and_actions.alert')
|
26
|
+
}
|
27
|
+
})
|
28
|
+
|
29
|
+
redirect_to resources_path
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def resource_creator
|
35
|
+
@resource_creator ||= Arpa::Services::Resources::ResourceManagerCreator.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def resource_finder
|
39
|
+
@resource_finder ||= Arpa::Repositories::Resources::Finder.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_resource
|
43
|
+
@resource = resource_finder.find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Arpa
|
2
|
+
class RolesController < ApplicationController
|
3
|
+
before_action :set_role, only: [:show, :edit, :update, :remove]
|
4
|
+
|
5
|
+
# GET /roles
|
6
|
+
def index
|
7
|
+
@roles = role_finder.all
|
8
|
+
respond_with(@roles)
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /roles/1
|
12
|
+
def show
|
13
|
+
respond_with(@role)
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /roles/new
|
17
|
+
def new
|
18
|
+
@role = Arpa::Entities::Role.new
|
19
|
+
all_resources
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /roles/1/edit
|
23
|
+
def edit
|
24
|
+
all_resources
|
25
|
+
end
|
26
|
+
|
27
|
+
# POST /roles
|
28
|
+
def create
|
29
|
+
role_creator.create({role: role_params}, {
|
30
|
+
success: -> (role) {
|
31
|
+
redirect_to role_path(role.id), notice: I18n.t('flash.actions.create_role.notice')
|
32
|
+
},
|
33
|
+
fail: -> (error) {
|
34
|
+
@role = Arpa::Entities::Role.new(role_params)
|
35
|
+
@error = error
|
36
|
+
all_resources
|
37
|
+
render :new
|
38
|
+
}
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
# PATCH/PUT /roles/1
|
43
|
+
def update
|
44
|
+
role_updater.update({role: role_params}, {
|
45
|
+
success: -> (role) {
|
46
|
+
redirect_to role_path(role.id), notice: I18n.t('flash.actions.update_role.notice')
|
47
|
+
},
|
48
|
+
fail: -> (error) {
|
49
|
+
@role = Arpa::Entities::Role.new(role_params)
|
50
|
+
@error = error
|
51
|
+
all_resources
|
52
|
+
render :edit
|
53
|
+
}
|
54
|
+
})
|
55
|
+
end
|
56
|
+
|
57
|
+
# DELETE /roles/1
|
58
|
+
def remove
|
59
|
+
role_remover.remove({role: @role}, {
|
60
|
+
success: -> (role) {
|
61
|
+
redirect_to roles_path, notice: I18n.t('flash.actions.remove_role.notice')
|
62
|
+
},
|
63
|
+
fail: -> (error) {
|
64
|
+
redirect_to roles_path, notice: I18n.t('flash.actions.remove_role.alert')
|
65
|
+
}
|
66
|
+
})
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def role_creator
|
73
|
+
@role_creator ||= Arpa::Services::Roles::RoleManagerCreator.new
|
74
|
+
end
|
75
|
+
|
76
|
+
def role_updater
|
77
|
+
@role_updater ||= Arpa::Services::Roles::RoleManagerUpdater.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def role_remover
|
81
|
+
@role_remover ||= Arpa::Services::Roles::RoleManagerRemover.new
|
82
|
+
end
|
83
|
+
|
84
|
+
def role_finder
|
85
|
+
@role_finder ||= Arpa::Repositories::Roles::Finder.new
|
86
|
+
end
|
87
|
+
|
88
|
+
def resource_finder
|
89
|
+
@resource_finder ||= Arpa::Repositories::Resources::Finder.new
|
90
|
+
end
|
91
|
+
|
92
|
+
def all_resources
|
93
|
+
@resources = resource_finder.all
|
94
|
+
end
|
95
|
+
|
96
|
+
def set_role
|
97
|
+
@role = role_finder.find(params[:id])
|
98
|
+
end
|
99
|
+
|
100
|
+
def role_params
|
101
|
+
params.require(:role).
|
102
|
+
permit(:id, :name, :description, action_ids: [])
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Arpa
|
2
|
+
module DataMappers
|
3
|
+
class ActionMapper < Base
|
4
|
+
entity_class 'Arpa::Entities::Action'
|
5
|
+
repository_class 'Arpa::Repositories::Actions::RepositoryAction'
|
6
|
+
|
7
|
+
attrs_to_entity :id, :resource_id, :name, :created_at, :updated_at,
|
8
|
+
resource: {mapper: 'Arpa::DataMappers::ResourceMapper'}
|
9
|
+
attrs_to_record :id, :resource_id, :name, :created_at, :updated_at
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Arpa
|
2
|
+
module DataMappers
|
3
|
+
class Base
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
def map_to_record(entity, options={})
|
7
|
+
options[:map_association_to] ||= :map_to_record
|
8
|
+
attrs_to_record = self.class._attrs_to_record
|
9
|
+
attributes = attributes_from(entity, attrs_to_record, options)
|
10
|
+
self.class._repository_class.new(attributes)
|
11
|
+
end
|
12
|
+
|
13
|
+
def map_to_entity(record, options={})
|
14
|
+
options[:map_association_to] ||= :map_to_entity
|
15
|
+
attrs_to_entity = self.class._attrs_to_entity
|
16
|
+
attributes = attributes_from(record, attrs_to_entity, options)
|
17
|
+
self.class._entity_class.new(attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def attributes_from(object, attrs_to_map, options={})
|
23
|
+
options[:map_association_to] = options.fetch(:map_association_to, :map_to_entity)
|
24
|
+
options[:map_association] = options.fetch(:map_association, true)
|
25
|
+
|
26
|
+
attrs_to_map ||= self.class._attributes_to_map
|
27
|
+
|
28
|
+
begin
|
29
|
+
build_hash_attributes(attrs_to_map, object, options)
|
30
|
+
rescue => e
|
31
|
+
raise StandardError, "#{self.class} -> #{e.message}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_hash_attributes(attributes_to_map, object, options)
|
36
|
+
builder_attribute = build_hash_attribute.curry.(object, options)
|
37
|
+
|
38
|
+
attributes_to_map.collect { |attr_key|
|
39
|
+
builder_attribute.(attr_key)
|
40
|
+
}.reduce({}, :merge)
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_hash_attribute
|
44
|
+
-> (object, options, attr_key) {
|
45
|
+
if attr_key.kind_of?(Hash)
|
46
|
+
key = attr_key.keys.first
|
47
|
+
value = association_value(object, attr_key, options)
|
48
|
+
else
|
49
|
+
key = attr_key
|
50
|
+
value = object.send(attr_key)
|
51
|
+
end
|
52
|
+
{:"#{key}" => value}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def association_value(object, attr_key, options)
|
57
|
+
key = attr_key.keys.first
|
58
|
+
object_value = object.send(key)
|
59
|
+
|
60
|
+
return object_value unless options[:map_association]
|
61
|
+
|
62
|
+
mapper = attr_key[key][:mapper].constantize.instance
|
63
|
+
|
64
|
+
if object_value.try(:size)
|
65
|
+
object_value.collect do |obj|
|
66
|
+
mapper.send(options[:map_association_to], obj, {map_association: false})
|
67
|
+
end
|
68
|
+
else
|
69
|
+
mapper.send(options[:map_association_to], object_value, {map_association: false})
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# --- Classes Methods ---
|
74
|
+
|
75
|
+
def self.entity_class(entity_class)
|
76
|
+
@entity_class = entity_class
|
77
|
+
end
|
78
|
+
|
79
|
+
def self._entity_class
|
80
|
+
@entity_class.constantize
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.repository_class(repository_class)
|
84
|
+
@repository_class = repository_class
|
85
|
+
end
|
86
|
+
|
87
|
+
def self._repository_class
|
88
|
+
@repository_class.constantize
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.attributes_to_map(*attrs)
|
92
|
+
@attributes_to_map = attrs
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.attrs_to_record(*attrs)
|
96
|
+
@attrs_to_record = attrs
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.attrs_to_entity(*attrs)
|
100
|
+
@attrs_to_entity = attrs
|
101
|
+
end
|
102
|
+
|
103
|
+
def self._attributes_to_map
|
104
|
+
@attributes_to_map
|
105
|
+
end
|
106
|
+
|
107
|
+
def self._attrs_to_record
|
108
|
+
@attrs_to_record
|
109
|
+
end
|
110
|
+
|
111
|
+
def self._attrs_to_entity
|
112
|
+
@attrs_to_entity
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Arpa
|
2
|
+
module DataMappers
|
3
|
+
class ProfileMapper < Base
|
4
|
+
entity_class 'Arpa::Entities::Profile'
|
5
|
+
repository_class 'Arpa::Repositories::Profiles::RepositoryProfile'
|
6
|
+
|
7
|
+
attrs_to_entity :id, :name, :description, :role_ids, :removed, :created_at, :updated_at,
|
8
|
+
roles: {mapper: 'Arpa::DataMappers::RoleMapper'}
|
9
|
+
|
10
|
+
attrs_to_record :id, :name, :description, :role_ids, :removed, :created_at, :updated_at
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Arpa
|
2
|
+
module DataMappers
|
3
|
+
class ResourceMapper < Base
|
4
|
+
entity_class 'Arpa::Entities::Resource'
|
5
|
+
repository_class 'Arpa::Repositories::Resources::RepositoryResource'
|
6
|
+
|
7
|
+
attributes_to_map :id, :name, :full_name,
|
8
|
+
actions: {mapper: 'Arpa::DataMappers::ActionMapper'}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Arpa
|
2
|
+
module DataMappers
|
3
|
+
class RoleMapper < Base
|
4
|
+
entity_class 'Arpa::Entities::Role'
|
5
|
+
repository_class 'Arpa::Repositories::Roles::RepositoryRole'
|
6
|
+
|
7
|
+
attrs_to_entity :id, :name, :description, :action_ids, :removed, :created_at, :updated_at,
|
8
|
+
{actions: {mapper: 'Arpa::DataMappers::ActionMapper'} },
|
9
|
+
{profiles: {mapper: 'Arpa::DataMappers::ProfileMapper'}}
|
10
|
+
|
11
|
+
attrs_to_record :id, :name, :description, :action_ids, :removed, :created_at, :updated_at
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Arpa
|
2
|
+
module Entities
|
3
|
+
class Action
|
4
|
+
|
5
|
+
attr_reader :id, :resource_id, :resource, :name, :created_at, :updated_at
|
6
|
+
|
7
|
+
def initialize(attrs = {})
|
8
|
+
attrs = attrs.with_indifferent_access
|
9
|
+
|
10
|
+
@id = attrs[:id]
|
11
|
+
@resource_id = attrs[:resource_id]
|
12
|
+
@resource = attrs[:resource]
|
13
|
+
@name = attrs[:name]
|
14
|
+
@created_at = attrs[:created_at]
|
15
|
+
@updated_at = attrs[:updated_at]
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
I18n.t(name.to_sym, scope: "entities.resources.#{resource.name}.actions.description")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|