arpa 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +17 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +4 -0
  6. data/README.md +4 -4
  7. data/Rakefile +1 -2
  8. data/arpa.gemspec +17 -18
  9. data/lib/arpa.rb +65 -67
  10. data/lib/arpa/additions/resource.rb +0 -2
  11. data/lib/arpa/data_mappers/action_mapper.rb +1 -2
  12. data/lib/arpa/data_mappers/base.rb +15 -16
  13. data/lib/arpa/data_mappers/profile_mapper.rb +3 -4
  14. data/lib/arpa/data_mappers/resource_mapper.rb +1 -1
  15. data/lib/arpa/data_mappers/role_mapper.rb +2 -2
  16. data/lib/arpa/entities/action.rb +0 -2
  17. data/lib/arpa/entities/profile.rb +2 -3
  18. data/lib/arpa/entities/resource.rb +4 -6
  19. data/lib/arpa/entities/role.rb +2 -3
  20. data/lib/arpa/exceptions/record_invalid.rb +0 -1
  21. data/lib/arpa/repositories/actions/creator.rb +0 -1
  22. data/lib/arpa/repositories/actions/finder.rb +5 -6
  23. data/lib/arpa/repositories/actions/remover.rb +0 -1
  24. data/lib/arpa/repositories/actions/repository_action.rb +1 -2
  25. data/lib/arpa/repositories/base.rb +0 -2
  26. data/lib/arpa/repositories/profiles/creator.rb +0 -1
  27. data/lib/arpa/repositories/profiles/finder.rb +2 -3
  28. data/lib/arpa/repositories/profiles/remover.rb +0 -1
  29. data/lib/arpa/repositories/profiles/repository_profile.rb +1 -2
  30. data/lib/arpa/repositories/profiles/updater.rb +0 -1
  31. data/lib/arpa/repositories/registrator.rb +5 -10
  32. data/lib/arpa/repositories/resources/creator.rb +0 -1
  33. data/lib/arpa/repositories/resources/finder.rb +0 -1
  34. data/lib/arpa/repositories/resources/remover.rb +0 -1
  35. data/lib/arpa/repositories/resources/repository_resource.rb +1 -2
  36. data/lib/arpa/repositories/roles/creator.rb +0 -1
  37. data/lib/arpa/repositories/roles/finder.rb +0 -1
  38. data/lib/arpa/repositories/roles/remover.rb +0 -1
  39. data/lib/arpa/repositories/roles/repository_role.rb +1 -2
  40. data/lib/arpa/repositories/roles/updater.rb +0 -1
  41. data/lib/arpa/services/actions/create/action_creator.rb +1 -3
  42. data/lib/arpa/services/actions/remove/action_remover.rb +0 -2
  43. data/lib/arpa/services/base.rb +6 -10
  44. data/lib/arpa/services/profiles/create/profile_creator.rb +0 -2
  45. data/lib/arpa/services/profiles/profile_manager_creator.rb +0 -1
  46. data/lib/arpa/services/profiles/profile_manager_remover.rb +0 -1
  47. data/lib/arpa/services/profiles/profile_manager_updater.rb +0 -1
  48. data/lib/arpa/services/profiles/remove/profile_remover.rb +0 -2
  49. data/lib/arpa/services/profiles/update/profile_updater.rb +0 -2
  50. data/lib/arpa/services/resources/create/resource_creator.rb +0 -2
  51. data/lib/arpa/services/resources/remove/resource_remover.rb +1 -4
  52. data/lib/arpa/services/resources/resource_manager_creator.rb +1 -2
  53. data/lib/arpa/services/roles/create/role_creator.rb +0 -3
  54. data/lib/arpa/services/roles/remove/role_remover.rb +0 -2
  55. data/lib/arpa/services/roles/role_manager_creator.rb +0 -2
  56. data/lib/arpa/services/roles/role_manager_remover.rb +0 -1
  57. data/lib/arpa/services/roles/role_manager_updater.rb +0 -1
  58. data/lib/arpa/services/roles/update/role_updater.rb +0 -2
  59. data/lib/arpa/services/verifier.rb +0 -1
  60. data/lib/arpa/validators/action_validator.rb +0 -1
  61. data/lib/arpa/validators/profile_validator.rb +0 -1
  62. data/lib/arpa/validators/resource_validator.rb +0 -1
  63. data/lib/arpa/validators/role_validator.rb +0 -2
  64. data/lib/arpa/version.rb +1 -1
  65. data/lib/generators/arpa/controllers_generator.rb +21 -22
  66. data/lib/generators/arpa/install_generator.rb +5 -6
  67. data/lib/generators/arpa/templates/controllers/profiles_controller.rb +31 -37
  68. data/lib/generators/arpa/templates/controllers/resources_controller.rb +20 -11
  69. data/lib/generators/arpa/templates/controllers/roles_controller.rb +31 -37
  70. data/lib/generators/arpa/templates/migration.rb +1 -1
  71. data/spec/factories/repository_actions.rb +4 -5
  72. data/spec/factories/repository_profiles.rb +4 -5
  73. data/spec/factories/repository_resources.rb +1 -3
  74. data/spec/factories/repository_roles.rb +2 -3
  75. data/spec/factories/repository_test.rb +1 -1
  76. data/spec/lib/arpa/additions/resource_spec.rb +8 -6
  77. data/spec/lib/arpa/data_mappers/action_mapper_spec.rb +1 -3
  78. data/spec/lib/arpa/data_mappers/base_spec.rb +0 -2
  79. data/spec/lib/arpa/data_mappers/profile_mapper_spec.rb +1 -3
  80. data/spec/lib/arpa/data_mappers/resource_mapper_spec.rb +1 -3
  81. data/spec/lib/arpa/data_mappers/role_mapper_spec.rb +1 -3
  82. data/spec/lib/arpa/entities/action_spec.rb +3 -6
  83. data/spec/lib/arpa/entities/profile_spec.rb +1 -7
  84. data/spec/lib/arpa/entities/resource_spec.rb +1 -9
  85. data/spec/lib/arpa/entities/role_spec.rb +1 -7
  86. data/spec/lib/arpa/repositories/actions/finder_spec.rb +1 -8
  87. data/spec/lib/arpa/repositories/base_spec.rb +1 -9
  88. data/spec/lib/arpa/repositories/profiles/finder_spec.rb +0 -6
  89. data/spec/lib/arpa/repositories/profiles/remover_spec.rb +0 -4
  90. data/spec/lib/arpa/repositories/resources/finder_spec.rb +0 -8
  91. data/spec/lib/arpa/repositories/resources/remover_spec.rb +0 -4
  92. data/spec/lib/arpa/repositories/roles/finder_spec.rb +0 -4
  93. data/spec/lib/arpa/repositories/roles/remover_spec.rb +0 -4
  94. data/spec/lib/arpa/requests/profiles/create_request_spec.rb +10 -12
  95. data/spec/lib/arpa/requests/profiles/remove_request_spec.rb +4 -9
  96. data/spec/lib/arpa/requests/resources/create_request_spec.rb +18 -21
  97. data/spec/lib/arpa/requests/roles/create_request_spec.rb +7 -9
  98. data/spec/lib/arpa/requests/roles/remove_request_spec.rb +3 -6
  99. data/spec/lib/arpa/requests/roles/update_request_spec.rb +7 -9
  100. data/spec/lib/arpa/services/actions/create/action_creator_spec.rb +5 -14
  101. data/spec/lib/arpa/services/actions/remove/action_remover_spec.rb +3 -6
  102. data/spec/lib/arpa/services/base_spec.rb +8 -15
  103. data/spec/lib/arpa/services/profiles/create/profile_creator_spec.rb +0 -7
  104. data/spec/lib/arpa/services/profiles/profile_manager_creator_spec.rb +2 -4
  105. data/spec/lib/arpa/services/profiles/profile_manager_remover_spec.rb +3 -6
  106. data/spec/lib/arpa/services/profiles/profile_manager_updater_spec.rb +2 -4
  107. data/spec/lib/arpa/services/profiles/remove/profile_remover_spec.rb +0 -5
  108. data/spec/lib/arpa/services/profiles/update/profile_updater_spec.rb +0 -7
  109. data/spec/lib/arpa/services/resources/create/resource_creator_spec.rb +1 -7
  110. data/spec/lib/arpa/services/resources/remove/resource_remover_spec.rb +2 -6
  111. data/spec/lib/arpa/services/resources/resource_manager_creator_spec.rb +5 -7
  112. data/spec/lib/arpa/services/roles/create/role_creator_spec.rb +0 -7
  113. data/spec/lib/arpa/services/roles/remove/role_remover_spec.rb +1 -8
  114. data/spec/lib/arpa/services/roles/role_manager_creator_spec.rb +2 -4
  115. data/spec/lib/arpa/services/roles/role_manager_remover_spec.rb +2 -4
  116. data/spec/lib/arpa/services/roles/role_manager_updater_spec.rb +2 -4
  117. data/spec/lib/arpa/services/roles/update/role_updater_spec.rb +0 -7
  118. data/spec/lib/arpa/services/verifier_spec.rb +3 -6
  119. data/spec/lib/arpa/validators/action_validator_spec.rb +0 -1
  120. data/spec/lib/arpa/validators/profile_validator_spec.rb +1 -2
  121. data/spec/lib/arpa/validators/resource_validator_spec.rb +0 -1
  122. data/spec/lib/arpa/validators/role_validator_spec.rb +1 -2
  123. data/spec/spec_helper.rb +4 -6
  124. data/spec/support/schema.rb +9 -10
  125. metadata +40 -36
