cayuga 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/cayuga.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "cayuga/version"
3
+ require 'cayuga/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "cayuga"
7
- spec.version = Cayuga::VERSION
8
- spec.authors = ["patrick"]
9
- spec.email = ["peateas@gmail.com"]
6
+ spec.name = "cayuga"
7
+ spec.version = Cayuga::VERSION
8
+ spec.authors = ["patrick"]
9
+ spec.email = ["peateas@gmail.com"]
10
10
 
11
- spec.summary = %q{Holder for Cayuga applications and utilities.}
12
- spec.homepage = ""
11
+ spec.summary = %q{Holder for Cayuga applications and utilities.}
12
+ spec.homepage = ""
13
13
 
14
14
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
15
15
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
27
  end
28
- spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.16"
data/cayuga.iml CHANGED
@@ -29,7 +29,7 @@
29
29
  <orderEntry type="library" scope="PROVIDED" name="tins (v1.17.0, ruby-2.4.4-p296) [gem]" level="application" />
30
30
  </component>
31
31
  <component name="RModuleSettingsStorage">
32
- <LOAD_PATH number="1" string0="$MODULE_DIR$/lib" />
32
+ <LOAD_PATH number="2" string0="$MODULE_DIR$/lib" string1="$MODULE_DIR$/spec" />
33
33
  <I18N_FOLDERS number="0" />
34
34
  </component>
35
35
  </module>
@@ -1,16 +1,11 @@
1
1
  #
2
2
  # Copyright (c) 2018 Patrick Thomas. All rights reserved.
3
3
  #
4
- require 'cayuga/tools/loggable'
5
- require 'cayuga/object/object'
6
- require 'cayuga/object/singleton'
4
+ require 'cayuga'
7
5
 
8
6
  module Cayuga
9
7
  module Object
10
- class Constants
11
- extend Singleton
12
- include Object
13
- include Tools::Loggable
8
+ class Constants < Singleton
14
9
 
15
10
  def directory(constant)
16
11
  directories[constant.symbolize]
@@ -22,11 +17,9 @@ module Cayuga
22
17
 
23
18
  attr_reader :factory, :directories
24
19
 
25
- def initialize(factory)
26
- @factory = factory
27
- factory[Logger].log_log!(self.class, filename: log_file, filter: Regexp.new("#{self.class.stringify}"))
28
-
29
- @directories = factory.directory_constants
20
+ def initialize(factory, configuration)
21
+ super
22
+ @directories = configuration[:directories]
30
23
  end
31
24
 
32
25
  end
@@ -2,15 +2,15 @@
2
2
  # Copyright (c) 2018 Patrick Thomas. All rights reserved.
3
3
  #
4
4
  require 'json'
5
- require 'cayuga/tools/string'
6
- require 'cayuga/tools/symbol'
7
- require 'cayuga/tools/class'
5
+ require 'cayuga'
8
6
 
9
7
  module Cayuga
10
8
  module Object
11
9
  # Cayuga Object Factory
12
10
  class Factory
13
- attr_reader :configuration_information, :logs_directory
11
+ include Tools::Loggable
12
+
13
+ attr_reader :configuration_name, :logs_directory
14
14
 
15
15
  def supported?(klass)
16
16
  types.key?(klass.symbolize)
@@ -74,17 +74,17 @@ module Cayuga
74
74
  end
75
75
  end
76
76
 
77
- def directory_constants
78
- @directories.freeze
79
- end
77
+ def directory_constants
78
+ @directories.freeze
79
+ end
80
80
 
81
81
  private
82
82
 
83
83
  attr_reader :configuration, :types, :instances
84
84
 
85
85
  def initialize(config)
86
- @configuration_information = config
87
86
  @configuration = JSON.parse(File.read(config), symbolize_names: true)
87
+ @configuration_name = configuration[:configuration_name]
88
88
  @logs_directory = configuration[:directories][:logs]
89
89
  @types = {}
90
90
  # register_classes(FACTORIES, :factory)
@@ -120,11 +120,11 @@ module Cayuga
120
120
  # log.info("factory #{klass} created ")
121
121
  # end
122
122
  when :singleton
123
- object = klass.create(self)
124
- # log.info("singleton #{klass} created ")
123
+ object = klass.create(self, configuration)
124
+ # log.info("singleton #{klass} created ")
125
125
  when :named
126
- object = klass.create(self, name)
127
- # log.info("#{klass} created with name #{name}")
126
+ object = klass.create(self, configuration, name)
127
+ # log.info("#{klass} created with name #{name}")
128
128
  else
129
129
  raise "unregistered or incorrectly registered class #{klass}"
130
130
  end
@@ -132,5 +132,6 @@ module Cayuga
132
132
  end
133
133
 
134
134
  end
135
+
135
136
  end
136
137
  end
@@ -2,47 +2,73 @@
2
2
  # Copyright (c) 2018 Patrick Thomas. All rights reserved.
3
3
  #
4
4
  require 'file-tail'
5
- require 'cayuga/object/constants'
6
- require 'cayuga/object/singleton'
7
- require 'cayuga/tools/loggable'
5
+ require 'cayuga'
8
6
 
