fedux_org-stdlib 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fedux_org/stdlib/logging.rb +4 -0
- data/lib/fedux_org/stdlib/logging/logger.rb +1 -1
- data/lib/fedux_org/stdlib/models/base_model.rb +8 -0
- data/lib/fedux_org/stdlib/models/class_based_model.rb +5 -1
- data/lib/fedux_org/stdlib/models/filesystem_based_model.rb +6 -1
- data/lib/fedux_org/stdlib/version.rb +1 -1
- data/spec/models/base_model_spec.rb +18 -0
- metadata +2 -2
@@ -81,6 +81,14 @@ module FeduxOrg
|
|
81
81
|
find_all(enabled: true).map(&:name).sort.join(connector)
|
82
82
|
end
|
83
83
|
|
84
|
+
def first
|
85
|
+
@instances.to_a.first
|
86
|
+
end
|
87
|
+
|
88
|
+
def last
|
89
|
+
@instances.to_a.last
|
90
|
+
end
|
91
|
+
|
84
92
|
#enables a specific instance
|
85
93
|
def enable(name)
|
86
94
|
find(name: name).enable
|
@@ -15,7 +15,10 @@ module FeduxOrg
|
|
15
15
|
module ClassMethods
|
16
16
|
|
17
17
|
def require_path(name)
|
18
|
-
File.join( library_name.underscore , model_name.pluralize.underscore , name.to_s )
|
18
|
+
path = File.join( library_name.underscore , model_name.pluralize.underscore , name.to_s )
|
19
|
+
FeduxOrg::Stdlib.logger.debug(self) { "Path to instances of model \"#{name}\": #{path}" }
|
20
|
+
|
21
|
+
path
|
19
22
|
end
|
20
23
|
|
21
24
|
def exception_for_model
|
@@ -44,6 +47,7 @@ module FeduxOrg
|
|
44
47
|
|
45
48
|
def load_from_filesystem
|
46
49
|
files = Dir.glob( path_to_instances )
|
50
|
+
FeduxOrg::Stdlib.logger.debug(self) { "Files found at path \"#{path_to_instances}\": #{ files.join(", ") }" }
|
47
51
|
|
48
52
|
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?
|
49
53
|
|
@@ -48,14 +48,19 @@ module FeduxOrg
|
|
48
48
|
|
49
49
|
def path_to_instances
|
50
50
|
local_path = ::File.expand_path("../../#{model_name.pluralize.underscore}", path )
|
51
|
+
return_path = ::File.join(local_path,"*#{suffix}")
|
51
52
|
|
52
|
-
::
|
53
|
+
FeduxOrg::Stdlib.logger.debug(self) { "Path to instances of model: #{return_path}" }
|
54
|
+
|
55
|
+
return_path
|
53
56
|
end
|
54
57
|
|
55
58
|
def name(path)
|
56
59
|
name = File.basename(path, suffix ).to_sym
|
57
60
|
raise FeduxOrg::Stdlib::Models::Exceptions::UnauthorizedUseOfKeyword if forbidden_keywords.include? name
|
58
61
|
|
62
|
+
FeduxOrg::Stdlib.logger.debug(self) { "Name of model: #{name}" }
|
63
|
+
|
59
64
|
name
|
60
65
|
end
|
61
66
|
|
@@ -61,4 +61,22 @@ describe Models::BaseModel do
|
|
61
61
|
expect(Models::BaseModel.all).to eq( [] )
|
62
62
|
end
|
63
63
|
|
64
|
+
it "return first object" do
|
65
|
+
expected_result = Models::BaseModel.create('name1')
|
66
|
+
Models::BaseModel.create('name2')
|
67
|
+
Models::BaseModel.create('name3')
|
68
|
+
|
69
|
+
result = Models::BaseModel.first
|
70
|
+
expect(result).to eq( expected_result )
|
71
|
+
end
|
72
|
+
|
73
|
+
it "return last object" do
|
74
|
+
Models::BaseModel.create('name1')
|
75
|
+
Models::BaseModel.create('name2')
|
76
|
+
expected_result = Models::BaseModel.create('name3')
|
77
|
+
|
78
|
+
result = Models::BaseModel.last
|
79
|
+
expect(result).to eq( expected_result )
|
80
|
+
end
|
81
|
+
|
64
82
|
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.8
|
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-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|