@@ -1,9 +1,8 @@
1
1
  module Arpa
2
2
  module Entities
3
3
  class Profile
4
-
5
4
  attr_reader :id, :name, :description, :role_ids, :roles, :entity_id, :entity_class,
6
- :created_at, :updated_at, :removed
5
+ :created_at, :updated_at, :removed
7
6
 
8
7
  def initialize(attrs = {})
9
8
  attrs = attrs.with_indifferent_access
@@ -21,11 +20,11 @@ module Arpa
21
20
  end
22
21
 
23
22
  private
23
+
24
24
  def default_value_to_nil_or_empty(attr_value, default_value)
25
25
  return attr_value if attr_value.present?
26
26
  default_value
27
27
  end
28
-
29
28
  end
30
29
  end
31
30
  end
@@ -1,7 +1,6 @@
1
1
  module Arpa
2
2
  module Entities
3
3
  class Resource
4
-
5
4
  attr_reader :id, :full_name, :name, :created_at, :updated_at, :actions
6
5
 
7
6
  def initialize(attrs = {})
@@ -24,10 +23,10 @@ module Arpa
24
23
 
25
24
  def adjust_name(name)
26
25
  parts_of_name = name.split '::'
27
- refactored_name = String.new
26
+ refactored_name = ''
28
27
 
