shamu 0.0.21 → 0.0.24

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.ruby-version +1 -1
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +70 -69
  6. data/app/README +1 -0
  7. data/config/environment.rb +1 -0
  8. data/lib/shamu/attributes.rb +26 -0
  9. data/lib/shamu/attributes/equality.rb +10 -1
  10. data/lib/shamu/entities/entity.rb +11 -0
  11. data/lib/shamu/entities/list_scope.rb +3 -0
  12. data/lib/shamu/entities/list_scope/sorting.rb +6 -1
  13. data/lib/shamu/entities/list_scope/window_paging.rb +1 -1
  14. data/lib/shamu/entities/null_entity.rb +18 -12
  15. data/lib/shamu/entities/opaque_id.rb +9 -8
  16. data/lib/shamu/error.rb +24 -3
  17. data/lib/shamu/events/active_record/migration.rb +0 -2
  18. data/lib/shamu/events/active_record/service.rb +3 -1
  19. data/lib/shamu/events/events_service.rb +2 -2
  20. data/lib/shamu/events/in_memory/async_service.rb +4 -2
  21. data/lib/shamu/events/in_memory/service.rb +3 -1
  22. data/lib/shamu/features/features_service.rb +3 -1
  23. data/lib/shamu/features/support.rb +1 -1
  24. data/lib/shamu/json_api/rails/controller.rb +1 -1
  25. data/lib/shamu/locale/en.yml +14 -2
  26. data/lib/shamu/security/active_record_policy.rb +2 -1
  27. data/lib/shamu/security/error.rb +1 -1
  28. data/lib/shamu/security/policy.rb +14 -4
  29. data/lib/shamu/security/principal.rb +22 -2
  30. data/lib/shamu/security/roles.rb +4 -3
  31. data/lib/shamu/services.rb +3 -1
  32. data/lib/shamu/services/active_record.rb +2 -1
  33. data/lib/shamu/services/active_record_crud.rb +43 -19
  34. data/lib/shamu/services/lazy_association.rb +50 -18
  35. data/lib/shamu/services/observable_support.rb +73 -0
  36. data/lib/shamu/services/observed_request.rb +76 -0
  37. data/lib/shamu/services/request.rb +12 -0
  38. data/lib/shamu/services/request_support.rb +24 -2
  39. data/lib/shamu/services/result.rb +62 -1
  40. data/lib/shamu/services/service.rb +58 -33
  41. data/lib/shamu/sessions/cookie_store.rb +3 -1
  42. data/lib/shamu/sessions/session_store.rb +2 -2
  43. data/lib/shamu/version.rb +1 -1
  44. data/shamu.gemspec +1 -1
  45. data/spec/lib/shamu/entities/entity_lookup_service_spec.rb +1 -1
  46. data/spec/lib/shamu/entities/list_scope/sorting_spec.rb +1 -1
  47. data/spec/lib/shamu/entities/null_entity_spec.rb +6 -1
  48. data/spec/lib/shamu/entities/opaque_id_spec.rb +13 -6
  49. data/spec/lib/shamu/entities/static_repository_spec.rb +2 -2
  50. data/spec/lib/shamu/rails/entity_spec.rb +1 -1
  51. data/spec/lib/shamu/rails/features_spec.rb +1 -1
  52. data/spec/lib/shamu/security/principal_spec.rb +25 -0
  53. data/spec/lib/shamu/services/active_record_crud_spec.rb +39 -4
  54. data/spec/lib/shamu/services/lazy_association_spec.rb +19 -6
  55. data/spec/lib/shamu/services/observable_support_spec.rb +55 -0
  56. data/spec/lib/shamu/services/observed_request_spec.rb +46 -0
  57. data/spec/lib/shamu/services/request_support_spec.rb +54 -3
  58. data/spec/lib/shamu/services/service_spec.rb +16 -27
  59. metadata +15 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cae4307a05211be596027da64335d8e7ea8a873
4
- data.tar.gz: 11c2070a6bab4b24e9770dbb6c92bd00f39b10ca
3
+ metadata.gz: 7021878c4a969d4191c47a51fd5833c4dbfac2ef
4
+ data.tar.gz: d1856e4d896fd0798bc297b3d2fc2647cff14492
5
5
  SHA512:
