shamu 0.0.1 → 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 +4 -4
- data/.codeclimate.yml +26 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +89 -30
- data/.yardopts +4 -5
- data/Gemfile +24 -12
- data/Guardfile +5 -0
- data/LABELS.md +22 -0
- data/README.md +41 -0
- data/Rakefile +12 -0
- data/circle.yml +7 -3
- data/config.ru +7 -0
- data/lib/shamu/active_record.rb +7 -0
- data/lib/shamu/attributes/assignment.rb +114 -0
- data/lib/shamu/attributes/equality.rb +40 -0
- data/lib/shamu/attributes/fluid_assignment.rb +49 -0
- data/lib/shamu/attributes/validation.rb +74 -0
- data/lib/shamu/attributes.rb +255 -0
- data/lib/shamu/auditing/README.md +0 -0
- data/lib/shamu/auditing/audit_record.rb +32 -0
- data/lib/shamu/auditing/auditing_service.rb +32 -0
- data/lib/shamu/auditing/list_scope.rb +22 -0
- data/lib/shamu/auditing/logging_auditing_service.rb +16 -0
- data/lib/shamu/auditing/support.rb +75 -0
- data/lib/shamu/auditing/transaction.rb +58 -0
- data/lib/shamu/auditing.rb +12 -0
- data/lib/shamu/entities/README.md +1 -0
- data/lib/shamu/entities/active_record.rb +123 -0
- data/lib/shamu/entities/active_record_soft_destroy.rb +91 -0
- data/lib/shamu/entities/entity.rb +196 -0
- data/lib/shamu/entities/entity_path.rb +87 -0
- data/lib/shamu/entities/identity_cache.rb +64 -0
- data/lib/shamu/entities/list.rb +54 -0
- data/lib/shamu/entities/list_scope/dates.rb +57 -0
- data/lib/shamu/entities/list_scope/paging.rb +51 -0
- data/lib/shamu/entities/list_scope/scoped_paging.rb +65 -0
- data/lib/shamu/entities/list_scope/sorting.rb +76 -0
- data/lib/shamu/entities/list_scope.rb +105 -0
- data/lib/shamu/entities/null_entity.rb +88 -0
- data/lib/shamu/entities.rb +11 -0
- data/lib/shamu/error.rb +23 -5
- data/lib/shamu/events/README.md +0 -0
- data/lib/shamu/events/active_record/channel.rb +36 -0
- data/lib/shamu/events/active_record/message.rb +52 -0
- data/lib/shamu/events/active_record/migration.rb +49 -0
- data/lib/shamu/events/active_record/runner.rb +28 -0
- data/lib/shamu/events/active_record/service.rb +174 -0
- data/lib/shamu/events/active_record.rb +13 -0
- data/lib/shamu/events/channel_stats.rb +23 -0
- data/lib/shamu/events/error.rb +24 -0
- data/lib/shamu/events/events_service.rb +136 -0
- data/lib/shamu/events/in_memory/async_service.rb +48 -0
- data/lib/shamu/events/in_memory/service.rb +97 -0
- data/lib/shamu/events/in_memory.rb +10 -0
- data/lib/shamu/events/message.rb +38 -0
- data/lib/shamu/events/support.rb +60 -0
- data/lib/shamu/events.rb +12 -0
- data/lib/shamu/features/README.md +0 -0
- data/lib/shamu/features/conditions/condition.rb +39 -0
- data/lib/shamu/features/conditions/env.rb +37 -0
- data/lib/shamu/features/conditions/hosts.rb +25 -0
- data/lib/shamu/features/conditions/matching.rb +16 -0
- data/lib/shamu/features/conditions/not_matching.rb +16 -0
- data/lib/shamu/features/conditions/percentage.rb +44 -0
- data/lib/shamu/features/conditions/proc.rb +54 -0
- data/lib/shamu/features/conditions/roles.rb +23 -0
- data/lib/shamu/features/conditions/schedule_at.rb +27 -0
- data/lib/shamu/features/conditions.rb +18 -0
- data/lib/shamu/features/config_service.rb +10 -0
- data/lib/shamu/features/context.rb +80 -0
- data/lib/shamu/features/env_store.rb +88 -0
- data/lib/shamu/features/errors.rb +29 -0
- data/lib/shamu/features/features_service.rb +168 -0
- data/lib/shamu/features/list_scope.rb +30 -0
- data/lib/shamu/features/selector.rb +50 -0
- data/lib/shamu/features/support.rb +51 -0
- data/lib/shamu/features/toggle.rb +149 -0
- data/lib/shamu/features/toggle_codec.rb +69 -0
- data/lib/shamu/features.rb +16 -0
- data/lib/shamu/locale/en.yml +22 -2
- data/lib/shamu/logger.rb +13 -0
- data/lib/shamu/rack/README.md +0 -0
- data/lib/shamu/rack/cookies.rb +115 -0
- data/lib/shamu/rack/cookies_middleware.rb +26 -0
- data/lib/shamu/rack/query_params.rb +41 -0
- data/lib/shamu/rack/query_params_middleware.rb +24 -0
- data/lib/shamu/rack.rb +12 -0
- data/lib/shamu/rails/controller.rb +131 -0
- data/lib/shamu/rails/entity.rb +168 -0
- data/lib/shamu/rails/features.rb +13 -0
- data/lib/shamu/rails/railtie.rb +30 -0
- data/lib/shamu/rails.rb +10 -0
- data/lib/shamu/rspec/matchers.rb +44 -0
- data/lib/shamu/rspec.rb +1 -0
- data/lib/shamu/security/README.md +0 -0
- data/lib/shamu/security/active_record_policy.rb +106 -0
- data/lib/shamu/security/error.rb +65 -0
- data/lib/shamu/security/hashed_value.rb +71 -0
- data/lib/shamu/security/no_policy.rb +15 -0
- data/lib/shamu/security/policy.rb +289 -0
- data/lib/shamu/security/policy_refinement.rb +50 -0
- data/lib/shamu/security/policy_rule.rb +59 -0
- data/lib/shamu/security/principal.rb +72 -0
- data/lib/shamu/security/roles.rb +62 -0
- data/lib/shamu/security/roles_service.rb +30 -0
- data/lib/shamu/security/support.rb +83 -0
- data/lib/shamu/security.rb +43 -0
- data/lib/shamu/services/README.md +2 -0
- data/lib/shamu/services/active_record.rb +58 -0
- data/lib/shamu/services/active_record_crud.rb +378 -0
- data/lib/shamu/services/error.rb +24 -0
- data/lib/shamu/services/lazy_association.rb +31 -0
- data/lib/shamu/services/lazy_transform.rb +97 -0
- data/lib/shamu/services/request.rb +122 -0
- data/lib/shamu/services/request_support.rb +124 -0
- data/lib/shamu/services/result.rb +75 -0
- data/lib/shamu/services/service.rb +355 -0
- data/lib/shamu/services.rb +12 -0
- data/lib/shamu/sessions/README.md +2 -0
- data/lib/shamu/sessions/cookie_store.rb +79 -0
- data/lib/shamu/sessions/session_store.rb +42 -0
- data/lib/shamu/sessions.rb +8 -0
- data/lib/shamu/to_bool_extension.rb +57 -0
- data/lib/shamu/to_model_id_extension.rb +50 -0
- data/lib/shamu/version.rb +10 -4
- data/lib/shamu.rb +18 -6
- data/shamu.gemspec +21 -10
- data/spec/internal/README.md +4 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +3 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/lib/shamu/active_record_support.rb +32 -0
- data/spec/lib/shamu/attributes/assignment_spec.rb +129 -0
- data/spec/lib/shamu/attributes/equality_spec.rb +63 -0
- data/spec/lib/shamu/attributes/fluid_assignment_spec.rb +31 -0
- data/spec/lib/shamu/attributes/validation_spec.rb +53 -0
- data/spec/lib/shamu/attributes_spec.rb +331 -0
- data/spec/lib/shamu/auditing/logging_auditing_service_spec.rb +18 -0
- data/spec/lib/shamu/auditing/support_spec.rb +41 -0
- data/spec/lib/shamu/entities/active_record_soft_destroy_spec.rb +82 -0
- data/spec/lib/shamu/entities/active_record_spec.rb +66 -0
- data/spec/lib/shamu/entities/entity_path_spec.rb +40 -0
- data/spec/lib/shamu/entities/entity_spec.rb +56 -0
- data/spec/lib/shamu/entities/identity_cache_spec.rb +69 -0
- data/spec/lib/shamu/entities/list_scope/dates_spec.rb +47 -0
- data/spec/lib/shamu/entities/list_scope/paging_spec.rb +41 -0
- data/spec/lib/shamu/entities/list_scope/scoped_paging_spec.rb +40 -0
- data/spec/lib/shamu/entities/list_scope/sorting_spec.rb +59 -0
- data/spec/lib/shamu/entities/list_scope_spec.rb +127 -0
- data/spec/lib/shamu/entities/list_spec.rb +60 -0
- data/spec/lib/shamu/entities/null_entity_spec.rb +94 -0
- data/spec/lib/shamu/events/active_record/migration_spec.rb +11 -0
- data/spec/lib/shamu/events/active_record/service_spec.rb +139 -0
- data/spec/lib/shamu/events/events_service_spec.rb +57 -0
- data/spec/lib/shamu/events/in_memory/async_service_spec.rb +37 -0
- data/spec/lib/shamu/events/in_memory/service_spec.rb +36 -0
- data/spec/lib/shamu/events/message_spec.rb +7 -0
- data/spec/lib/shamu/events/support_spec.rb +44 -0
- data/spec/lib/shamu/features/conditions/condition_spec.rb +8 -0
- data/spec/lib/shamu/features/conditions/env_spec.rb +29 -0
- data/spec/lib/shamu/features/conditions/hosts_spec.rb +21 -0
- data/spec/lib/shamu/features/conditions/matching_spec.rb +23 -0
- data/spec/lib/shamu/features/conditions/percentage_spec.rb +71 -0
- data/spec/lib/shamu/features/conditions/proc_spec.rb +28 -0
- data/spec/lib/shamu/features/env_store_spec.rb +48 -0
- data/spec/lib/shamu/features/features.yml +34 -0
- data/spec/lib/shamu/features/features_service_spec.rb +109 -0
- data/spec/lib/shamu/features/secondary.yml +5 -0
- data/spec/lib/shamu/features/selector_spec.rb +17 -0
- data/spec/lib/shamu/features/support_spec.rb +45 -0
- data/spec/lib/shamu/features/toggle_codec_spec.rb +28 -0
- data/spec/lib/shamu/features/toggle_spec.rb +42 -0
- data/spec/lib/shamu/rack/cookies_middleware_spec.rb +33 -0
- data/spec/lib/shamu/rack/cookies_spec.rb +43 -0
- data/spec/lib/shamu/rack/query_params_middleware_spec.rb +33 -0
- data/spec/lib/shamu/rack/query_params_spec.rb +23 -0
- data/spec/lib/shamu/rails/controller_spec.rb +74 -0
- data/spec/lib/shamu/rails/entity_spec.rb +150 -0
- data/spec/lib/shamu/rails/features.yml +13 -0
- data/spec/lib/shamu/rails/features_spec.rb +45 -0
- data/spec/lib/shamu/security/active_record_policy_spec.rb +38 -0
- data/spec/lib/shamu/security/hashed_value_spec.rb +41 -0
- data/spec/lib/shamu/security/policy_refinement_spec.rb +61 -0
- data/spec/lib/shamu/security/policy_rule_spec.rb +60 -0
- data/spec/lib/shamu/security/policy_spec.rb +158 -0
- data/spec/lib/shamu/security/roles_spec.rb +46 -0
- data/spec/lib/shamu/services/active_record_crud_spec.rb +460 -0
- data/spec/lib/shamu/services/active_record_spec.rb +92 -0
- data/spec/lib/shamu/services/lazy_association_spec.rb +31 -0
- data/spec/lib/shamu/services/lazy_transform_spec.rb +96 -0
- data/spec/lib/shamu/services/request_spec.rb +58 -0
- data/spec/lib/shamu/services/request_support_spec.rb +129 -0
- data/spec/lib/shamu/services/result_spec.rb +37 -0
- data/spec/lib/shamu/services/service_spec.rb +307 -0
- data/spec/lib/shamu/sessions/cookie_store_spec.rb +44 -0
- data/spec/lib/shamu/to_bool_extension_spec.rb +67 -0
- data/spec/lib/shamu/to_model_id_extension_spec.rb +54 -0
- data/spec/rails_helper.rb +13 -0
- data/spec/spec_helper.rb +17 -12
- data/spec/support/active_record.rb +17 -0
- data/spec/support/database.rb +14 -0
- data/spec/support/logger.rb +0 -0
- metadata +383 -9
- data/spec/lib/shamu_spec.rb +0 -5
- /data/{spec/internal/log/test.log → lib/shamu/attributes/README.md} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 27e560182b114ef221743131ca89ac18601cfbf7
|
|
4
|
+
data.tar.gz: c6fd668c63413a9d45cefe73b87a587240ee5c8c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31814221203809e5be4e532732c4f01d0f6c2583dc197bf4025efb8f1ae0e6e69c45707d5b7d553ea87e555767bf56a7efc29c910b1ea1245ac62283f3e5602d
|
|
7
|
+
data.tar.gz: 915d74f223c593d04dc7b5d79629d7207d26fd5238956c52bf43f03cfd2bf20915ba59fedafd6249b19a0c00792952aa9e4d62638af880fe0d7e5d13702ce7aa
|
data/.codeclimate.yml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
engines:
|
|
2
|
+
duplication:
|
|
3
|
+
enabled: true
|
|
4
|
+
config:
|
|
5
|
+
languages:
|
|
6
|
+
- ruby
|
|
7
|
+
- javascript
|
|
8
|
+
- python
|
|
9
|
+
- php
|
|
10
|
+
fixme:
|
|
11
|
+
enabled: true
|
|
12
|
+
rubocop:
|
|
13
|
+
enabled: true
|
|
14
|
+
eslint:
|
|
15
|
+
enabled: true
|
|
16
|
+
ratings:
|
|
17
|
+
paths:
|
|
18
|
+
- "**.inc"
|
|
19
|
+
- "**.js"
|
|
20
|
+
- "**.jsx"
|
|
21
|
+
- "**.module"
|
|
22
|
+
- "**.php"
|
|
23
|
+
- "**.py"
|
|
24
|
+
- "**.rb"
|
|
25
|
+
exclude_paths:
|
|
26
|
+
- spec/**/*
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,62 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.2
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Lint/AmbiguousRegexpLiteral:
|
|
6
|
+
Enabled: false
|
|
7
|
+
|
|
8
|
+
Lint/AssignmentInCondition:
|
|
9
|
+
Enabled: false
|
|
10
|
+
|
|
11
|
+
Lint/UnusedMethodArgument:
|
|
12
|
+
Enabled: false
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Metrics/ClassLength:
|
|
16
|
+
Max: 500
|
|
17
|
+
|
|
18
|
+
Metrics/LineLength:
|
|
2
19
|
Max: 120
|
|
3
20
|
|
|
4
|
-
|
|
5
|
-
|
|
21
|
+
Metrics/MethodLength:
|
|
22
|
+
Max: 15
|
|
6
23
|
|
|
7
|
-
|
|
24
|
+
Metrics/AbcSize:
|
|
25
|
+
Max: 20
|
|
26
|
+
|
|
27
|
+
Metrics/CyclomaticComplexity:
|
|
28
|
+
Max: 10
|
|
29
|
+
|
|
30
|
+
Metrics/ModuleLength:
|
|
31
|
+
Max: 500
|
|
32
|
+
|
|
33
|
+
Metrics/ParameterLists:
|
|
34
|
+
CountKeywordArgs: false
|
|
35
|
+
|
|
36
|
+
Style/Alias:
|
|
8
37
|
Enabled: false
|
|
9
38
|
|
|
10
|
-
Style/
|
|
39
|
+
Style/CommentIndentation:
|
|
11
40
|
Enabled: false
|
|
12
41
|
|
|
13
|
-
Style/
|
|
42
|
+
Style/EmptyLines:
|
|
14
43
|
Enabled: false
|
|
15
44
|
|
|
16
|
-
Style/
|
|
45
|
+
Style/EmptyLinesAroundBlockBody:
|
|
17
46
|
Enabled: false
|
|
18
47
|
|
|
19
|
-
Style/
|
|
48
|
+
Style/EmptyLinesAroundClassBody:
|
|
20
49
|
Enabled: false
|
|
21
50
|
|
|
22
|
-
Style/
|
|
51
|
+
Style/EmptyLinesAroundModuleBody:
|
|
23
52
|
Enabled: false
|
|
24
53
|
|
|
25
|
-
Style/
|
|
54
|
+
Style/DoubleNegation:
|
|
26
55
|
Enabled: false
|
|
27
56
|
|
|
28
|
-
Style/
|
|
57
|
+
Style/Documentation:
|
|
29
58
|
Enabled: false
|
|
30
59
|
|
|
31
|
-
Style/
|
|
60
|
+
Style/GuardClause:
|
|
32
61
|
Enabled: false
|
|
33
62
|
|
|
34
|
-
Style/
|
|
63
|
+
Style/HashSyntax:
|
|
35
64
|
Enabled: false
|
|
36
65
|
|
|
37
|
-
Style/
|
|
66
|
+
Style/IndentArray:
|
|
38
67
|
Enabled: false
|
|
39
68
|
|
|
40
|
-
Style/
|
|
69
|
+
Style/IndentationConsistency:
|
|
41
70
|
Enabled: false
|
|
42
71
|
|
|
43
|
-
Style/
|
|
44
|
-
|
|
72
|
+
Style/IndentationWidth:
|
|
73
|
+
Enabled: false
|
|
45
74
|
|
|
46
|
-
Style/
|
|
47
|
-
|
|
48
|
-
'%': '{}'
|
|
49
|
-
'%i': '{}'
|
|
50
|
-
'%q': '{}'
|
|
51
|
-
'%Q': '{}'
|
|
52
|
-
'%r': '{}'
|
|
53
|
-
'%s': '{}'
|
|
54
|
-
'%w': '{}'
|
|
55
|
-
'%W': '{}'
|
|
56
|
-
'%x': '{}'
|
|
75
|
+
Style/Lambda:
|
|
76
|
+
Enabled: false
|
|
57
77
|
|
|
58
|
-
|
|
78
|
+
Style/MultilineBlockChain:
|
|
59
79
|
Enabled: false
|
|
60
80
|
|
|
61
|
-
|
|
81
|
+
Style/OptionHash:
|
|
82
|
+
Enabled: true
|
|
83
|
+
|
|
84
|
+
Style/RegexpLiteral:
|
|
85
|
+
Enabled: false
|
|
86
|
+
|
|
87
|
+
Style/SignalException:
|
|
88
|
+
Enabled: false
|
|
89
|
+
|
|
90
|
+
Style/SpaceAroundBlockParameters:
|
|
91
|
+
Enabled: false
|
|
92
|
+
|
|
93
|
+
Style/SpaceAroundOperators:
|
|
94
|
+
Enabled: false
|
|
95
|
+
|
|
96
|
+
Style/SpaceInsideBrackets:
|
|
97
|
+
Enabled: false
|
|
98
|
+
|
|
99
|
+
Style/SpaceInsideParens:
|
|
100
|
+
Enabled: false
|
|
101
|
+
|
|
102
|
+
Style/SpaceInsideStringInterpolation:
|
|
103
|
+
EnforcedStyle: space
|
|
104
|
+
|
|
105
|
+
Style/StringLiterals:
|
|
106
|
+
EnforcedStyle: double_quotes
|
|
107
|
+
|
|
108
|
+
Style/TrailingBlankLines:
|
|
109
|
+
Enabled: false
|
|
110
|
+
|
|
111
|
+
Style/TrailingCommaInLiteral:
|
|
112
|
+
Enabled: false
|
|
113
|
+
|
|
114
|
+
Style/UnneededInterpolation:
|
|
115
|
+
Enabled: false
|
|
116
|
+
|
|
117
|
+
Style/CaseEquality:
|
|
118
|
+
Enabled: false
|
|
119
|
+
|
|
120
|
+
Style/WordArray:
|
|
62
121
|
Enabled: false
|
data/.yardopts
CHANGED
data/Gemfile
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
source
|
|
1
|
+
source "https://rubygems.org"
|
|
2
2
|
|
|
3
|
-
# Specify your gem
|
|
3
|
+
# Specify your gem"s dependencies in shamu.gemspec
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
group :test do
|
|
7
|
+
gem "activerecord", "~> 4.2.5"
|
|
8
|
+
gem "actionpack", "~> 4.2.5"
|
|
9
|
+
gem "kaminari", "~> 0.16.3", require: false
|
|
7
10
|
|
|
8
|
-
gem
|
|
9
|
-
gem
|
|
10
|
-
|
|
11
|
-
gem
|
|
12
|
-
gem
|
|
13
|
-
gem
|
|
14
|
-
gem
|
|
15
|
-
gem
|
|
16
|
-
gem
|
|
17
|
-
gem
|
|
11
|
+
gem "byebug"
|
|
12
|
+
gem "pry-byebug"
|
|
13
|
+
|
|
14
|
+
gem "sqlite3", "~> 1.3.11"
|
|
15
|
+
gem "guard", "~> 2.12.8"
|
|
16
|
+
gem "rubocop"
|
|
17
|
+
gem "guard-rubocop"
|
|
18
|
+
gem "spring"
|
|
19
|
+
gem "guard-rspec"
|
|
20
|
+
gem "rspec-its"
|
|
21
|
+
gem "rspec-wait"
|
|
22
|
+
gem "rspec-rails", require: false
|
|
23
|
+
gem "fuubar"
|
|
24
|
+
gem "yard"
|
|
25
|
+
gem "yard-activesupport-concern"
|
|
26
|
+
gem "simplecov", github: "colszowka/simplecov"
|
|
27
|
+
gem "ruby_gntp", "~> 0.3.4"
|
|
28
|
+
gem "awesome_print"
|
|
18
29
|
|
|
19
30
|
gem "codeclimate-test-reporter", group: :test, require: nil
|
|
31
|
+
gem "rspec_junit_formatter", "~> 0.2.2", platforms: :mri
|
|
20
32
|
end
|
data/Guardfile
CHANGED
data/LABELS.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Kind
|
|
2
|
+
|
|
3
|
+
- __kind/bug__ the reported issue or PR addresses a bug.
|
|
4
|
+
- __kind/design__ design work for a _kind/feature_.
|
|
5
|
+
- __kind/eng__ general eng work. Part of a larger _kind/feature_.
|
|
6
|
+
- __kind/feature__ a comprehensive
|
|
7
|
+
- __kind/task__ non-eng/design work such as updating blogs, registering accounts, etc.
|
|
8
|
+
|
|
9
|
+
# Review
|
|
10
|
+
|
|
11
|
+
- __review/ship-it__ - changes are approved. Merge to master.
|
|
12
|
+
- __review/waiting-for-changes__ - the PR has been reviewed but changes are required. Remove label when changes have been submitted.
|
|
13
|
+
- __review/work-in-progress__ - the PR is a work in progress open for comments understanding it is not ready for production.
|
|
14
|
+
|
|
15
|
+
# Status
|
|
16
|
+
|
|
17
|
+
- __status/blocked__ - cannot ship due to dependencies. Mention any open issues or PRs that are blocking.
|
|
18
|
+
- __status/duplicate__ - duplicate of another issue or PR.
|
|
19
|
+
- __status/hold__ - ready for production but don't deploy yet.
|
|
20
|
+
- __status/in-progress__ - work is currently being done on the issue.
|
|
21
|
+
- __status/need-help__ - issue needs help from OSS community.
|
|
22
|
+
- __status/wontfix__ - while the issue or PR may be valid we are choosing not to address it.
|
data/README.md
CHANGED
|
@@ -10,3 +10,44 @@ Have a whale of a good time adding Service Oriented Architecture to your ruby pr
|
|
|
10
10
|
|
|
11
11
|
(Also check out [shog](http://github.com/phallguy/shog) for better rails logs)
|
|
12
12
|
|
|
13
|
+
# SOA
|
|
14
|
+
|
|
15
|
+
# Components
|
|
16
|
+
|
|
17
|
+
- {Shamu::Attributes}
|
|
18
|
+
- {Shamu::Entities}
|
|
19
|
+
- {Shamu::Services}
|
|
20
|
+
- {Shamu::Security}
|
|
21
|
+
- {Shamu::Sessions}
|
|
22
|
+
- {Shamu::Events}
|
|
23
|
+
- {Shamu::Auditing}
|
|
24
|
+
- {Shamu::Features}
|
|
25
|
+
- {Shamu::Rails}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Dependency Injection
|
|
30
|
+
|
|
31
|
+
....
|
|
32
|
+
[Scorpion](http://github.com/phallguy/scorpion)
|
|
33
|
+
|
|
34
|
+
# Using with Rails
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Active Record
|
|
38
|
+
|
|
39
|
+
Shamu does not come with a hard dependency on ActiveRecord - it should work with
|
|
40
|
+
any persistence you've chosen to use in your project. It does come with some
|
|
41
|
+
convenience mixins to make it easier to work with AR.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
- **{Shamu::Entities::ActiveRecord}** adds convenience methods for working with
|
|
45
|
+
ActiveRecord models as entities.
|
|
46
|
+
|
|
47
|
+
## Controllers
|
|
48
|
+
|
|
49
|
+
- {Shamu::Rails::Controller}
|
|
50
|
+
|
|
51
|
+
# Contributing
|
|
52
|
+
|
|
53
|
+
See [LABELS](LABELS.md)
|
data/Rakefile
CHANGED
data/circle.yml
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
database:
|
|
2
2
|
override:
|
|
3
|
-
# We
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
# We manually setup a sqlite3 database so don't setup anything on the CI machine
|
|
4
|
+
- echo "Skip DB"
|
|
5
|
+
|
|
6
|
+
test:
|
|
7
|
+
override:
|
|
8
|
+
- RAILS_ENV=test bundle exec rspec -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml
|
|
9
|
+
- bundle exec rubocop
|
data/config.ru
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
require "shamu/entities/active_record"
|
|
2
|
+
require "shamu/entities/active_record_soft_destroy"
|
|
3
|
+
require "shamu/services/active_record"
|
|
4
|
+
require "shamu/services/active_record_crud"
|
|
5
|
+
require "shamu/security/active_record_policy"
|
|
6
|
+
require "shamu/security/policy_refinement"
|
|
7
|
+
require "shamu/events/active_record"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require "active_support/concern"
|
|
2
|
+
|
|
3
|
+
module Shamu
|
|
4
|
+
module Attributes
|
|
5
|
+
|
|
6
|
+
# Provide a means for defining writable attributes.
|
|
7
|
+
module Assignment
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do |base|
|
|
11
|
+
raise "Must include Shamu::Attributes first." unless base < Shamu::Attributes
|
|
12
|
+
public :assign_attributes
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class_methods do
|
|
16
|
+
|
|
17
|
+
# Define a new attribute for the class.
|
|
18
|
+
#
|
|
19
|
+
# @param (see Projection::DSL#attribute)
|
|
20
|
+
# @param [Symbol, #call] coerce name of a method on the assigned value
|
|
21
|
+
# to call, or a custom method that can parse values when assigning
|
|
22
|
+
# the attribute.
|
|
23
|
+
# @param [Boolean] array true if the expected value should be an array.
|
|
24
|
+
#
|
|
25
|
+
# @return [void]
|
|
26
|
+
#
|
|
27
|
+
# @example
|
|
28
|
+
#
|
|
29
|
+
# class Params
|
|
30
|
+
# include Shamu::Attributes
|
|
31
|
+
# include Shamu::Attributes::Assignment
|
|
32
|
+
#
|
|
33
|
+
# attribute :created_at, coerce: :to_datetime
|
|
34
|
+
# attribute :count, coerce: :to_i
|
|
35
|
+
# attribute :label, coerce: ->(value){ value.upcase.to_sym }
|
|
36
|
+
# attribute :tags, coerce: :to_s, array: true
|
|
37
|
+
# end
|
|
38
|
+
def attribute( name, *args, **options, &block )
|
|
39
|
+
super
|
|
40
|
+
define_attribute_assignment( name, **options )
|
|
41
|
+
define_attribute_writer( name, **options )
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def attribute_option_keys
|
|
47
|
+
super + [ :coerce, :array ]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def define_attribute_assignment( name, coerce: :smart, array: false, ** )
|
|
51
|
+
super
|
|
52
|
+
|
|
53
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
54
|
+
def assign_#{ name }( *values )
|
|
55
|
+
@#{ name } = coerce_#{ name }#{ array ? '_array' : '' }( *values )
|
|
56
|
+
end
|
|
57
|
+
RUBY
|
|
58
|
+
private :"assign_#{ name }"
|
|
59
|
+
|
|
60
|
+
define_attribute_coercion( name, coerce )
|
|
61
|
+
define_attribute_array( name ) if array
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def define_attribute_array( name )
|
|
65
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
66
|
+
def coerce_#{ name }_array( value )
|
|
67
|
+
value && Array( value ).map do |v|
|
|
68
|
+
coerce_#{ name }( v )
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
RUBY
|
|
72
|
+
|
|
73
|
+
private :"coerce_#{ name }_array"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def define_attribute_coercion( name, coerce )
|
|
77
|
+
coerce = cource_method( name, coerce )
|
|
78
|
+
|
|
79
|
+
if !coerce || coerce.is_a?( Symbol )
|
|
80
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
81
|
+
def coerce_#{ name }( value )
|
|
82
|
+
value#{ coerce && ".#{ coerce }" }
|
|
83
|
+
end
|
|
84
|
+
RUBY
|
|
85
|
+
elsif coerce
|
|
86
|
+
define_method :"coerce_#{ name }", coerce
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private :"coerce_#{ name }"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def cource_method( name, coerce )
|
|
93
|
+
if coerce == :smart
|
|
94
|
+
case name
|
|
95
|
+
when /_at$/, /_on$/ then :to_datetime
|
|
96
|
+
when /_ids?$/ then :to_i
|
|
97
|
+
end
|
|
98
|
+
else
|
|
99
|
+
coerce
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def define_attribute_writer( name, as: nil, ** )
|
|
104
|
+
alias_method :"#{ name }=", :"assign_#{ name }"
|
|
105
|
+
public :"#{ name }="
|
|
106
|
+
|
|
107
|
+
alias_method :"#{ as }=", :"#{ name }=" if as
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Shamu
|
|
2
|
+
module Attributes
|
|
3
|
+
|
|
4
|
+
# Override equality methods to support shallow comparison of attribute
|
|
5
|
+
# values for equality.
|
|
6
|
+
#
|
|
7
|
+
# Add `ignore_inequality: true` to any {Attributes::DSL#attribute} that
|
|
8
|
+
# shouldn't be included in equalty comparisons.
|
|
9
|
+
module Equality
|
|
10
|
+
|
|
11
|
+
# @param [Attributes] other object to compare with.
|
|
12
|
+
# @return [Boolean] true if the two objects are of the same type and
|
|
13
|
+
# attributes are all eql? to each other.
|
|
14
|
+
def ==( other )
|
|
15
|
+
return false unless other.is_a?( self.class ) || is_a?( other.class )
|
|
16
|
+
attributes_eql?( other )
|
|
17
|
+
end
|
|
18
|
+
alias_method :eql?, :==
|
|
19
|
+
|
|
20
|
+
# @return [Integer] a hash computed from the attributes of the object.
|
|
21
|
+
def hash
|
|
22
|
+
self.class.attributes.map do |key, _|
|
|
23
|
+
send( key )
|
|
24
|
+
end.hash
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# @return [Boolean] true if the object's attributes and `other`
|
|
30
|
+
# attributes are all `eql?` to each other.
|
|
31
|
+
def attributes_eql?( other )
|
|
32
|
+
self.class.attributes.all? do |key, attr|
|
|
33
|
+
next true if attr[:ignore_inequality]
|
|
34
|
+
send( key ).eql?( other.send( key ) )
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Shamu
|
|
2
|
+
module Attributes
|
|
3
|
+
|
|
4
|
+
# Add methods to a class to make it easy to build out an object using fluid
|
|
5
|
+
# assignment.
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
#
|
|
9
|
+
# # Without fluid
|
|
10
|
+
# obj = AttributeObject.new
|
|
11
|
+
# obj.name = '...'
|
|
12
|
+
# obj.email = '...'
|
|
13
|
+
#
|
|
14
|
+
# # With fluid
|
|
15
|
+
# obj = FluidObject.new
|
|
16
|
+
# obj.name( '...' )
|
|
17
|
+
# .email( '...' )
|
|
18
|
+
module FluidAssignment
|
|
19
|
+
extend ActiveSupport::Concern
|
|
20
|
+
|
|
21
|
+
included do |base|
|
|
22
|
+
raise "Must include Shamu::Attributes first." unless base < Shamu::Attributes
|
|
23
|
+
raise "Must include Shamu::Attributes::Assignment first." unless base < Shamu::Attributes::Assignment
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# DSL for declaring fluid assignment.
|
|
27
|
+
class_methods do
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def define_attribute_reader( name, ** )
|
|
32
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
33
|
+
def #{ name }( *args )
|
|
34
|
+
if args.length > 0
|
|
35
|
+
assign_#{ name }( *args )
|
|
36
|
+
self
|
|
37
|
+
else
|
|
38
|
+
return @#{ name } if defined? @#{ name }
|
|
39
|
+
@#{ name } = fetch_#{ name }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
RUBY
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require "active_model"
|
|
2
|
+
|
|
3
|
+
module Shamu
|
|
4
|
+
module Attributes
|
|
5
|
+
|
|
6
|
+
# Defines an interface for entities that report validation failures with
|
|
7
|
+
# respect to their attributes.
|
|
8
|
+
module Validation
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
included do |base|
|
|
12
|
+
raise "Must include Shamu::Attributes first." unless base < Shamu::Attributes
|
|
13
|
+
|
|
14
|
+
base.include( ::ActiveModel::Validations )
|
|
15
|
+
base.include( Validation::Overrides )
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @return [Boolean] if the object is free from validation errors. Must
|
|
19
|
+
# call {#validate} before checking.
|
|
20
|
+
def valid?
|
|
21
|
+
errors.blank?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @return [Boolean] true if the object has been validated at least once.
|
|
25
|
+
def validated?
|
|
26
|
+
@validated
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class_methods do
|
|
30
|
+
|
|
31
|
+
# Adds validation options to {Attributes::DSL#attribute}. Any option not
|
|
32
|
+
# recognized by one of the Attributes mixins will be used as validation
|
|
33
|
+
# arguments for the given attribute.
|
|
34
|
+
#
|
|
35
|
+
# @overload attribute( name, build, **options )
|
|
36
|
+
# @param (see Attributes::Assignment::DSL#attribute)
|
|
37
|
+
# @return (see Attributes::Assignment::DSL#attribute)
|
|
38
|
+
#
|
|
39
|
+
# @example
|
|
40
|
+
# attribute :email, presence: true
|
|
41
|
+
#
|
|
42
|
+
# # Results in
|
|
43
|
+
# attribute :email
|
|
44
|
+
# validates :email, presence: true
|
|
45
|
+
def attribute( name, *args, **options, &block )
|
|
46
|
+
super
|
|
47
|
+
|
|
48
|
+
validation_options = options.each_with_object({}) do |(key, value), opts|
|
|
49
|
+
opts[key] = value unless attribute_option_keys.include?( key )
|
|
50
|
+
end
|
|
51
|
+
validates name, validation_options if validation_options.any?
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Overrides ActiveModel::Validation behavior to match Shamu validation
|
|
56
|
+
# behaviors.
|
|
57
|
+
module Overrides
|
|
58
|
+
# @return [Boolean] true if there are no errors reported manually or
|
|
59
|
+
# through {Validation#validate}.
|
|
60
|
+
def valid?
|
|
61
|
+
validate unless validated?
|
|
62
|
+
errors.empty?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Validate the attributes and expose any errors via {#errors}.
|
|
66
|
+
def validate
|
|
67
|
+
@validated = true
|
|
68
|
+
run_validations!
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|