arpa 0.0.2
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 +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,35 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Entities
|
|
3
|
+
class Permissions
|
|
4
|
+
|
|
5
|
+
attr_reader :permissions
|
|
6
|
+
|
|
7
|
+
def initialize(resources)
|
|
8
|
+
@resources = resources
|
|
9
|
+
@permissions = Array.new
|
|
10
|
+
build_permissions
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def has_permission?(resource_name, action_name)
|
|
14
|
+
hash_permission = build_hash_permission(resource_name, action_name)
|
|
15
|
+
permissions.include?(hash_permission)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
def build_permissions
|
|
20
|
+
@resources.each do |resource|
|
|
21
|
+
resource.actions.collect do |action|
|
|
22
|
+
hash_permission = build_hash_permission(resource.name, action.name)
|
|
23
|
+
@permissions << hash_permission unless permissions.include?(hash_permission)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def build_hash_permission(resource_name, action_name)
|
|
29
|
+
{'resource' => resource_name, 'action' => action_name }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Entities
|
|
3
|
+
class Profile
|
|
4
|
+
|
|
5
|
+
attr_reader :id, :name, :description, :role_ids, :roles, :created_at, :updated_at, :removed
|
|
6
|
+
|
|
7
|
+
def initialize(attrs = {})
|
|
8
|
+
attrs = attrs.with_indifferent_access
|
|
9
|
+
|
|
10
|
+
@id = attrs[:id]
|
|
11
|
+
@name = attrs[:name]
|
|
12
|
+
@description = attrs[:name]
|
|
13
|
+
@role_ids = attrs[:role_ids] || []
|
|
14
|
+
@roles = attrs[:roles] || []
|
|
15
|
+
@created_at = attrs[:created_at]
|
|
16
|
+
@updated_at = attrs[:updated_at]
|
|
17
|
+
@removed = attrs[:removed] || false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Entities
|
|
3
|
+
class Resource
|
|
4
|
+
|
|
5
|
+
attr_reader :id, :full_name, :name, :created_at, :updated_at, :actions
|
|
6
|
+
|
|
7
|
+
def initialize(attrs = {})
|
|
8
|
+
attrs = attrs.with_indifferent_access
|
|
9
|
+
|
|
10
|
+
@id = attrs[:id]
|
|
11
|
+
@full_name = attrs[:full_name]
|
|
12
|
+
@name = attrs[:name]
|
|
13
|
+
@created_at = attrs[:created_at]
|
|
14
|
+
@updated_at = attrs[:updated_at]
|
|
15
|
+
@actions = attrs[:actions] || []
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def build_correct_name
|
|
19
|
+
name = remove_word(full_name)
|
|
20
|
+
@name = adjust_name(name)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def adjust_name(name)
|
|
26
|
+
parts_of_name = name.split '::'
|
|
27
|
+
refactored_name = String.new
|
|
28
|
+
|
|
29
|
+
parts_of_name.each_with_index do |part, index|
|
|
30
|
+
refactored_name << '/' if index > 0
|
|
31
|
+
refactored_name << change_to_snake_case(part)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
refactored_name
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def remove_word(word, word_to_delete = 'Controller')
|
|
38
|
+
word = "#{word}del" if word.include?(word_to_delete)
|
|
39
|
+
word.slice!("#{word_to_delete}del")
|
|
40
|
+
word
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def change_to_snake_case(name)
|
|
44
|
+
parts_of_name = name.split(/(?=[A-Z])/) # Split at CamelCase
|
|
45
|
+
refactored_name = String.new
|
|
46
|
+
|
|
47
|
+
parts_of_name.each_with_index do |part, index|
|
|
48
|
+
part.downcase!
|
|
49
|
+
refactored_name << '_' if index > 0
|
|
50
|
+
refactored_name << part
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
refactored_name
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Entities
|
|
3
|
+
class Role
|
|
4
|
+
|
|
5
|
+
attr_reader :id, :name, :description, :created_at, :updated_at, :removed,
|
|
6
|
+
:action_ids, :actions, :profiles
|
|
7
|
+
|
|
8
|
+
def initialize(attrs = {})
|
|
9
|
+
attrs = attrs.with_indifferent_access
|
|
10
|
+
|
|
11
|
+
@id = attrs[:id]
|
|
12
|
+
@name = attrs[:name]
|
|
13
|
+
@description = attrs[:description]
|
|
14
|
+
@action_ids = attrs[:action_ids] || []
|
|
15
|
+
@actions = attrs[:actions] || []
|
|
16
|
+
@profiles = attrs[:profiles] || []
|
|
17
|
+
@created_at = attrs[:created_at]
|
|
18
|
+
@updated_at = attrs[:updated_at]
|
|
19
|
+
@removed = attrs[:removed] || false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def has_profile?
|
|
23
|
+
profiles.present?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Actions
|
|
4
|
+
class Creator
|
|
5
|
+
include Arpa::Repositories::Registrator
|
|
6
|
+
|
|
7
|
+
def mapper_instance
|
|
8
|
+
Arpa::DataMappers::ActionMapper.instance
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def repository_class
|
|
12
|
+
RepositoryAction
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Actions
|
|
4
|
+
class Finder
|
|
5
|
+
include Arpa::Repositories::Base
|
|
6
|
+
|
|
7
|
+
def by_name_and_resource(name, resource_id)
|
|
8
|
+
record = repository_class.where(name: name, repository_resource_id: resource_id).first
|
|
9
|
+
mapper_instance.map_to_entity(record) if record
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def mapper_instance
|
|
13
|
+
Arpa::DataMappers::ActionMapper.instance
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def repository_class
|
|
17
|
+
RepositoryAction
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Actions
|
|
4
|
+
class Remover
|
|
5
|
+
include Arpa::Repositories::Base
|
|
6
|
+
|
|
7
|
+
def destroy(entity)
|
|
8
|
+
repository_class.destroy(entity.id)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def mapper_instance
|
|
12
|
+
Arpa::DataMappers::ActionMapper.instance
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def repository_class
|
|
16
|
+
RepositoryAction
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Actions
|
|
4
|
+
class RepositoryAction < ActiveRecord::Base
|
|
5
|
+
default_scope {order(name: :asc)}
|
|
6
|
+
|
|
7
|
+
alias_attribute :resource_id, :repository_resource_id
|
|
8
|
+
belongs_to :resource, foreign_key: 'repository_resource_id', class_name: 'Arpa::Repositories::Resources::RepositoryResource'
|
|
9
|
+
|
|
10
|
+
has_and_belongs_to_many :roles, class_name: 'Arpa::Repositories::Roles::RepositoryRole'
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Base
|
|
4
|
+
|
|
5
|
+
def mapper_instance
|
|
6
|
+
raise NotImplementedError, "This #{self.class} cannot respond :mapper_instance"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def repository_class
|
|
10
|
+
raise NotImplementedError, "This #{self.class} cannot respond :repository_class"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Profiles
|
|
4
|
+
class Creator
|
|
5
|
+
include Arpa::Repositories::Registrator
|
|
6
|
+
|
|
7
|
+
def mapper_instance
|
|
8
|
+
Arpa::DataMappers::ProfileMapper.instance
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def repository_class
|
|
12
|
+
RepositoryProfile
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Profiles
|
|
4
|
+
class Finder
|
|
5
|
+
include Arpa::Repositories::Base
|
|
6
|
+
|
|
7
|
+
def find(id)
|
|
8
|
+
record = repository_class.find(id)
|
|
9
|
+
mapper_instance.map_to_entity(record)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all
|
|
13
|
+
repository_class.all.collect do |record|
|
|
14
|
+
mapper_instance.map_to_entity(record)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def mapper_instance
|
|
19
|
+
Arpa::DataMappers::ProfileMapper.instance
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def repository_class
|
|
23
|
+
RepositoryProfile
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Profiles
|
|
4
|
+
class Remover
|
|
5
|
+
include Arpa::Repositories::Base
|
|
6
|
+
|
|
7
|
+
def destroy(entity)
|
|
8
|
+
repository_class.destroy(entity.id)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def disable(entity)
|
|
12
|
+
record = mapper_instance.map_to_record(entity)
|
|
13
|
+
repository_class.update(record.id, removed: true)
|
|
14
|
+
record.reload
|
|
15
|
+
mapper_instance.map_to_entity(record)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def mapper_instance
|
|
19
|
+
Arpa::DataMappers::ProfileMapper.instance
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def repository_class
|
|
23
|
+
RepositoryProfile
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Profiles
|
|
4
|
+
class RepositoryProfile < ActiveRecord::Base
|
|
5
|
+
default_scope {where(removed: false).order(name: :asc)}
|
|
6
|
+
|
|
7
|
+
has_and_belongs_to_many :roles, class_name: 'Arpa::Repositories::Roles::RepositoryRole'
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Profiles
|
|
4
|
+
class Updater
|
|
5
|
+
include Arpa::Repositories::Registrator
|
|
6
|
+
|
|
7
|
+
def post_update(entity, record)
|
|
8
|
+
record.role_ids = entity.role_ids
|
|
9
|
+
record.save!
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def mapper_instance
|
|
13
|
+
Arpa::DataMappers::ProfileMapper.instance
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def repository_class
|
|
17
|
+
RepositoryProfile
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Registrator
|
|
4
|
+
include Base
|
|
5
|
+
|
|
6
|
+
def create(entity)
|
|
7
|
+
save(entity) do |record|
|
|
8
|
+
record.save!
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update(entity)
|
|
13
|
+
save(entity) do |record|
|
|
14
|
+
record.updated_at = Time.new.utc
|
|
15
|
+
attributes = record.attributes.except('id', 'created_at')
|
|
16
|
+
|
|
17
|
+
repository_class.update(entity.id, attributes)
|
|
18
|
+
|
|
19
|
+
record.reload
|
|
20
|
+
record.reload
|
|
21
|
+
post_update(entity, record)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def save(entity, &block)
|
|
28
|
+
record = mapper_instance.map_to_record( entity)
|
|
29
|
+
begin
|
|
30
|
+
block.call(record)
|
|
31
|
+
rescue ActiveRecord::RecordInvalid => invalid
|
|
32
|
+
raise Arpa::Exceptions::RecordInvalid.new(message: invalid.message, errors: invalid.record.errors)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
mapper_instance.map_to_entity(record)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def post_update(entity, record)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Arpa
|
|
2
|
+
module Repositories
|
|
3
|
+
module Resources
|
|
4
|
+
class Creator
|
|
5
|
+
include Arpa::Repositories::Registrator
|
|
6
|
+
|
|
7
|
+
def mapper_instance
|
|
8
|
+
Arpa::DataMappers::ResourceMapper.instance
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def repository_class
|
|
12
|
+
RepositoryResource
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|