6
- metadata.gz: 626bd61e2a680af882d36bea800ce9229213e92dd0b1c474dd81aba7834768ea5659b87ec3294cdd59b077885a24a7869fa848b77eade04fa0971394f56a76fe
7
- data.tar.gz: 9b3bab05830afd1b09bb9662348a6e404d7b03e2e817407afb5d0b70e035a20a3f3e1358bbab4bdbadbe1e072c755382b933bcd2122a6a4ff296e85964501ace
6
+ metadata.gz: 5dd78cd63aac4c2547bc5d7c467a968ee0543f66eabfcb1025308c1d95cdce9b9e23c482d9ae7f2a180cabde51427fcf2429825fbe0e921a475f9098eeae673b
7
+ data.tar.gz: 97e94eafab8cf431c311b2feb9252e590b6af9b6f276e97a2ac034259f75d7de3b26a81309ba9fef648c17f4c30cc8c8851be5c385ebb4734fe98c21da236360
@@ -36,7 +36,7 @@ Metrics/LineLength:
36
36
  Max: 120
37
37
 
38
38
  Metrics/MethodLength:
39
- Max: 15
39
+ Max: 25
40
40
 
41
41
  Metrics/AbcSize:
42
42
  Max: 24
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.4.1
data/Gemfile CHANGED
@@ -11,7 +11,7 @@ group :test do
11
11
  gem "responders", "~> 2.1.2"
12
12
  gem "kaminari", "~> 0.16.3", require: false
13
13
 
14
- gem "byebug"
14
+ gem "byebug", "9.0.6"
15
15
  gem "pry-byebug"
16
16
 
17
17
  gem "sqlite3", "~> 1.3.11"
@@ -30,6 +30,8 @@ group :test do
30
30
  gem "ruby_gntp", "~> 0.3.4"
31
31
  gem "awesome_print"
32
32
 
33
+ gem "nokogiri", "1.8.0"
34
+
33
35
  gem "codeclimate-test-reporter", "~> 1.0 ", group: :test, require: nil
34
36
  gem "rspec_junit_formatter", "~> 0.2.2", platforms: :mri
35
37
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shamu (0.0.21)
4
+ shamu (0.0.24)
5
5
  activemodel (>= 5.0)
6
6
  activesupport (>= 5.0)
7
7
  crc32 (~> 1)
@@ -9,61 +9,62 @@ PATH
9
9
  loofah (~> 2)
10
10
  multi_json (~> 1.11)
11
11
  rack (>= 1)
12
- scorpion-ioc (~> 0.6)
12
+ scorpion-ioc (~> 1.0.1)
13
13
 
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- actioncable (5.0.3)
18
- actionpack (= 5.0.3)
17
+ actioncable (5.0.6)
18
+ actionpack (= 5.0.6)
19
19
  nio4r (>= 1.2, < 3.0)
20
20
  websocket-driver (~> 0.6.1)
21
- actionmailer (5.0.3)
22
- actionpack (= 5.0.3)
23
- actionview (= 5.0.3)
24
- activejob (= 5.0.3)
21
+ actionmailer (5.0.6)
22
+ actionpack (= 5.0.6)
23
+ actionview (= 5.0.6)
24
+ activejob (= 5.0.6)
25
25
  mail (~> 2.5, >= 2.5.4)
26
26
  rails-dom-testing (~> 2.0)
27
- actionpack (5.0.3)
28
- actionview (= 5.0.3)
29
- activesupport (= 5.0.3)
27
+ actionpack (5.0.6)
28
+ actionview (= 5.0.6)
29
+ activesupport (= 5.0.6)
30
30
  rack (~> 2.0)
31
31
  rack-test (~> 0.6.3)
32
32
  rails-dom-testing (~> 2.0)
33
33
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
- actionview (5.0.3)
35
- activesupport (= 5.0.3)
34
+ actionview (5.0.6)
35
+ activesupport (= 5.0.6)
36
36
  builder (~> 3.1)
