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.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +26 -0
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +89 -30
  5. data/.yardopts +4 -5
  6. data/Gemfile +24 -12
  7. data/Guardfile +5 -0
  8. data/LABELS.md +22 -0
  9. data/README.md +41 -0
  10. data/Rakefile +12 -0
  11. data/circle.yml +7 -3
  12. data/config.ru +7 -0
  13. data/lib/shamu/active_record.rb +7 -0
  14. data/lib/shamu/attributes/assignment.rb +114 -0
  15. data/lib/shamu/attributes/equality.rb +40 -0
  16. data/lib/shamu/attributes/fluid_assignment.rb +49 -0
  17. data/lib/shamu/attributes/validation.rb +74 -0
  18. data/lib/shamu/attributes.rb +255 -0
  19. data/lib/shamu/auditing/README.md +0 -0
  20. data/lib/shamu/auditing/audit_record.rb +32 -0
  21. data/lib/shamu/auditing/auditing_service.rb +32 -0
  22. data/lib/shamu/auditing/list_scope.rb +22 -0
  23. data/lib/shamu/auditing/logging_auditing_service.rb +16 -0
  24. data/lib/shamu/auditing/support.rb +75 -0
  25. data/lib/shamu/auditing/transaction.rb +58 -0
  26. data/lib/shamu/auditing.rb +12 -0
  27. data/lib/shamu/entities/README.md +1 -0
  28. data/lib/shamu/entities/active_record.rb +123 -0
  29. data/lib/shamu/entities/active_record_soft_destroy.rb +91 -0
  30. data/lib/shamu/entities/entity.rb +196 -0
  31. data/lib/shamu/entities/entity_path.rb +87 -0
  32. data/lib/shamu/entities/identity_cache.rb +64 -0
  33. data/lib/shamu/entities/list.rb +54 -0
  34. data/lib/shamu/entities/list_scope/dates.rb +57 -0
  35. data/lib/shamu/entities/list_scope/paging.rb +51 -0
  36. data/lib/shamu/entities/list_scope/scoped_paging.rb +65 -0
  37. data/lib/shamu/entities/list_scope/sorting.rb +76 -0
  38. data/lib/shamu/entities/list_scope.rb +105 -0
  39. data/lib/shamu/entities/null_entity.rb +88 -0
  40. data/lib/shamu/entities.rb +11 -0
  41. data/lib/shamu/error.rb +23 -5
  42. data/lib/shamu/events/README.md +0 -0
  43. data/lib/shamu/events/active_record/channel.rb +36 -0
  44. data/lib/shamu/events/active_record/message.rb +52 -0
  45. data/lib/shamu/events/active_record/migration.rb +49 -0
  46. data/lib/shamu/events/active_record/runner.rb +28 -0
  47. data/lib/shamu/events/active_record/service.rb +174 -0
  48. data/lib/shamu/events/active_record.rb +13 -0
  49. data/lib/shamu/events/channel_stats.rb +23 -0
  50. data/lib/shamu/events/error.rb +24 -0
  51. data/lib/shamu/events/events_service.rb +136 -0
  52. data/lib/shamu/events/in_memory/async_service.rb +48 -0
  53. data/lib/shamu/events/in_memory/service.rb +97 -0
  54. data/lib/shamu/events/in_memory.rb +10 -0
  55. data/lib/shamu/events/message.rb +38 -0
  56. data/lib/shamu/events/support.rb +60 -0
  57. data/lib/shamu/events.rb +12 -0
  58. data/lib/shamu/features/README.md +0 -0
  59. data/lib/shamu/features/conditions/condition.rb +39 -0
  60. data/lib/shamu/features/conditions/env.rb +37 -0
  61. data/lib/shamu/features/conditions/hosts.rb +25 -0
  62. data/lib/shamu/features/conditions/matching.rb +16 -0
  63. data/lib/shamu/features/conditions/not_matching.rb +16 -0
  64. data/lib/shamu/features/conditions/percentage.rb +44 -0
  65. data/lib/shamu/features/conditions/proc.rb +54 -0
  66. data/lib/shamu/features/conditions/roles.rb +23 -0
  67. data/lib/shamu/features/conditions/schedule_at.rb +27 -0
  68. data/lib/shamu/features/conditions.rb +18 -0
  69. data/lib/shamu/features/config_service.rb +10 -0
  70. data/lib/shamu/features/context.rb +80 -0
  71. data/lib/shamu/features/env_store.rb +88 -0
  72. data/lib/shamu/features/errors.rb +29 -0
  73. data/lib/shamu/features/features_service.rb +168 -0
  74. data/lib/shamu/features/list_scope.rb +30 -0
  75. data/lib/shamu/features/selector.rb +50 -0
  76. data/lib/shamu/features/support.rb +51 -0
  77. data/lib/shamu/features/toggle.rb +149 -0
  78. data/lib/shamu/features/toggle_codec.rb +69 -0
  79. data/lib/shamu/features.rb +16 -0
  80. data/lib/shamu/locale/en.yml +22 -2
  81. data/lib/shamu/logger.rb +13 -0
  82. data/lib/shamu/rack/README.md +0 -0
  83. data/lib/shamu/rack/cookies.rb +115 -0
  84. data/lib/shamu/rack/cookies_middleware.rb +26 -0
  85. data/lib/shamu/rack/query_params.rb +41 -0
  86. data/lib/shamu/rack/query_params_middleware.rb +24 -0
  87. data/lib/shamu/rack.rb +12 -0
  88. data/lib/shamu/rails/controller.rb +131 -0
  89. data/lib/shamu/rails/entity.rb +168 -0
  90. data/lib/shamu/rails/features.rb +13 -0
  91. data/lib/shamu/rails/railtie.rb +30 -0
  92. data/lib/shamu/rails.rb +10 -0
  93. data/lib/shamu/rspec/matchers.rb +44 -0
  94. data/lib/shamu/rspec.rb +1 -0
  95. data/lib/shamu/security/README.md +0 -0
  96. data/lib/shamu/security/active_record_policy.rb +106 -0
  97. data/lib/shamu/security/error.rb +65 -0
  98. data/lib/shamu/security/hashed_value.rb +71 -0
  99. data/lib/shamu/security/no_policy.rb +15 -0
  100. data/lib/shamu/security/policy.rb +289 -0
  101. data/lib/shamu/security/policy_refinement.rb +50 -0
  102. data/lib/shamu/security/policy_rule.rb +59 -0
  103. data/lib/shamu/security/principal.rb +72 -0
  104. data/lib/shamu/security/roles.rb +62 -0
  105. data/lib/shamu/security/roles_service.rb +30 -0
  106. data/lib/shamu/security/support.rb +83 -0
  107. data/lib/shamu/security.rb +43 -0
  108. data/lib/shamu/services/README.md +2 -0
  109. data/lib/shamu/services/active_record.rb +58 -0
  110. data/lib/shamu/services/active_record_crud.rb +378 -0
  111. data/lib/shamu/services/error.rb +24 -0
  112. data/lib/shamu/services/lazy_association.rb +31 -0
  113. data/lib/shamu/services/lazy_transform.rb +97 -0
  114. data/lib/shamu/services/request.rb +122 -0
  115. data/lib/shamu/services/request_support.rb +124 -0
  116. data/lib/shamu/services/result.rb +75 -0
  117. data/lib/shamu/services/service.rb +355 -0
  118. data/lib/shamu/services.rb +12 -0
  119. data/lib/shamu/sessions/README.md +2 -0
  120. data/lib/shamu/sessions/cookie_store.rb +79 -0
  121. data/lib/shamu/sessions/session_store.rb +42 -0
  122. data/lib/shamu/sessions.rb +8 -0
  123. data/lib/shamu/to_bool_extension.rb +57 -0
  124. data/lib/shamu/to_model_id_extension.rb +50 -0
  125. data/lib/shamu/version.rb +10 -4
  126. data/lib/shamu.rb +18 -6
  127. data/shamu.gemspec +21 -10
  128. data/spec/internal/README.md +4 -0
  129. data/spec/internal/config/database.yml +3 -0
  130. data/spec/internal/config/routes.rb +3 -0
  131. data/spec/internal/db/schema.rb +3 -0
  132. data/spec/internal/log/.gitignore +1 -0
  133. data/spec/internal/public/favicon.ico +0 -0
  134. data/spec/lib/shamu/active_record_support.rb +32 -0
  135. data/spec/lib/shamu/attributes/assignment_spec.rb +129 -0
  136. data/spec/lib/shamu/attributes/equality_spec.rb +63 -0
  137. data/spec/lib/shamu/attributes/fluid_assignment_spec.rb +31 -0
  138. data/spec/lib/shamu/attributes/validation_spec.rb +53 -0
  139. data/spec/lib/shamu/attributes_spec.rb +331 -0
  140. data/spec/lib/shamu/auditing/logging_auditing_service_spec.rb +18 -0
  141. data/spec/lib/shamu/auditing/support_spec.rb +41 -0
  142. data/spec/lib/shamu/entities/active_record_soft_destroy_spec.rb +82 -0
  143. data/spec/lib/shamu/entities/active_record_spec.rb +66 -0
  144. data/spec/lib/shamu/entities/entity_path_spec.rb +40 -0
  145. data/spec/lib/shamu/entities/entity_spec.rb +56 -0
  146. data/spec/lib/shamu/entities/identity_cache_spec.rb +69 -0
  147. data/spec/lib/shamu/entities/list_scope/dates_spec.rb +47 -0
  148. data/spec/lib/shamu/entities/list_scope/paging_spec.rb +41 -0
  149. data/spec/lib/shamu/entities/list_scope/scoped_paging_spec.rb +40 -0
  150. data/spec/lib/shamu/entities/list_scope/sorting_spec.rb +59 -0
  151. data/spec/lib/shamu/entities/list_scope_spec.rb +127 -0
  152. data/spec/lib/shamu/entities/list_spec.rb +60 -0
  153. data/spec/lib/shamu/entities/null_entity_spec.rb +94 -0
  154. data/spec/lib/shamu/events/active_record/migration_spec.rb +11 -0
  155. data/spec/lib/shamu/events/active_record/service_spec.rb +139 -0
  156. data/spec/lib/shamu/events/events_service_spec.rb +57 -0
  157. data/spec/lib/shamu/events/in_memory/async_service_spec.rb +37 -0
  158. data/spec/lib/shamu/events/in_memory/service_spec.rb +36 -0
  159. data/spec/lib/shamu/events/message_spec.rb +7 -0
  160. data/spec/lib/shamu/events/support_spec.rb +44 -0
  161. data/spec/lib/shamu/features/conditions/condition_spec.rb +8 -0
  162. data/spec/lib/shamu/features/conditions/env_spec.rb +29 -0
  163. data/spec/lib/shamu/features/conditions/hosts_spec.rb +21 -0
  164. data/spec/lib/shamu/features/conditions/matching_spec.rb +23 -0
  165. data/spec/lib/shamu/features/conditions/percentage_spec.rb +71 -0
  166. data/spec/lib/shamu/features/conditions/proc_spec.rb +28 -0
  167. data/spec/lib/shamu/features/env_store_spec.rb +48 -0
  168. data/spec/lib/shamu/features/features.yml +34 -0
  169. data/spec/lib/shamu/features/features_service_spec.rb +109 -0
  170. data/spec/lib/shamu/features/secondary.yml +5 -0
  171. data/spec/lib/shamu/features/selector_spec.rb +17 -0
  172. data/spec/lib/shamu/features/support_spec.rb +45 -0
  173. data/spec/lib/shamu/features/toggle_codec_spec.rb +28 -0
  174. data/spec/lib/shamu/features/toggle_spec.rb +42 -0
  175. data/spec/lib/shamu/rack/cookies_middleware_spec.rb +33 -0
  176. data/spec/lib/shamu/rack/cookies_spec.rb +43 -0
  177. data/spec/lib/shamu/rack/query_params_middleware_spec.rb +33 -0
  178. data/spec/lib/shamu/rack/query_params_spec.rb +23 -0
  179. data/spec/lib/shamu/rails/controller_spec.rb +74 -0
  180. data/spec/lib/shamu/rails/entity_spec.rb +150 -0
  181. data/spec/lib/shamu/rails/features.yml +13 -0
  182. data/spec/lib/shamu/rails/features_spec.rb +45 -0
  183. data/spec/lib/shamu/security/active_record_policy_spec.rb +38 -0
  184. data/spec/lib/shamu/security/hashed_value_spec.rb +41 -0
  185. data/spec/lib/shamu/security/policy_refinement_spec.rb +61 -0
  186. data/spec/lib/shamu/security/policy_rule_spec.rb +60 -0
  187. data/spec/lib/shamu/security/policy_spec.rb +158 -0
  188. data/spec/lib/shamu/security/roles_spec.rb +46 -0
  189. data/spec/lib/shamu/services/active_record_crud_spec.rb +460 -0
  190. data/spec/lib/shamu/services/active_record_spec.rb +92 -0
  191. data/spec/lib/shamu/services/lazy_association_spec.rb +31 -0
  192. data/spec/lib/shamu/services/lazy_transform_spec.rb +96 -0
  193. data/spec/lib/shamu/services/request_spec.rb +58 -0
  194. data/spec/lib/shamu/services/request_support_spec.rb +129 -0
  195. data/spec/lib/shamu/services/result_spec.rb +37 -0
  196. data/spec/lib/shamu/services/service_spec.rb +307 -0
  197. data/spec/lib/shamu/sessions/cookie_store_spec.rb +44 -0
  198. data/spec/lib/shamu/to_bool_extension_spec.rb +67 -0
  199. data/spec/lib/shamu/to_model_id_extension_spec.rb +54 -0
  200. data/spec/rails_helper.rb +13 -0
  201. data/spec/spec_helper.rb +17 -12
  202. data/spec/support/active_record.rb +17 -0
  203. data/spec/support/database.rb +14 -0
  204. data/spec/support/logger.rb +0 -0
  205. metadata +383 -9
  206. data/spec/lib/shamu_spec.rb +0 -5
  207. /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: 17432a9ad613be127cf8fcd337ff0783499ce17f