9
7
  module Cayuga
10
8
  module Object
11
- class Logger
12
- extend Singleton
13
- include Object
14
- include Tools::Loggable
9
+ class Logger < Singleton
15
10
 
16
11
  def generic_log_file(name)
17
12
  "#{factory.logs_directory}/#{name.stringify.filenamify('.log')}"
18
13
  end
19
14
 
20
- def logs
15
+ def log_names
21
16
  @logs.keys.freeze
22
17
  end
23
18
 
24
- def log_log(name)
19
+ def log_filename(name)
25
20
  @logs[name.symbolize]
26
21
  end
27
22
 
28
- alias [] log_log
23
+ alias [] log_filename
24
+
25
+ def log_appender(name)
26
+ all = SemanticLogger.appenders.select { |log| log.name == name.stringify }
27
+ count = all.count
28
+ raise RuntimeError, "More than one log with name #{name}" if count > 1
29
+ if count == 1
30
+ all[0]
31
+ else
32
+ nil
33
+ end
34
+ end
29
35
 
30
36
  def log_log?(name)
31
37
  not @logs[name.symbolize].nil?
32
38
  end
33
39
 
34
- def log_log!(name, filename: nil, stream: nil, filter: nil)
35
- return log_log(name) if log_log?(name)
36
- log = nil
37
- log = SemanticLogger.add_appender(file_name: filename, filter: filter) unless filename.nil?
38
- log = SemanticLogger.add_appender(io: stream, filter: filter) unless stream.nil?
39
- raise ArgumentError, "no filename or stream for log #{name.stringify}" if log.nil?
40
+ def log_log!(name, filename: nil, stream: nil, filter: nil, level: :info)
41
+ symbol = name.symbolize
42
+ return log_filename(symbol) if log_log?(symbol)
43
+ if log_appender_exists?(symbol)
44
+ logger.warn('no entry for log', payload = { name: symbol })
45
+ logger.warn('no entry for log', payload = { log: log_names })
46
+ @logs[symbol] = filename || stream
47
+ if log_filename(symbol).nil?
48
+ @logs[symbol] = factory.logs_directory + '/' + name.classify.log_file
49
+ end
50
+ return
51
+ end
52
+ if filename.nil?
53
+ if stream.nil?
54
+ #must be a class
55
+ filename = factory.logs_directory + '/' + name.classify.log_file
56
+ log = SemanticLogger.add_appender(file_name: filename, filter: filter)
57
+ else
58
+ log = SemanticLogger.add_appender(io: stream, filter: filter)
59
+ end
60
+ else
61
+ log = SemanticLogger.add_appender(file_name: filename, filter: filter)
62
+ end
40
63
  log.name = name.stringify
41
- @logs[name.symbolize] = filename || stream
64
+ log.level = level
65
+ @logs[name.symbolize] = filename || stream || name.stringify
66
+ logger.info('logs', payload = { log_names: log_names })
67
+ logger.info('logs', payload = { count: SemanticLogger.appenders.count })
42
68
  end
43
69
 
44
70
  def tail(name, size: 5)
45
- File.open(log_log(name)) do |log|
71
+ File.open(log_filename(name)) do |log|
46
72
  log.extend File::Tail
47
73
  log.return_if_eof = true
48
74
  log.backward(size).tail(size)
@@ -55,14 +81,25 @@ module Cayuga
55
81
 
56
82
  attr_reader :factory
57
83
 
58
- def initialize(factory)
84
+ def initialize(factory, configuration)
59
85
  @factory = factory
60
86
  @logs = {}
61
- log_log!(:console, stream: $stderr)
87
+ log_log!(:console, stream: $stderr, level: :warn)
62
88
  log_log!(:main, filename: generic_log_file(:main))
63
- log_log!(self.class, filename: log_file, filter: Regexp.new(self.class.stringify))
89
+ log_log!(factory.class, filter: Regexp.new(factory.class.stringify))
90
+ log_log!(self.class, filter: Regexp.new(self.class.stringify))
91
+ end
92
+
93
+ def log_appender_exists?(name)
94
+ name = name.symbolize
95
+ log = log_appender(name)
96
+ if log.nil?
97
+ false
98
+ else
99
+ true
100
+ end
64
101
  end
65
102
 
66
103
  end
67
104
  end
68
- end
105
+ end
@@ -3,21 +3,24 @@
3
3
  #
4
4
  module Cayuga
5
5
  module Object
6
- # Named Object Class
7
- module NamedObjectClass
8
- def valid_name?(_factory, name)
6
+ # Named Object
7
+ class NamedObject < Object
8
+ attr_reader :name
9
+
10
+ def self.valid_name?(_factory, name)
9
11
  name != nil
10
12
  end
11
13
 
12
- def primary?(_name)
14
+ def self.primary?(_name)
13
15
  true
14
16
  end
15
17
 
16
- def primary(name)
18
+ def self.primary(name)
17
19
  name
18
20
  end
19
21
 
20
- def create(factory, name)
22
+ def self.create(factory, configuration, name)
23
+ raise "#{self.stringify}[#{name}] already registered" if factory.registered?(self, name)
21
24
  if primary?(name)