37
37
  erubis (~> 2.7.0)
38
38
  rails-dom-testing (~> 2.0)
39
39
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
40
- activejob (5.0.3)
41
- activesupport (= 5.0.3)
40
+ activejob (5.0.6)
41
+ activesupport (= 5.0.6)
42
42
  globalid (>= 0.3.6)
43
- activemodel (5.0.3)
44
- activesupport (= 5.0.3)
45
- activerecord (5.0.3)
46
- activemodel (= 5.0.3)
47
- activesupport (= 5.0.3)
43
+ activemodel (5.0.6)
44
+ activesupport (= 5.0.6)
45
+ activerecord (5.0.6)
46
+ activemodel (= 5.0.6)
47
+ activesupport (= 5.0.6)
48
48
  arel (~> 7.0)
49
- activesupport (5.0.3)
49
+ activesupport (5.0.6)
50
50
  concurrent-ruby (~> 1.0, >= 1.0.2)
51
51
  i18n (~> 0.7)
52
52
  minitest (~> 5.1)
53
53
  tzinfo (~> 1.1)
54
54
  arel (7.1.4)
55
55
  ast (2.3.0)
56
- awesome_print (1.7.0)
56
+ awesome_print (1.8.0)
57
57
  builder (3.2.3)
58
58
  byebug (9.0.6)
59
59
  codeclimate-test-reporter (1.0.7)
60
60
  simplecov
61
- coderay (1.1.1)
62
- combustion (0.6.0)
61
+ coderay (1.1.2)
62
+ combustion (0.7.0)
63
63
  activesupport (>= 3.0.0)
64
64
  railties (>= 3.0.0)
65
65
  thor (>= 0.14.6)
66
66
  concurrent-ruby (1.0.5)
67
+ crass (1.0.2)
67
68
  crc32 (1.0.1)
68
69
  diff-lcs (1.3)
69
70
  docile (1.1.5)
@@ -89,10 +90,10 @@ GEM
89
90
  guard (~> 2.1)
90
91
  guard-compat (~> 1.1)
91
92
  rspec (>= 2.99.0, < 4.0)
92
- guard-rubocop (1.2.0)
93
+ guard-rubocop (1.3.0)
93
94
  guard (~> 2.0)
94
95
  rubocop (~> 0.20)
95
- i18n (0.8.1)
96
+ i18n (0.8.6)
96
97
  json (2.1.0)
97
98
  kaminari (0.16.3)
98
99
  actionpack (>= 3.0.0)
@@ -101,68 +102,68 @@ GEM
101
102
  rb-fsevent (~> 0.9, >= 0.9.4)
102
103
  rb-inotify (~> 0.9, >= 0.9.7)
103
104
  ruby_dep (~> 1.2)
104
- loofah (2.0.3)
105
+ loofah (2.1.1)
106
+ crass (~> 1.0.2)
105
107
  nokogiri (>= 1.5.9)
106
108
  lumberjack (1.0.12)
107
109
  mail (2.6.6)
108
110
  mime-types (>= 1.16, < 4)
109
- method_source (0.8.2)
111
+ method_source (0.9.0)
110
112
  mime-types (3.1)
111
113
  mime-types-data (~> 3.2015)
112
114
  mime-types-data (3.2016.0521)
113
- mini_portile2 (2.1.0)
114
- minitest (5.10.2)
115
- multi_json (1.12.1)
115
+ mini_portile2 (2.2.0)
116
+ minitest (5.10.3)
117
+ multi_json (1.12.2)
116
118
  nenv (0.3.0)
117
119
  nio4r (2.1.0)
118
- nokogiri (1.7.2)
119
- mini_portile2 (~> 2.1.0)
120
+ nokogiri (1.8.0)
121
+ mini_portile2 (~> 2.2.0)
120
122
  notiffany (0.1.1)
121
123
  nenv (~> 0.1)
122
124
  shellany (~> 0.0)
123
- parallel (1.11.2)
125
+ parallel (1.12.0)
124
126
  parser (2.4.0.0)
125
127
  ast (~> 2.2)
126
128
  powerpack (0.1.1)