29
28
  parts_of_name.each_with_index do |part, index|
30
- refactored_name << '/' if index > 0
29
+ refactored_name << '/' if index.positive?
31
30
  refactored_name << change_to_snake_case(part)
32
31
  end
33
32
 
@@ -42,17 +41,16 @@ module Arpa
42
41
 
43
42
  def change_to_snake_case(name)
44
43
  parts_of_name = name.split(/(?=[A-Z])/) # Split at CamelCase
45
- refactored_name = String.new
44
+ refactored_name = ''
46
45
 
47
46
  parts_of_name.each_with_index do |part, index|
48
47
  part.downcase!
49
- refactored_name << '_' if index > 0
48
+ refactored_name << '_' if index.positive?
50
49
  refactored_name << part
51
50
  end
52
51
 
53
52
  refactored_name
54
53
  end
55
-
56
54
  end
57
55
  end
58
56
  end
@@ -1,9 +1,8 @@
1
1
  module Arpa
2
2
  module Entities
3
3
  class Role
4
-
5
4
  attr_reader :id, :name, :description, :created_at, :updated_at, :removed,
6
- :action_ids, :actions, :profiles
5
+ :action_ids, :actions, :profiles
7
6
 
8
7
  def initialize(attrs = {})
9
8
  attrs = attrs.with_indifferent_access
@@ -24,11 +23,11 @@ module Arpa
24
23
  end
25
24
 
26
25
  private
26
+
27
27
  def default_value_to_nil_or_empty(attr_value, default_value)
28
28
  return attr_value if attr_value.present?
29
29
  default_value
30
30
  end
31
-
32
31
  end
33
32
  end
34
33
  end
@@ -7,7 +7,6 @@ module Arpa
7
7
  super(args[:message])
8
8
  @errors = args[:errors]
9
9
  end
10
-
11
10
  end
12
11
  end
13
12
  end
@@ -11,7 +11,6 @@ module Arpa
11
11
  def repository_class
12
12
  RepositoryAction
13
13
  end
14
-
15
14
  end
16
15
  end
17
16
  end
@@ -11,11 +11,11 @@ module Arpa
11
11
 
12
12
  def permission(resource_name, action_name, profile_ids)
13
13
  record = repository_class
14
- .distinct(true)
15
- .joins(:resource, roles: :profiles)
16
- .find_by(repository_profiles: {id: profile_ids},
17
- repository_resources: {name: resource_name},
18
- name: action_name)
14
+ .distinct(true)
15
+ .joins(:resource, roles: :profiles)
16
+ .find_by(repository_profiles: { id: profile_ids },
17
+ repository_resources: { name: resource_name },
18
+ name: action_name)
19
19
  mapper_instance.map_to_entity(record) if record
20
20
  end
21
21
 
@@ -26,7 +26,6 @@ module Arpa
26
26
  def repository_class
27
27
  RepositoryAction
28
28
  end
29
-
30
29
  end
31
30
  end
32
31
  end
@@ -15,7 +15,6 @@ module Arpa
15
15
  def repository_class
16
16
  RepositoryAction
17
17
  end
18
-
19
18
  end
20
19
  end
21
20
  end
@@ -2,13 +2,12 @@ module Arpa
2
2
  module Repositories
3
3
  module Actions
4
4
  class RepositoryAction < ActiveRecord::Base
5
- default_scope {order(name: :asc)}
5
+ default_scope { order(name: :asc) }
6
6
 
7
7
  alias_attribute :resource_id, :repository_resource_id
8
8
  belongs_to :resource, foreign_key: 'repository_resource_id', class_name: 'Arpa::Repositories::Resources::RepositoryResource'
9
9
 
10
10
  has_and_belongs_to_many :roles, class_name: 'Arpa::Repositories::Roles::RepositoryRole'
11
-
12
11
  end
13
12
  end
14
13
  end
@@ -1,7 +1,6 @@
1
1
  module Arpa
2
2
  module Repositories
3
3
  module Base
4
-
5
4
  def mapper_instance
6
5
  raise NotImplementedError, "This #{self.class} cannot respond :mapper_instance"
7
6
  end
@@ -9,7 +8,6 @@ module Arpa
9
8
  def repository_class
10
9
  raise NotImplementedError, "This #{self.class} cannot respond :repository_class"
11
10
  end
12
-
13
11
  end
14
12
  end
15
13
  end
@@ -11,7 +11,6 @@ module Arpa
11
11
  def repository_class
12
12
  RepositoryProfile
13
13
  end
14
-
15
14
  end
16
15
  end
17
16
  end
@@ -17,9 +17,9 @@ module Arpa
17
17
 
18
18
  def all_by_entity(entity_id, entity_class)
19
19
  repository_class
20
- .where("( (entity_id is null AND entity_class is null) OR (entity_id = '#{entity_id}' AND entity_class = '#{entity_class}') )" )
20
+ .where("( (entity_id is null AND entity_class is null) OR (entity_id = '#{entity_id}' AND entity_class = '#{entity_class}') )")
21
21
  .collect do |record|
22
- mapper_instance.map_to_entity(record)
22
+ mapper_instance.map_to_entity(record)
23
23
  end
24
24
  end
25
25
 
@@ -30,7 +30,6 @@ module Arpa
30
30
  def repository_class
31
31
  RepositoryProfile
32
32
  end
33
-
34
33
  end
35
34
  end
36
35
  end
@@ -22,7 +22,6 @@ module Arpa
22
22
  def repository_class
23
23
  RepositoryProfile
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
  end
@@ -2,10 +2,9 @@ module Arpa
2
2
  module Repositories
3
3
  module Profiles
4
4
  class RepositoryProfile < ActiveRecord::Base
5
- default_scope {where(removed: false).order(name: :asc)}
5
+ default_scope { where(removed: false).order(name: :asc) }
6
6
 
7
7
  has_and_belongs_to_many :roles, class_name: 'Arpa::Repositories::Roles::RepositoryRole'
8
-
9
8
  end
10
9
  end
11
10
  end
@@ -16,7 +16,6 @@ module Arpa
16
16
  def repository_class
17
17
  RepositoryProfile
18
18
  end
19
-
20
19
  end
21
20
  end
22
21
  end
@@ -4,9 +4,7 @@ module Arpa
4
4
  include Base
5
5
 
6
6
  def create(entity)
7
- save(entity) do |record|
8
- record.save!
9
- end
7
+ save(entity, &:save!)
10
8
  end
11
9
 
12
10
  def update(entity)
@@ -24,10 +22,10 @@ module Arpa
24
22
 
25
23
  private
26
24
 
27
- def save(entity, &block)
28
- record = mapper_instance.map_to_record( entity)
25
+ def save(entity)
26
+ record = mapper_instance.map_to_record(entity)
29
27
  begin
30
- block.call(record)
28
+ yield(record)
31
29
  rescue ActiveRecord::RecordInvalid => invalid
32
30
  raise Arpa::Exceptions::RecordInvalid.new(message: invalid.message, errors: invalid.record.errors)
33
31
  end
@@ -35,10 +33,7 @@ module Arpa
35
33
  mapper_instance.map_to_entity(record)
36
34
  end
37
35
 
38
- def post_update(entity, record)
39
- end
40
-
36
+ def post_update(entity, record); end
41
37
  end
42
38
  end
43
39
  end
44
-
@@ -11,7 +11,6 @@ module Arpa
11
11
  def repository_class
12
12
  RepositoryResource
13
13
  end
14
-
15
14
  end
16
15
  end
17
16
  end
@@ -27,7 +27,6 @@ module Arpa
27
27
  def repository_class
28
28
  RepositoryResource
29
29
  end
30
-
31
30
  end
32
31
  end
33
32
  end
@@ -15,7 +15,6 @@ module Arpa
15
15
  def repository_class
16
16
  RepositoryResource
17
17
  end
18
-
19
18
  end
20
19
  end
21
20
  end
@@ -2,10 +2,9 @@ module Arpa
2
2
  module Repositories
3
3
  module Resources
4
4
  class RepositoryResource < ActiveRecord::Base
5
- default_scope {order(name: :asc)}
5
+ default_scope { order(name: :asc) }
6
6
 
7
7
  has_many :actions, dependent: :destroy, class_name: 'Arpa::Repositories::Actions::RepositoryAction'
8
-
9
8
  end
10
9
  end
11
10
  end
@@ -11,7 +11,6 @@ module Arpa
11
11
  def repository_class
12
12
  RepositoryRole
13
13
  end
14
-
15
14
  end
16
15
  end
17
16
  end
@@ -22,7 +22,6 @@ module Arpa
22
22
  def repository_class
23
23
  RepositoryRole
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
  end
@@ -22,7 +22,6 @@ module Arpa
22
22
  def repository_class
23
23
  RepositoryRole
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
  end