4
- data.tar.gz: 9781a19889f10541dc79a2ff2d9be287c7bf5c79
3
+ metadata.gz: 27e560182b114ef221743131ca89ac18601cfbf7
4
+ data.tar.gz: c6fd668c63413a9d45cefe73b87a587240ee5c8c
5
5
  SHA512:
6
- metadata.gz: 0063e5b0ecec7d70a54b3131f923e04c944c946f4f42940fe081a53e36e31ccc95e7b5b01adc4eef123013b444c4d9a93aac504954fe44b98702ffe92cb5bb2f
7
- data.tar.gz: cb725d193fe76f76517b3a3d57dbf159154e8591c7cac18e681711690b5dc8bae71afb5cb4dd3844d7e552481f57990f83647eb85b25863b3b100e1610c15870
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
@@ -21,4 +21,5 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  .env
24
- *.sqlite
24
+ *.sqlite
25
+ test.db
data/.rubocop.yml CHANGED
@@ -1,62 +1,121 @@
1
- Style/LineLength:
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
- Style/AccessModifierIndentation:
5
- EnforceStyle: indent
21
+ Metrics/MethodLength:
22
+ Max: 15
6
23
 
7
- Style/IndentationConsistency:
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/TrailingBlankLines:
39
+ Style/CommentIndentation:
11
40
  Enabled: false
12
41
 
13
- Style/EmptyLinesAroundBody:
42
+ Style/EmptyLines:
14
43
  Enabled: false
15
44
 
16
- Style/StringLiterals:
45
+ Style/EmptyLinesAroundBlockBody:
17
46
  Enabled: false
18
47
 
19
- Style/SpaceInsideParens:
48
+ Style/EmptyLinesAroundClassBody:
20
49
  Enabled: false
21
50
 
22
- Style/SpaceBeforeBlockBraces:
51
+ Style/EmptyLinesAroundModuleBody:
23
52
  Enabled: false
24
53
 
25
- Style/SpaceInsideBlockBraces:
54
+ Style/DoubleNegation:
26
55
  Enabled: false
27
56
 
28
- Style/SpaceInsideBrackets:
57
+ Style/Documentation:
29
58
  Enabled: false
30
59
 
31
- Style/SingleLineBlockParams:
60
+ Style/GuardClause:
32
61
  Enabled: false
33
62
 
34
- Style/SingleSpaceBeforeFirstArg:
63
+ Style/HashSyntax:
35
64
  Enabled: false
36
65
 
37
- Style/TrailingComma:
66
+ Style/IndentArray:
38
67
  Enabled: false
39
68
 
40
- Style/SpaceAfterComma:
69
+ Style/IndentationConsistency:
41
70
  Enabled: false