22
25
  primary = name
23
26
  alternate = nil
@@ -26,14 +29,20 @@ module Cayuga
26
29
  alternate = name
27
30
  end
28
31
  verify_name_validity(factory, primary, alternate)
29
- instance = create_primary(factory, primary(name))
32
+ instance = create_primary(factory, configuration, primary(name))
30
33
  factory.register(instance, self, alternate) unless alternate.nil?
31
34
  instance
32
35
  end
33
36
 
34
37
  private
35
38
 
36
- def verify_name_validity(factory, name, alternate)
39
+ def initialize(factory, configuration, name)
40
+ super(factory, configuration)
41
+ @name = name
42
+ # Todo: alternative names
43
+ end
44
+
45
+ def self.verify_name_validity(factory, name, alternate)
37
46
  # check validity of name
38
47
  unless valid_name?(factory, name)
39
48
  raise "'#{self}['#{name}'] is not a valid #{self}"
@@ -49,16 +58,20 @@ module Cayuga
49
58
  true
50
59
  end
51
60
 
52
- def create_primary(factory, name)
61
+ private_class_method :verify_name_validity
62
+
63
+ def self.create_primary(factory, configuration, name)
53
64
  if factory.registered?(self, name)
54
65
  instance = factory[self, name]
55
66
  else
56
- instance = new(factory, name)
67
+ instance = new(factory, configuration, name)
57
68
  factory.register(instance, self, name)
58
69
  end
59
70
  instance
60
71
  end
61
72
 
73
+ private_class_method :create_primary
74
+
62
75
  end
63
76
  end
64
- end
77
+ end
@@ -2,18 +2,35 @@
2
2
  # Copyright (c) 2018 Patrick Thomas. All rights reserved.
3
3
  #
4
4
  #
5
- require 'cayuga/tools/string'
6
- require 'cayuga/tools/symbol'
7
- require 'cayuga/tools/class'
8
- require 'cayuga/tools/loggable'
5
+ require 'cayuga'
9
6
 
10
7
  module Cayuga
8
+ # noinspection RubyConstantNamingConvention
9
+ RootObject = Object
10
+
11
11
  module Object
12
- module Object
13
- def log_file
14
- @log_file ||= "#{factory.logs_directory}/#{self.class.filenamify('.log')}"
12
+ class Object
13
+ include Tools::Loggable
14
+
15
+ attr_reader :configuration_name
16
+
17
+ private_class_method :new
18
+
19
+ private
20
+
21
+ attr_reader :factory, :configuration
22
+
23
+ def initialize(factory, configuration)
24
+ @factory = factory
25
+ @configuration = configuration
26
+ @configuration_name = factory.configuration_name
27
+ factory[Logger].log_log!(
28
+ self.class,
29
+ filter: Regexp.new(self.class.stringify)
30
+ ) unless self.class == Logger
15
31
  end
16
32
 
17
33
  end
18
34
  end
19
- end
35
+ end
36
+
@@ -4,13 +4,11 @@
4
4
  module Cayuga
5
5
  module Object
6
6
  # Cayuga Object Singleton
7
- module Singleton
8
-
9
- def create(factory)
7
+ class Singleton < Object
8
+ def self.create(factory, configuration)
10
9
  raise "#{self.stringify} already registered" if factory.registered?(self)
11
- factory.register(new(factory), self)
10
+ factory.register(new(factory, configuration), self)
12
11
  end
13
-
14
12
  end
15
13
  end
16
- end
14
+ end
@@ -13,7 +13,13 @@ module Cayuga
13
13
  class << self
14
14
  alias_method :log, :logger
15
15
  end
16
+
16
17
  alias_method :log, :logger
18
+
19
+ def self.log_file
20
+ "#{self.filenamify('.log')}"
21
+ end
22
+
17
23
  end
18
24
  end
19
25
  end
@@ -1,3 +1,3 @@
1
1
  module Cayuga
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/cayuga.rb CHANGED
@@ -1,5 +1,12 @@
1
- require "cayuga/version"
1
+ require 'cayuga/version'
2
+ require 'cayuga/tools/string'
3
+ require 'cayuga/tools/symbol'
4
+ require 'cayuga/tools/class'
5
+ require 'cayuga/tools/loggable'
6
+ require 'cayuga/object/object'
7
+ require 'cayuga/object/singleton'
8
+ require 'cayuga/object/constants'
9
+ require 'cayuga/object/logger'
10
+ require 'cayuga/object/named_object'
11
+ require 'cayuga/object/factory'
2
12
 
3
- module Cayuga
4
- # Your code goes here...
5
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cayuga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - patrick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,7 +138,7 @@ files:
138
138
  - lib/cayuga/object/constants.rb
139
139
  - lib/cayuga/object/factory.rb
140
140
  - lib/cayuga/object/logger.rb
141
- - lib/cayuga/object/named_object_class.rb
141
+ - lib/cayuga/object/named_object.rb
142
142
  - lib/cayuga/object/object.rb
143
143
  - lib/cayuga/object/singleton.rb
144
144
  - lib/cayuga/tools/class.rb