127
- pry (0.10.4)
129
+ pry (0.11.1)
128
130
  coderay (~> 1.1.0)
129
- method_source (~> 0.8.1)
130
- slop (~> 3.4)
131
- pry-byebug (3.4.2)
132
- byebug (~> 9.0)
131
+ method_source (~> 0.9.0)
132
+ pry-byebug (3.4.3)
133
+ byebug (>= 9.0, < 9.1)
133
134
  pry (~> 0.10)
134
135
  rack (2.0.3)
135
136
  rack-test (0.6.3)
136
137
  rack (>= 1.0)
137
- rails (5.0.3)
138
- actioncable (= 5.0.3)
139
- actionmailer (= 5.0.3)
140
- actionpack (= 5.0.3)
141
- actionview (= 5.0.3)
142
- activejob (= 5.0.3)
143
- activemodel (= 5.0.3)
144
- activerecord (= 5.0.3)
145
- activesupport (= 5.0.3)
146
- bundler (>= 1.3.0, < 2.0)
147
- railties (= 5.0.3)
138
+ rails (5.0.6)
139
+ actioncable (= 5.0.6)
140
+ actionmailer (= 5.0.6)
141
+ actionpack (= 5.0.6)
142
+ actionview (= 5.0.6)
143
+ activejob (= 5.0.6)
144
+ activemodel (= 5.0.6)
145
+ activerecord (= 5.0.6)
146
+ activesupport (= 5.0.6)
147
+ bundler (>= 1.3.0)
148
+ railties (= 5.0.6)
148
149
  sprockets-rails (>= 2.0.0)
149
150
  rails-dom-testing (2.0.3)
150
151
  activesupport (>= 4.2.0)
151
152
  nokogiri (>= 1.6)
152
153
  rails-html-sanitizer (1.0.3)
153
154
  loofah (~> 2.0)
154
- railties (5.0.3)
155
- actionpack (= 5.0.3)
156
- activesupport (= 5.0.3)
155
+ railties (5.0.6)
156
+ actionpack (= 5.0.6)
157
+ activesupport (= 5.0.6)
157
158
  method_source
158
159
  rake (>= 0.8.7)
159
160
  thor (>= 0.18.1, < 2.0)
160
161
  rainbow (2.2.2)
161
162
  rake
162
- rake (12.0.0)
163
- rb-fsevent (0.9.8)
164
- rb-inotify (0.9.8)
165
- ffi (>= 0.5.0)
163
+ rake (12.1.0)
164
+ rb-fsevent (0.10.2)
165
+ rb-inotify (0.9.10)
166
+ ffi (>= 0.5.0, < 2)
166
167
  responders (2.1.2)
167
168
  railties (>= 4.2.0, < 5.1)
168
169
  rspec (3.6.0)
@@ -180,7 +181,7 @@ GEM
180
181
  rspec-mocks (3.6.0)
181
182
  diff-lcs (>= 1.2.0, < 2.0)
182
183
  rspec-support (~> 3.6.0)
183
- rspec-rails (3.6.0)
184
+ rspec-rails (3.6.1)
184
185
  actionpack (>= 3.0)
185
186
  activesupport (>= 3.0)
186
187
  railties (>= 3.0)
@@ -201,33 +202,32 @@ GEM
201
202
  rainbow (>= 1.99.1, < 3.0)
202
203
  ruby-progressbar (~> 1.7)
203
204
  unicode-display_width (~> 1.0, >= 1.0.1)
204
- ruby-progressbar (1.8.1)
205
+ ruby-progressbar (1.9.0)
205
206
  ruby_dep (1.5.0)
206
207
  ruby_gntp (0.3.4)
207
- scorpion-ioc (0.6.0)
208
+ scorpion-ioc (1.0.1)
208
209
  rails (>= 4.0)
209
210
  shellany (0.0.1)
210
- simplecov (0.14.1)
211
+ simplecov (0.15.1)
211
212
  docile (~> 1.1.0)
212
213
  json (>= 1.8, < 3)
213
214
  simplecov-html (~> 0.10.0)
