fedux_org-stdlib 0.0.14 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require 'active_support/core_ext/string/inflections'
2
2
  require 'active_support/core_ext/object/blank'
3
3
  require 'fedux_org/stdlib/models/filesystem_based_model'
4
+ require 'find'
4
5
 
5
6
  module FeduxOrg
6
7
  module Stdlib
@@ -28,15 +29,13 @@ module FeduxOrg
28
29
  end
29
30
 
30
31
  def check_klass( klass , *methods)
31
- methods.flatten.each do |m|
32
- raise exception_for_model, "A valid \"#{model_name}\"-class needs to respond to \"#{ m }\"." unless klass.new.respond_to? m
33
- end
32
+ raise exception_for_model, "A valid \"#{model_name}\"-class needs to respond to \"#{ methods.flatten.join(", ") }\"." unless methods.flatten.all? { |m| klass.new.respond_to? m }
34
33
  end
35
34
 
36
35
  def build_class_constant(name)
37
36
  "#{library_name}::#{model_name.pluralize}::#{name.to_s.camelcase}".constantize
38
37
  rescue
39
- raise exception_for_model , "The filename needs to be snakecase and needs to be convertible to the action class name: filename in camelcase."
38
+ raise exception_for_model , "Class \"#{library_name}::#{model_name.pluralize}::#{name.to_s.camelcase}\" cannot be found in file \"#{require_path(name)}\"."
40
39
  end
41
40
 
42
41
  def check_method
@@ -47,8 +46,28 @@ module FeduxOrg
47
46
  '.rb'
48
47
  end
49
48
 
49
+ def ignore
50
+ 'BORING_STRING_WHICH_SHOULD_NEVER_MATCH'
51
+ end
52
+
53
+ def find_files
54
+ files = []
55
+ Find.find(path_to_instances) do |path|
56
+ next unless File.file? path
57
+ next if path =~ /^\.\.?/
58
+ next if path =~ %r{#{ignore}}
59
+
60
+ files << path
61
+ end
62
+
63
+ files
64
+ rescue
65
+ raise FeduxOrg::Stdlib::Models::Exceptions::NoImplementationsForModelFound, "You might need to create the directory\"#{File.dirname(path_to_instances)}\"."
66
+ end
67
+
50
68
  def load_from_filesystem
51
- files = Dir.glob( path_to_instances )
69
+ files = find_files
70
+
52
71
  FeduxOrg::Stdlib.logger.debug(self) { "Files found at path \"#{path_to_instances}\": #{ files.join(", ") }" }
53
72
 
54
73
  raise FeduxOrg::Stdlib::Models::Exceptions::NoImplementationsForModelFound, "You might need to store files at \"#{File.dirname(path_to_instances)}\" to make the library work." if files.blank?
@@ -1,6 +1,6 @@
1
1
  #main FeduxOrg
2
2
  module FeduxOrg
3
3
  module Stdlib
4
- VERSION = '0.0.14'
4
+ VERSION = '0.0.16'
5
5
  end
6
6
  end
@@ -0,0 +1,8 @@
1
+ module TestIt
2
+ module TestClasses
3
+ class Valid1
4
+ def req_method
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module TestIt
2
+ module TestClasses
3
+ class Valid1
4
+ def req_method1
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module TestIt
2
+ module TestClasses
3
+ class Valid2
4
+ def req_method1
5
+ end
6
+ def req_method2
7
+ end
8
+ end
9
+ end
10
+ end
@@ -98,7 +98,6 @@ describe Models::ClassBasedModel do
98
98
  expect(test_class.all.first.name).to eq(:valid_1)
99
99
  end
100
100
 
101
-
102
101
  it "raises an error if an instance is invalid: name error" do
103
102
  test_class = Class.new(Models::BaseModel) do
104
103
  include Models::FilesystemBasedModel
@@ -173,41 +172,117 @@ describe Models::ClassBasedModel do
173
172
  }.to raise_error FeduxOrg::Stdlib::Models::Exceptions::UnauthorizedUseOfKeyword
174
173
  end
175
174
 
176
- it "raises an error if an import filter is invalid: missing method" do
177
- test_class = Class.new(Models::BaseModel) do
178
- include Models::FilesystemBasedModel
179
- include Models::ClassBasedModel
175
+ context "#check_method" do
176
+ it "raises an error if an import filter is invalid: missing method" do
177
+ test_class = Class.new(Models::BaseModel) do
178
+ include Models::FilesystemBasedModel
179
+ include Models::ClassBasedModel
180
180
 
181
- def initialize(name, klass)
182
- super(name)
181
+ def initialize(name, klass)
182
+ super(name)
183
183
 
184
- @klass = klass
185
- end
184
+ @klass = klass
185
+ end
186
186
 
187
- def self.model_name
188
- "TestClass"
189
- end
187
+ def self.model_name
188
+ "TestClass"
189
+ end
190
190
 
191
- def self.library_name
192
- 'TestIt'
193
- end
191
+ def self.library_name
192
+ 'TestIt'
193
+ end
194
194
 
195
- def self.path_to_instances
196
- File.join( examples_dir, 'models', 'class_based', 'invalid_2.rb' )
197
- end
195
+ def self.path_to_instances
196
+ File.join( examples_dir, 'models', 'class_based', 'invalid_2.rb' )
197
+ end
198
198
 
199
- def self.require_path(name)
200
- File.join( examples_dir, 'models', 'class_based', 'invalid_2' )
199
+ def self.require_path(name)
200
+ File.join( examples_dir, 'models', 'class_based', 'invalid_2' )
201
+ end
202
+
203
+ def self.check_method
204
+ :req_method
205
+ end
201
206
  end
202
207
 
203
- def self.check_method
204
- :req_method
208
+ expect {
209
+ test_class.init
210
+ }.to raise_error TestIt::Exceptions::InvalidTestClass
211
+ end
212
+
213
+ it "supports multiple methods to check for invalid instance and succeeds if both are avaiable." do
214
+ test_class = Class.new(Models::BaseModel) do
215
+ include Models::FilesystemBasedModel
216
+ include Models::ClassBasedModel
217
+
218
+ def initialize(name, klass)
219
+ super(name)
220
+
221
+ @klass = klass
222
+ end
223
+
224
+ def self.model_name
225
+ "TestClass"
226
+ end
227
+
228
+ def self.library_name
229
+ 'TestIt'
230
+ end
231
+
232
+ def self.path_to_instances
233
+ File.join( examples_dir, 'models', 'class_based', 'valid_2.rb' )
234
+ end
235
+
236
+ def self.require_path(name)
237
+ File.join( examples_dir, 'models', 'class_based', 'valid_2' )
238
+ end
239
+
240
+ def self.check_method
241
+ [ :req_method1, :req_method2 ]
242
+ end
205
243
  end
244
+
245
+ expect {
246
+ test_class.init
247
+ }.to_not raise_error TestIt::Exceptions::InvalidTestClass
206
248
  end
207
249
 
208
- expect {
209
- test_class.init
210
- }.to raise_error TestIt::Exceptions::InvalidTestClass
250
+ it "supports multiple methods to check for invalid instance and fails if one is missing." do
251
+ test_class = Class.new(Models::BaseModel) do
252
+ include Models::FilesystemBasedModel
253
+ include Models::ClassBasedModel
254
+
255
+ def initialize(name, klass)
256
+ super(name)
257
+
258
+ @klass = klass
259
+ end
260
+
261
+ def self.model_name
262
+ "TestClass"
263
+ end
264
+
265
+ def self.library_name
266
+ 'TestIt'
267
+ end
268
+
269
+ def self.path_to_instances
270
+ File.join( examples_dir, 'models', 'class_based', 'invalid_3.rb' )
271
+ end
272
+
273
+ def self.require_path(name)
274
+ File.join( examples_dir, 'models', 'class_based', 'invalid_3' )
275
+ end
276
+
277
+ def self.check_method
278
+ [ :req_method1, :req_method2 ]
279
+ end
280
+ end
281
+
282
+ expect {
283
+ test_class.init
284
+ }.to raise_error TestIt::Exceptions::InvalidTestClass
285
+ end
211
286
  end
212
287
 
213
288
  it "returns the require path" do
@@ -262,4 +337,45 @@ describe Models::ClassBasedModel do
262
337
  }.to raise_error FeduxOrg::Stdlib::Models::Exceptions::NoImplementationsForModelFound
263
338
  end
264
339
 
340
+ it "#ignore" do
341
+ test_class = Class.new(Models::BaseModel) do
342
+ include Models::FilesystemBasedModel
343
+ include Models::ClassBasedModel
344
+
345
+ def initialize(name, klass)
346
+ super(name)
347
+
348
+ @klass = klass
349
+ end
350
+
351
+ def self.model_name
352
+ "TestClass"
353
+ end
354
+
355
+ def self.library_name
356
+ 'TestIt'
357
+ end
358
+
359
+ def self.path_to_instances
360
+ File.join( examples_dir, 'models', 'class_based', 'ignore' )
361
+ end
362
+
363
+ def self.require_path(name)
364
+ File.join( examples_dir, 'models', 'class_based', 'ignore', 'valid_1.rb' )
365
+ end
366
+
367
+ def self.check_method
368
+ :req_method
369
+ end
370
+
371
+ def self.ignore
372
+ 'ignored'
373
+ end
374
+ end
375
+
376
+ test_class.init
377
+ expect(test_class.all.count).to eq(1)
378
+
379
+ end
380
+
265
381
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-27 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -115,9 +115,13 @@ files:
115
115
  - script/console
116
116
  - script/terminal
117
117
  - spec/examples/models/class_based/forbidden_keyword.rb
118
+ - spec/examples/models/class_based/ignore/ignored.rb
119
+ - spec/examples/models/class_based/ignore/valid_1.rb
118
120
  - spec/examples/models/class_based/invalid_1.rb
119
121
  - spec/examples/models/class_based/invalid_2.rb
122
+ - spec/examples/models/class_based/invalid_3.rb
120
123
  - spec/examples/models/class_based/valid_1.rb
124
+ - spec/examples/models/class_based/valid_2.rb
121
125
  - spec/models/base_model_spec.rb
122
126
  - spec/models/class_based_model_spec.rb
123
127
  - spec/models/filesystem_based_model_spec.rb
@@ -149,9 +153,13 @@ specification_version: 3
149
153
  summary: collection of use full libraries
150
154
  test_files:
151
155
  - spec/examples/models/class_based/forbidden_keyword.rb
156
+ - spec/examples/models/class_based/ignore/ignored.rb
157
+ - spec/examples/models/class_based/ignore/valid_1.rb
152
158
  - spec/examples/models/class_based/invalid_1.rb
153
159
  - spec/examples/models/class_based/invalid_2.rb
160
+ - spec/examples/models/class_based/invalid_3.rb
154
161
  - spec/examples/models/class_based/valid_1.rb
162
+ - spec/examples/models/class_based/valid_2.rb
155
163
  - spec/models/base_model_spec.rb
156
164
  - spec/models/class_based_model_spec.rb
157
165
  - spec/models/filesystem_based_model_spec.rb