@@ -2,11 +2,10 @@ module Arpa
2
2
  module Repositories
3
3
  module Roles
4
4
  class RepositoryRole < ActiveRecord::Base
5
- default_scope {where(removed: false).order(name: :asc)}
5
+ default_scope { where(removed: false).order(name: :asc) }
6
6
 
7
7
  has_and_belongs_to_many :actions, class_name: 'Arpa::Repositories::Actions::RepositoryAction'
8
8
  has_and_belongs_to_many :profiles, class_name: 'Arpa::Repositories::Profiles::RepositoryProfile'
9
-
10
9
  end
11
10
  end
12
11
  end
@@ -16,7 +16,6 @@ module Arpa
16
16
  def repository_class
17
17
  RepositoryRole
18
18
  end
19
-
20
19
  end
21
20
  end
22
21
  end
@@ -3,7 +3,6 @@ module Arpa
3
3
  module Actions
4
4
  module Create
5
5
  class ActionCreator
6
-
7
6
  def create_many(params)
8
7
  params[:actions_names].collect do |action_name|
9
8
  create(action_params(params, action_name))
@@ -23,7 +22,7 @@ module Arpa
23
22
  private
24
23
 
25
24
  def action_params(params, action_name)
26
- {name: action_name, resource_id: params[:resource].id}
25
+ { name: action_name, resource_id: params[:resource].id }
27
26
  end
28
27
 
29
28
  def action_instance(params)
@@ -42,7 +41,6 @@ module Arpa
42
41
  def creator_repo
43
42
  @creator_repo ||= Arpa::Repositories::Actions::Creator.new
44
43
  end
45
-
46
44
  end
47
45
  end
48
46
  end
@@ -3,7 +3,6 @@ module Arpa
3
3
  module Actions
4
4
  module Remove
5
5
  class ActionRemover
6
-
7
6
  def remove_nonexistent_actions(params)
8
7
  params[:resource].actions.each do |action|
9
8
  exist = params[:actions_names].include?(action.name)
@@ -16,7 +15,6 @@ module Arpa
16
15
  def remover_repo
17
16
  @remover_repo ||= Arpa::Repositories::Actions::Remover.new
18
17
  end
19
-
20
18
  end
21
19
  end
22
20
  end
@@ -1,19 +1,16 @@
1
1
  module Arpa
2
2
  module Services
3
3
  module Base
4
-
5
4
  def self.included(base)
6
5
  base.extend ClassMethods
7
6
  end
8
7
 
9
- def manager_action callback, &block
8
+ def manager_action(callback)
10
9
  begin_transaction do
11
- begin
12
- result = block.call
13
- callback[:success].call result
14
- rescue => e
15
- callback[:fail].call e
16
- end
10
+ result = yield
11
+ callback[:success].call result
12
+ rescue StandardError => e
13
+ callback[:fail].call e
17
14
  end
18
15
  end
19
16
 
@@ -26,7 +23,7 @@ module Arpa
26
23
  end
27
24
 
28
25
  module ClassMethods
29
- def repository_transaction repository_transaction_class
26
+ def repository_transaction(repository_transaction_class)
30
27
  @repository_transaction = repository_transaction_class
31
28
  end
32
29
 
@@ -34,7 +31,6 @@ module Arpa
34
31
  @repository_transaction ||= 'ActiveRecord::Base'
35
32
  @repository_transaction.constantize
36
33
  end
37
-
38
34
  end
39
35
  end
40
36
  end
@@ -3,7 +3,6 @@ module Arpa
3
3
  module Profiles
4
4
  module Create
5
5
  class ProfileCreator
6
-
7
6
  def create(params)
8
7
  profile = profile_instance(params)
9
8
  validate_profile(profile)
@@ -24,7 +23,6 @@ module Arpa
24
23
  def creator_repo
25
24
  @creator_repo ||= Arpa::Repositories::Profiles::Creator.new
26
25
  end
27
-
28
26
  end
29
27
  end
30
28
  end