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.
@@ -5,5 +5,9 @@ module FeduxOrg
5
5
  def self.logger
6
6
  @logger ||= FeduxOrg::Stdlib::Logging::Logger.new
7
7
  end
8
+
9
+ def self.logger=(logger)
10
+ @logger = logger
11
+ end
8
12
  end
9
13
  end
@@ -64,5 +64,5 @@ module FeduxOrg
64
64
  end
65
65
 
66
66
  class ::Logger
67
- SILENT = 9999
67
+ SILENT = 9999 unless defined? SILENT
68
68
  end
@@ -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
- ::File.join(local_path,"*#{suffix}")
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
 
@@ -1,6 +1,6 @@
1
1
  #main FeduxOrg
2
2
  module FeduxOrg
3
3
  module Stdlib
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.8'
5
5
  end
6
6
  end
@@ -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.6
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-07 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler