fedux_org-stdlib 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,25 +46,6 @@ module FeduxOrg
46
46
  '.rb'
47
47
  end
48
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
-
68
49
  def load_from_filesystem
69
50
  files = find_files
70
51
 
@@ -46,9 +46,28 @@ module FeduxOrg
46
46
  raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented, "Please defined the method \"path\" to make the library work."
47
47
  end
48
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 suffix and path !~/#{suffix}/
58
+ next if path =~ /^\.\.?/
59
+ next if path =~ %r{#{ignore}}
60
+
61
+ files << path
62
+ end
63
+
64
+ files
65
+ rescue
66
+ raise FeduxOrg::Stdlib::Models::Exceptions::NoImplementationsForModelFound, "You might need to create the directory\"#{File.dirname(path_to_instances)}\"."
67
+ end
68
+
49
69
  def path_to_instances
50
- local_path = ::File.expand_path("../../#{model_name.pluralize.underscore}", path )
51
- return_path = ::File.join(local_path,"*#{suffix}")
70
+ return_path = ::File.expand_path("../../#{model_name.pluralize.underscore}", path )
52
71
 
53
72
  FeduxOrg::Stdlib.logger.debug(self) { "Path to instances of model: #{return_path}" }
54
73
 
@@ -1,6 +1,6 @@
1
1
  #main FeduxOrg
2
2
  module FeduxOrg
3
3
  module Stdlib
4
- VERSION = '0.0.16'
4
+ VERSION = '0.0.17'
5
5
  end
6
6
  end
@@ -300,11 +300,6 @@ describe Models::ClassBasedModel do
300
300
  expect( result ).to eq( expect_result )
301
301
  end
302
302
 
303
- it "returns the path to instances" do
304
- expected_result= File.join( examples_dir, 'test_class_for_filesystems', '*.rb' )
305
- expect( Test123::Models::TestClassForFilesystem.send(:path_to_instances) ).to eq( expected_result )
306
- end
307
-
308
303
  it "returns the name for the instance based on the path to the ruby file" do
309
304
  expect( Test123::Models::TestClassForFilesystem.send(:name, Test123::Models::TestClassForFilesystem.send( :path ) ) ).to eq( :class_based )
310
305
  end
@@ -24,19 +24,6 @@ describe Models::FilesystemBasedModel do
24
24
  end
25
25
  end
26
26
 
27
- it "returns a string of all active filters" do
28
- @model.create(:name1)
29
- @model.create(:name2)
30
- @model.enable :name1
31
- @model.enable :name2
32
-
33
- result = @model.all_names_as_string(", ")
34
- expect(result).to eq("name1, name2")
35
-
36
- result = @model.all_names_as_string
37
- expect(result).to eq("name1, name2")
38
- end
39
-
40
27
  it "finds all available filter" do
41
28
  @model.init
42
29
  filter = @model.find(:hello)
@@ -100,7 +87,51 @@ describe Models::FilesystemBasedModel do
100
87
  expect( Test123::Models::TestClassForFilesystem.send(:model_name) ).to eq('TestClassForFilesystem')
101
88
  end
102
89
 
103
- it "returns the library name" do
104
- expect( Test123::Models::TestClassForFilesystem.send(:library_name) ).to eq('Test123')
90
+ context "#library_name" do
91
+ it "returns the library name" do
92
+ expect( Test123::Models::TestClassForFilesystem.send(:library_name) ).to eq('Test123')
93
+ end
94
+ end
95
+
96
+ context "#path_to_instances" do
97
+ klass = Class.new( FeduxOrg::Stdlib::Models::BaseModel ) do
98
+ include FeduxOrg::Stdlib::Models::FilesystemBasedModel
99
+
100
+ def self.model_name
101
+ 'FindFiles'
102
+ end
103
+
104
+ def self.path
105
+ File.join( examples_dir, 'models', 'filesystem_based', 'find_files')
106
+ end
107
+
108
+ end
109
+
110
+ it "returns the path to the instances" do
111
+ expect( klass.send(:path_to_instances) ).to eq( File.join( examples_dir, 'models', 'find_files') )
112
+ end
113
+ end
114
+
115
+ context "#find_files" do
116
+ klass = Class.new( FeduxOrg::Stdlib::Models::BaseModel ) do
117
+ include FeduxOrg::Stdlib::Models::FilesystemBasedModel
118
+
119
+ def self.path_to_instances
120
+ File.join( examples_dir, 'models', 'filesystem_based', 'find_files')
121
+ end
122
+
123
+ def self.suffix
124
+ '.rb'
125
+ end
126
+ end
127
+
128
+ it "search for available instances in filesystem" do
129
+ expect( klass.send(:find_files) ).to eq(
130
+ [
131
+ "/home/d/work/projects/fedux_org-stdlib/spec/examples/models/filesystem_based/find_files/abc.rb",
132
+ "/home/d/work/projects/fedux_org-stdlib/spec/examples/models/filesystem_based/find_files/cde.rb",
133
+ ]
134
+ )
135
+ end
105
136
  end
106
137
  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.16
4
+ version: 0.0.17
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-07-02 00:00:00.000000000 Z
12
+ date: 2013-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -122,6 +122,8 @@ files:
122
122
  - spec/examples/models/class_based/invalid_3.rb
123
123
  - spec/examples/models/class_based/valid_1.rb
124
124
  - spec/examples/models/class_based/valid_2.rb
125
+ - spec/examples/models/filesystem_based/find_files/abc.rb
126
+ - spec/examples/models/filesystem_based/find_files/cde.rb
125
127
  - spec/models/base_model_spec.rb
126
128
  - spec/models/class_based_model_spec.rb
127
129
  - spec/models/filesystem_based_model_spec.rb
@@ -160,6 +162,8 @@ test_files:
160
162
  - spec/examples/models/class_based/invalid_3.rb
161
163
  - spec/examples/models/class_based/valid_1.rb
162
164
  - spec/examples/models/class_based/valid_2.rb
165
+ - spec/examples/models/filesystem_based/find_files/abc.rb
166
+ - spec/examples/models/filesystem_based/find_files/cde.rb
163
167
  - spec/models/base_model_spec.rb
164
168
  - spec/models/class_based_model_spec.rb
165
169
  - spec/models/filesystem_based_model_spec.rb