214
- simplecov-html (0.10.1)
215
- slop (3.6.0)
216
- spring (2.0.1)
215
+ simplecov-html (0.10.2)
216
+ spring (2.0.2)
217
217
  activesupport (>= 4.2)
218
218
  sprockets (3.7.1)
219
219
  concurrent-ruby (~> 1.0)
220
220
  rack (> 1, < 3)
221
- sprockets-rails (3.2.0)
221
+ sprockets-rails (3.2.1)
222
222
  actionpack (>= 4.0)
223
223
  activesupport (>= 4.0)
224
224
  sprockets (>= 3.0.0)
225
225
  sqlite3 (1.3.13)
226
- thor (0.19.4)
226
+ thor (0.20.0)
227
227
  thread_safe (0.3.6)
228
228
  tzinfo (1.2.3)
229
229
  thread_safe (~> 0.1)
230
- unicode-display_width (1.2.1)
230
+ unicode-display_width (1.3.0)
231
231
  websocket-driver (0.6.5)
232
232
  websocket-extensions (>= 0.1.0)
233
233
  websocket-extensions (0.1.2)
@@ -243,7 +243,7 @@ DEPENDENCIES
243
243
  activerecord (~> 5.0)
244
244
  awesome_print
245
245
  bundler (~> 1.6)
246
- byebug
246
+ byebug (= 9.0.6)
247
247
  codeclimate-test-reporter (~> 1.0)
248
248
  combustion (~> 0.5)
249
249
  fuubar
@@ -252,6 +252,7 @@ DEPENDENCIES
252
252
  guard-rubocop
253
253
  i18n (~> 0.7)
254
254
  kaminari (~> 0.16.3)
255
+ nokogiri (= 1.8.0)
255
256
  pry-byebug
256
257
  rake
257
258
  responders (~> 2.1.2)
@@ -270,4 +271,4 @@ DEPENDENCIES
270
271
  yard-activesupport-concern
271
272
 
272
273
  BUNDLED WITH
273
- 1.14.6
274
+ 1.15.3
@@ -0,0 +1 @@
1
+ Here to make vim-rails work
@@ -0,0 +1 @@
1
+ # Dummy file to make vim-rails work
@@ -76,6 +76,32 @@ module Shamu
76
76
  instance_variable_defined? :"@#{ attribute }"
77
77
  end
78
78
 
79
+ # @return [Hash] the assigned attributes as a hash for JSON serialization.
80
+ def as_json( options = {} ) # rubocop:disable Styles/OptionHash
81
+ to_attributes( options.slice( :only, :except ) ).as_json
82
+ end
83
+
84
+ # @return [String] JSON encoded version of the assigned attributes.
85
+ def to_json( options = {} ) # rubocop:disable Styles/OptionHash
86
+ as_json( options ).to_json
87
+ end
88
+
89
+ def pretty_print( pp )
90
+ attributes = to_attributes
91
+
92
+ pp.object_address_group( self ) do
93
+ pp.seplist( attributes.keys, -> { pp.text "," } ) do |name|
94
+ pp.breakable " "
95
+ pp.group( 1 ) do
96
+ pp.text name.to_s
97
+ pp.text ":"
98
+ pp.breakable " "
99
+ pp.pp attributes[ name ]
100
+ end
101
+ end
102
+ end
103
+ end
104
+
79
105
  private
80
106
 
81
107
  def match_attribute?( pattern, name )
@@ -12,6 +12,7 @@ module Shamu
12
12
  # @return [Boolean] true if the two objects are of the same type and
13
13
  # attributes are all eql? to each other.
14
14
  def ==( other )
15
+ return true if other.object_id == object_id
15
16
  return false unless other.is_a?( self.class ) || is_a?( other.class )
16
17
  attributes_eql?( other )
17
18
  end
@@ -31,10 +32,18 @@ module Shamu
31
32
  def attributes_eql?( other )
32
33
  self.class.attributes.all? do |key, attr|
33
34
  next true if attr[:ignore_equality]
34
- send( key ).eql?( other.send( key ) )
35
+ attribute_eql?( other, key )
35
36
  end
36
37
  end
37
38
 
39
+ # @param [Object] other the other object.
40
+ # @param [Symbol] attr the name of the other attribute.
41
+ # @return [Boolean] true if the value of the given attribute is equal
42
+ # on the current object and the other object.
43
+ def attribute_eql?( other, attr )
44
+ send( attr ).eql?( other.send( attr ) )
45
+ end
46
+
38
47
  end
39
48
  end
40
49
  end
@@ -143,6 +143,17 @@ module Shamu
143
143
  super && !options[:model]
144
144
  end
145
145
 
146
+ def attribute_eql?( other, name )
147
+ value = send( name )
148
+ other_value = other.send( name )
149
+
150
+ if value.is_a?( Entity ) || other_value.is_a?( Entity )
151
+ return value.id.eql?( other_value.id )
152
+ else
153
+ value.eql?( other_value )
154
+ end
155
+ end
156
+
146
157
  class << self
147
158
 
148
159
  # @return [ActiveModel::Name] used by url_helpers etc when generating
@@ -87,6 +87,9 @@ module Shamu
87
87
  name = base_name.sub /(Entity)?$/, "ListScope"
88
88
  begin
89
89
  return name.constantize
90
+
91
+ # Rescuing instead of using const_defined? so that active record can
92
+ # do it's auto-loading magic.
90
93
  rescue NameError # rubocop:disable Lint/HandleExceptions
91
94
  end
92
95
 
@@ -42,7 +42,12 @@ module Shamu
42
42
  def self.included( base )
43
43
  super
44
44
 
45
- base.attribute :sort_by, as: :order, coerce: ->( *values ) { parse_sort_by( values ) }
45
+ base.attribute :default_sort_by, as: :default_order,
46
+ coerce: ->( *values ) { parse_sort_by( values ) }
47
+
48
+ base.attribute :sort_by, as: :order,
49
+ coerce: ->( *values ) { parse_sort_by( values ) },
50
+ default: ->() { default_sort_by }
46
51
  end
47
52
 
48
53
  # @return [Boolean] true if the scope is paged.
@@ -35,7 +35,7 @@ module Shamu
35
35
  #
36
36
  # @!endgroup Attributes
37
37
 
38
- def self.included( base ) # rubocop:disable Metrics/MethodLength
38
+ def self.included( base )
39
39
  super
40
40
 
41
41
  base.attribute :first, coerce: :to_i, default: ->() { default_first }
@@ -50,15 +50,21 @@ module Shamu
50
50
  AUTO_FORMATTED_ATTRIBUTES.each do |attr|
51
51
  next unless base.attributes.key?( attr )
52
52
 
53
- base_name ||= begin
54
- name = base.name || "Resource"
55
- name.split( "::" )
56
- .last
57
- .sub( /Entity/, "" )
58
- .gsub( /(.)([[:upper:]])/, '\1 \2' )
59
- end
53
+ base_name ||=
54
+ begin
55
+ name = base.superclass.name || "Resource"
56
+ name.split( "::" )
57
+ .last
58
+ .sub( /Entity/, "" )
59
+ .gsub( /(.)([[:upper:]])/, '\1 \2' )
60
+ end
60
61
  base.attribute attr, default: "Unknown #{ base_name }"
61
62
  end
63
+
64
+ # Make sure the null version has the model name.
65
+ def base.model_name
66
+ superclass.model_name
67
+ end
62
68
  end
63
69
 
64
70
  # Dynamically generate a new null entity class.
@@ -73,11 +79,11 @@ module Shamu
73
79
  end
74
80
 
75
81
  unless null_klass
76
- null_klass = Class.new( entity_class ) do
77
- include ::Shamu::Entities::NullEntity
78
- end
79
-
82
+ null_klass = Class.new( entity_class )
80
83
  entity_class.const_set :NullEntity, null_klass
84
+
85
+ # After const_set so we have name and inheritance
86
+ null_klass.include ::Shamu::Entities::NullEntity
81
87
  end
82
88
 
83
89
  null_klass
@@ -85,4 +91,4 @@ module Shamu
85
91
 
86
92
  end
87
93
  end
88
- end
94
+ end