fedux_org-stdlib 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.simplecov +6 -4
- data/lib/fedux_org/stdlib/models/class_based_model.rb +1 -1
- data/lib/fedux_org/stdlib/models/filesystem_based_model.rb +7 -3
- data/lib/fedux_org/stdlib/version.rb +1 -1
- data/spec/models/base_model_spec.rb +16 -0
- data/spec/models/class_based_model_spec.rb +58 -0
- data/spec/models/filesystem_based_model_spec.rb +1 -0
- metadata +2 -2
data/.simplecov
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
SimpleCov.start do
|
2
2
|
add_filter "/features/"
|
3
3
|
add_filter "/spec/"
|
4
|
-
add_group "
|
5
|
-
add_group "
|
6
|
-
add_group "
|
7
|
-
add_group "
|
4
|
+
add_group "stdlib", "lib/fedux_org/stdlib"
|
5
|
+
add_group "models", "lib/fedux_org/stdlib/models"
|
6
|
+
add_group "logging", "lib/fedux_org/stdlib/logging"
|
7
|
+
add_group "command", "lib/fedux_org/stdlib/command"
|
8
|
+
add_group "environment", "lib/fedux_org/stdlib/environment"
|
9
|
+
add_group "filesystem", "lib/fedux_org/stdlib/filesystem"
|
8
10
|
end
|
@@ -14,7 +14,7 @@ module FeduxOrg
|
|
14
14
|
module ClassMethods
|
15
15
|
|
16
16
|
def require_path(name)
|
17
|
-
File.join(
|
17
|
+
File.join( library_name.underscore , model_name.pluralize.underscore , name.to_s )
|
18
18
|
end
|
19
19
|
|
20
20
|
def exception_for_model
|
@@ -39,13 +39,17 @@ module FeduxOrg
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def suffix
|
42
|
-
raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented
|
42
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented, "Please defined the method \"suffix\" to make the library work."
|
43
|
+
end
|
44
|
+
|
45
|
+
def path
|
46
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented, "Please defined the method \"path\" to make the library work."
|
43
47
|
end
|
44
48
|
|
45
49
|
def path_to_instances
|
46
|
-
|
50
|
+
local_path = ::File.expand_path("../../#{model_name.pluralize.underscore}", path )
|
47
51
|
|
48
|
-
File.join(
|
52
|
+
::File.join(local_path,"*#{suffix}")
|
49
53
|
end
|
50
54
|
|
51
55
|
def name(path)
|
@@ -22,6 +22,22 @@ describe Models::BaseModel do
|
|
22
22
|
expect(m1).to eq(m_found)
|
23
23
|
end
|
24
24
|
|
25
|
+
it "returns a string of all active instances" do
|
26
|
+
Models::BaseModel.create(:name1)
|
27
|
+
Models::BaseModel.create(:name2)
|
28
|
+
Models::BaseModel.enable :name1
|
29
|
+
Models::BaseModel.enable :name2
|
30
|
+
|
31
|
+
result = Models::BaseModel.all_names_as_string(", ")
|
32
|
+
expect(result).to eq("name1, name2")
|
33
|
+
|
34
|
+
result = Models::BaseModel.all_names_as_string(": ")
|
35
|
+
expect(result).to eq("name1: name2")
|
36
|
+
|
37
|
+
result = Models::BaseModel.all_names_as_string
|
38
|
+
expect(result).to eq("name1, name2")
|
39
|
+
end
|
40
|
+
|
25
41
|
it "is possible to create and register in one step" do
|
26
42
|
m1 = Models::BaseModel.create('name')
|
27
43
|
m_found = Models::BaseModel.find('name')
|
@@ -11,6 +11,34 @@ describe Models::ClassBasedModel do
|
|
11
11
|
class InvalidTestClass < Exception; end
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
module Test123
|
16
|
+
module Models
|
17
|
+
class TestClassForFilesystem < FeduxOrg::Stdlib::Models::BaseModel
|
18
|
+
include FeduxOrg::Stdlib::Models::FilesystemBasedModel
|
19
|
+
include FeduxOrg::Stdlib::Models::ClassBasedModel
|
20
|
+
def self.path
|
21
|
+
File.join( examples_dir, 'models', 'class_based.rb' )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Test123
|
28
|
+
module Models
|
29
|
+
class TestClassForFilesystem2 < FeduxOrg::Stdlib::Models::BaseModel
|
30
|
+
include FeduxOrg::Stdlib::Models::FilesystemBasedModel
|
31
|
+
include FeduxOrg::Stdlib::Models::ClassBasedModel
|
32
|
+
def self.path
|
33
|
+
File.join( examples_dir, 'models', 'forbidden.rb' )
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.forbidden_keywords
|
37
|
+
[ :forbidden ]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
14
42
|
|
15
43
|
end
|
16
44
|
|
@@ -182,4 +210,34 @@ describe Models::ClassBasedModel do
|
|
182
210
|
}.to raise_error TestIt::Exceptions::InvalidTestClass
|
183
211
|
end
|
184
212
|
|
213
|
+
it "returns the require path" do
|
214
|
+
model = Class.new(Models::BaseModel) do
|
215
|
+
include Models::FilesystemBasedModel
|
216
|
+
|
217
|
+
def self.require_path(name)
|
218
|
+
File.join( examples_dir, 'models', 'class_based', 'invalid_2' )
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
expect_result = File.join( examples_dir, 'models', 'class_based', 'invalid_2' )
|
223
|
+
result = model.send( :require_path, :name )
|
224
|
+
|
225
|
+
expect( result ).to eq( expect_result )
|
226
|
+
end
|
227
|
+
|
228
|
+
it "returns the path to instances" do
|
229
|
+
expected_result= File.join( examples_dir, 'test_class_for_filesystems', '*.rb' )
|
230
|
+
expect( Test123::Models::TestClassForFilesystem.send(:path_to_instances) ).to eq( expected_result )
|
231
|
+
end
|
232
|
+
|
233
|
+
it "returns the name for the instance based on the path to the ruby file" do
|
234
|
+
expect( Test123::Models::TestClassForFilesystem.send(:name, Test123::Models::TestClassForFilesystem.send( :path ) ) ).to eq( :class_based )
|
235
|
+
end
|
236
|
+
|
237
|
+
it "check if the name for the instances is forbidden" do
|
238
|
+
expect {
|
239
|
+
Test123::Models::TestClassForFilesystem2.send(:name, Test123::Models::TestClassForFilesystem2.send( :path ) )
|
240
|
+
}.to raise_error FeduxOrg::Stdlib::Models::Exceptions::UnauthorizedUseOfKeyword
|
241
|
+
end
|
242
|
+
|
185
243
|
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.
|
4
|
+
version: 0.0.4
|
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-
|
12
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|