42
71
 
43
- Style/ClassAndModuleChildren:
44
- EnforcedStyle: nested
72
+ Style/IndentationWidth:
73
+ Enabled: false
45
74
 
46
- Style/PercentLiteralDelimiters:
47
- PreferredDelimiters:
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
- Lint/AssignmentInCondition:
78
+ Style/MultilineBlockChain:
59
79
  Enabled: false
60
80
 
61
- Lint/AmbiguousRegexpLiteral:
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
@@ -1,7 +1,6 @@
1
- --protected
2
- --no-private
1
+ --markup markdown
3
2
  --no-cache
3
+ --no-private
4
+ --hide-api internal
4
5
  --hide-void-return
5
- --output-dir /tmp/shamu_docs
6
- --db /tmp/shamu_yardoc
7
- --markup markdown
6
+ --plugin activesupport-concern
data/Gemfile CHANGED
@@ -1,20 +1,32 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in shamu.gemspec
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 'guard', '~> 2.12.8'
9
- gem 'spring'
10
- gem 'byebug'
11
- gem 'pry-byebug'
12
- gem 'guard-rspec'
13
- gem 'fuubar'
14
- gem 'yard'
15
- gem 'simplecov', github: "colszowka/simplecov"
16
- gem 'ruby_gntp', '~> 0.3.4'
17
- gem 'awesome_print'
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
@@ -1,3 +1,8 @@
1
+ guard :rubocop, all_on_start: false, cli: [ "--display-cop-names", "--display-style-guide" ] do
2
+ watch( /lib\/.*\.rb$/ )
3
+ watch( /spec\/.*\.rb$/ )
4
+ end
5
+
1
6
  guard :rspec, cmd: "bundle exec rspec" do
2
7
  require "guard/rspec/dsl"
3
8
  dsl = Guard::RSpec::Dsl.new(self)
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
@@ -1,2 +1,14 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ desc "Run the specs"
4
+ task :specs do
5
+ system "rspec"
6
+ end
7
+
8
+ desc "Run linters on the codebase"
9
+ task :lint do
10
+ system "rubocop"
11
+ end
12
+
13
+ task :default => [ :lint, :specs ]
14
+ task :release => [ :default ]
data/circle.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  database:
2
2
  override:
3
- # We don't actually use a DB but it is included in the internal rails app
4
- # for specs. So override default behavior to do nothing
5
- - echo "Skip DB"
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 "rubygems"
2
+ require "bundler"
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! :all
7
+ run Combustion::Application
@@ -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