cayuga 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +11 -11
- data/.idea/.rakeTasks +7 -0
- data/.idea/dictionaries/patrick.xml +12 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/misc.xml +5 -5
- data/.idea/modules.xml +7 -7
- data/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +1348 -358
- data/.rspec +3 -3
- data/.rubocop.yml +31 -0
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/README.md +35 -35
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cayuga.gemspec +39 -37
- data/cayuga.iml +34 -16
- data/lib/cayuga/object/constants.rb +34 -0
- data/lib/cayuga/object/factory.rb +136 -0
- data/lib/cayuga/object/logger.rb +68 -0
- data/lib/cayuga/object/named_object_class.rb +64 -0
- data/lib/cayuga/object/object.rb +19 -0
- data/lib/cayuga/object/singleton.rb +16 -0
- data/lib/cayuga/tools/class.rb +30 -0
- data/lib/cayuga/tools/loggable.rb +21 -0
- data/lib/cayuga/tools/string.rb +40 -0
- data/lib/cayuga/tools/symbol.rb +32 -0
- data/lib/cayuga/version.rb +3 -3
- data/lib/cayuga.rb +5 -5
- data/load_categories_810.json +39 -0
- data/load_patrick_810.json +21 -0
- data/load_relations_810.json +28 -0
- data/load_time_and_locations_810.json +43 -0
- data/load_universe_810.json +45 -0
- data/reports.txt +77 -0
- data/system_category_reports_2018.json +149 -0
- data/system_relation_reports_2018.json +175 -0
- data/system_test.json +8 -0
- data/system_things_reports_2018.json +77 -0
- data/test_script.rb +87 -0
- metadata +89 -9
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
3
|
-
--require spec_helper
|
1
|
+
--format documentation
|
2
|
+
--color
|
3
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Layout/AlignParameters:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Layout/EmptyLinesAroundBlockBody:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Layout/EmptyLinesAroundClassBody:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Layout/EmptyLinesAroundModuleBody:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Layout/EndAlignment:
|
14
|
+
EnforcedStyleAlignWith: start_of_line
|
15
|
+
|
16
|
+
Layout/SpaceAroundOperators:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/TrailingBlankLines:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Enabled: true
|
24
|
+
Max: 15
|
25
|
+
|
26
|
+
Style/CaseIndentation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/IfUnlessModifier:
|
30
|
+
Enabled: false
|
31
|
+
|
data/.travis.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.4.4
|
5
|
-
before_install: gem install bundler -v 1.16.2
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.4.4
|
5
|
+
before_install: gem install bundler -v 1.16.2
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in cayuga.gemspec
|
6
|
-
gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in cayuga.gemspec
|
6
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
# Cayuga
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cayuga`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'cayuga'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install cayuga
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cayuga.
|
1
|
+
# Cayuga
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cayuga`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cayuga'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cayuga
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cayuga.
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "cayuga"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cayuga"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/cayuga.gemspec
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
-
|
2
|
-
lib
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
spec.
|
8
|
-
spec.
|
9
|
-
spec.
|
10
|
-
|
11
|
-
|
12
|
-
spec.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
spec.
|
31
|
-
|
32
|
-
spec.
|
33
|
-
|
34
|
-
spec.add_development_dependency "
|
35
|
-
spec.add_development_dependency "
|
36
|
-
spec.add_development_dependency "
|
37
|
-
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "cayuga/version"
|
4
|
+
|
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"]
|
10
|
+
|
11
|
+
spec.summary = %q{Holder for Cayuga applications and utilities.}
|
12
|
+
spec.homepage = ""
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
15
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
16
|
+
# if spec.respond_to?(:metadata)
|
17
|
+
# spec.metadata["allowed_push_host"] = "http://rubygems.org"
|
18
|
+
# else
|
19
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
20
|
+
# "public gem pushes."
|
21
|
+
# end
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
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
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "semantic_logger", "~>4.3"
|
36
|
+
spec.add_development_dependency "file-tail", "~>1.2"
|
37
|
+
spec.add_development_dependency "facets", "~>3.1"
|
38
|
+
spec.add_development_dependency "memoist", "~>0.16"
|
39
|
+
end
|
data/cayuga.iml
CHANGED
@@ -1,17 +1,35 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="RUBY_MODULE" version="4">
|
3
|
-
<component name="
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
<
|
10
|
-
<
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
<orderEntry type="
|
15
|
-
<orderEntry type="
|
16
|
-
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Gem">
|
5
|
+
<configuration />
|
6
|
+
</facet>
|
7
|
+
</component>
|
8
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
9
|
+
<exclude-output />
|
10
|
+
<content url="file://$MODULE_DIR$">
|
11
|
+
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
|
12
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
13
|
+
</content>
|
14
|
+
<orderEntry type="jdk" jdkName="ruby-2.4.4-p296" jdkType="RUBY_SDK" />
|
15
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.16.2, ruby-2.4.4-p296) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.0.5, ruby-2.4.4-p296) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, ruby-2.4.4-p296) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="facets (v3.1.0, ruby-2.4.4-p296) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="file-tail (v1.2.0, ruby-2.4.4-p296) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="memoist (v0.16.0, ruby-2.4.4-p296) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, ruby-2.4.4-p296) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.8.0, ruby-2.4.4-p296) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.8.0, ruby-2.4.4-p296) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.8.2, ruby-2.4.4-p296) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.8.0, ruby-2.4.4-p296) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.8.0, ruby-2.4.4-p296) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="semantic_logger (v4.3.0, ruby-2.4.4-p296) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="tins (v1.17.0, ruby-2.4.4-p296) [gem]" level="application" />
|
30
|
+
</component>
|
31
|
+
<component name="RModuleSettingsStorage">
|
32
|
+
<LOAD_PATH number="1" string0="$MODULE_DIR$/lib" />
|
33
|
+
<I18N_FOLDERS number="0" />
|
34
|
+
</component>
|
17
35
|
</module>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018 Patrick Thomas. All rights reserved.
|
3
|
+
#
|
4
|
+
require 'cayuga/tools/loggable'
|
5
|
+
require 'cayuga/object/object'
|
6
|
+
require 'cayuga/object/singleton'
|
7
|
+
|
8
|
+
module Cayuga
|
9
|
+
module Object
|
10
|
+
class Constants
|
11
|
+
extend Singleton
|
12
|
+
include Object
|
13
|
+
include Tools::Loggable
|
14
|
+
|
15
|
+
def directory(constant)
|
16
|
+
directories[constant.symbolize]
|
17
|
+
end
|
18
|
+
|
19
|
+
private_class_method :new
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :factory, :directories
|
24
|
+
|
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
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018 Patrick Thomas. All rights reserved.
|
3
|
+
#
|
4
|
+
require 'json'
|
5
|
+
require 'cayuga/tools/string'
|
6
|
+
require 'cayuga/tools/symbol'
|
7
|
+
require 'cayuga/tools/class'
|
8
|
+
|
9
|
+
module Cayuga
|
10
|
+
module Object
|
11
|
+
# Cayuga Object Factory
|
12
|
+
class Factory
|
13
|
+
attr_reader :configuration_information, :logs_directory
|
14
|
+
|
15
|
+
def supported?(klass)
|
16
|
+
types.key?(klass.symbolize)
|
17
|
+
end
|
18
|
+
|
19
|
+
def type(klass)
|
20
|
+
types[klass.symbolize]
|
21
|
+
end
|
22
|
+
|
23
|
+
def registered?(klass, name = nil)
|
24
|
+
lookup_registered_instances(klass.symbolize, name) != nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def register(instance, klass, name = nil)
|
28
|
+
key = klass.symbolize
|
29
|
+
unless lookup_registered_instances(key, name).nil?
|
30
|
+
value = name.nil? ? klass.string : "#{klass.string}[#{name}]"
|
31
|
+
raise "instance for #{value} already registered}"
|
32
|
+
end
|
33
|
+
type = type(key)
|
34
|
+
case type
|
35
|
+
when :singleton # , :factory
|
36
|
+
instances[key] = instance
|
37
|
+
when :named
|
38
|
+
value = instances[key]
|
39
|
+
if value.nil?
|
40
|
+
value = {}
|
41
|
+
instances[key] = value
|
42
|
+
end
|
43
|
+
value[name] = instance
|
44
|
+
else
|
45
|
+
raise "bad type '#{type}'"
|
46
|
+
end
|
47
|
+
instance
|
48
|
+
end
|
49
|
+
|
50
|
+
def [](klass, name = nil)
|
51
|
+
key = klass.symbolize
|
52
|
+
value = lookup_registered_instances(key, name)
|
53
|
+
if value.nil?
|
54
|
+
value = create_instance(type(key), klass.classify, name)
|
55
|
+
end
|
56
|
+
value
|
57
|
+
end
|
58
|
+
|
59
|
+
def release(klass, name = nil)
|
60
|
+
key = klass.symbolize
|
61
|
+
if registered?(key, name)
|
62
|
+
type = type(key)
|
63
|
+
case type
|
64
|
+
when :singleton #, :factory
|
65
|
+
instances.delete(key)
|
66
|
+
when :named
|
67
|
+
value = instances[key]
|
68
|
+
if value
|
69
|
+
value.delete(name)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
raise "bad type '#{type}'"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def directory_constants
|
78
|
+
@directories.freeze
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
attr_reader :configuration, :types, :instances
|
84
|
+
|
85
|
+
def initialize(config)
|
86
|
+
@configuration_information = config
|
87
|
+
@configuration = JSON.parse(File.read(config), symbolize_names: true)
|
88
|
+
@logs_directory = configuration[:directories][:logs]
|
89
|
+
@types = {}
|
90
|
+
# register_classes(FACTORIES, :factory)
|
91
|
+
register_classes(configuration[:singletons], :singleton)
|
92
|
+
# register_classes(INDEXED_CLASSES, :indexed)
|
93
|
+
register_classes(
|
94
|
+
configuration[:named_object_classes], :named
|
95
|
+
)
|
96
|
+
@instances = {}
|
97
|
+
@directories = configuration[:directories].freeze
|
98
|
+
end
|
99
|
+
|
100
|
+
def register_classes(list, type)
|
101
|
+
return if list.nil?
|
102
|
+
list.each do |klass|
|
103
|
+
types[klass.symbolize] = type
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def lookup_registered_instances(key, name)
|
108
|
+
value = instances[key]
|
109
|
+
if !value.nil? && !name.nil?
|
110
|
+
value = value[name]
|
111
|
+
end
|
112
|
+
value
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_instance(type, klass, name)
|
116
|
+
case type
|
117
|
+
# when :factory
|
118
|
+
# object = klass.create(self, configuration)
|
119
|
+
# unless klass == LoggerFactory
|
120
|
+
# log.info("factory #{klass} created ")
|
121
|
+
# end
|
122
|
+
when :singleton
|
123
|
+
object = klass.create(self)
|
124
|
+
# log.info("singleton #{klass} created ")
|
125
|
+
when :named
|
126
|
+
object = klass.create(self, name)
|
127
|
+
# log.info("#{klass} created with name #{name}")
|
128
|
+
else
|
129
|
+
raise "unregistered or incorrectly registered class #{klass}"
|
130
|
+
end
|
131
|
+
object
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018 Patrick Thomas. All rights reserved.
|
3
|
+
#
|
4
|
+
require 'file-tail'
|
5
|
+
require 'cayuga/object/constants'
|
6
|
+
require 'cayuga/object/singleton'
|
7
|
+
require 'cayuga/tools/loggable'
|
8
|
+
|
9
|
+
module Cayuga
|
10
|
+
module Object
|
11
|
+
class Logger
|
12
|
+
extend Singleton
|
13
|
+
include Object
|
14
|
+
include Tools::Loggable
|
15
|
+
|
16
|
+
def generic_log_file(name)
|
17
|
+
"#{factory.logs_directory}/#{name.stringify.filenamify('.log')}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def logs
|
21
|
+
@logs.keys.freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
def log_log(name)
|
25
|
+
@logs[name.symbolize]
|
26
|
+
end
|
27
|
+
|
28
|
+
alias [] log_log
|
29
|
+
|
30
|
+
def log_log?(name)
|
31
|
+
not @logs[name.symbolize].nil?
|
32
|
+
end
|
33
|
+
|
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
|
+
log.name = name.stringify
|
41
|
+
@logs[name.symbolize] = filename || stream
|
42
|
+
end
|
43
|
+
|
44
|
+
def tail(name, size: 5)
|
45
|
+
File.open(log_log(name)) do |log|
|
46
|
+
log.extend File::Tail
|
47
|
+
log.return_if_eof = true
|
48
|
+
log.backward(size).tail(size)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private_class_method :new
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
attr_reader :factory
|
57
|
+
|
58
|
+
def initialize(factory)
|
59
|
+
@factory = factory
|
60
|
+
@logs = {}
|
61
|
+
log_log!(:console, stream: $stderr)
|
62
|
+
log_log!(:main, filename: generic_log_file(:main))
|
63
|
+
log_log!(self.class, filename: log_file, filter: Regexp.new(self.class.stringify))
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2016-2018 Patrick Thomas. All rights reserved.
|
3
|
+
#
|
4
|
+
module Cayuga
|
5
|
+
module Object
|
6
|
+
# Named Object Class
|
7
|
+
module NamedObjectClass
|
8
|
+
def valid_name?(_factory, name)
|
9
|
+
name != nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def primary?(_name)
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def primary(name)
|
17
|
+
name
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(factory, name)
|
21
|
+
if primary?(name)
|
22
|
+
primary = name
|
23
|
+
alternate = nil
|
24
|
+
else
|
25
|
+
primary = primary(name)
|
26
|
+
alternate = name
|
27
|
+
end
|
28
|
+
verify_name_validity(factory, primary, alternate)
|
29
|
+
instance = create_primary(factory, primary(name))
|
30
|
+
factory.register(instance, self, alternate) unless alternate.nil?
|
31
|
+
instance
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def verify_name_validity(factory, name, alternate)
|
37
|
+
# check validity of name
|
38
|
+
unless valid_name?(factory, name)
|
39
|
+
raise "'#{self}['#{name}'] is not a valid #{self}"
|
40
|
+
end
|
41
|
+
# name valid
|
42
|
+
# check alternate valid if exists
|
43
|
+
unless alternate.nil?
|
44
|
+
unless valid_name?(factory, alternate)
|
45
|
+
raise "'#{self}['#{alternate}'] is not a valid #{self}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
# alternate valid
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_primary(factory, name)
|
53
|
+
if factory.registered?(self, name)
|
54
|
+
instance = factory[self, name]
|
55
|
+
else
|
56
|
+
instance = new(factory, name)
|
57
|
+
factory.register(instance, self, name)
|
58
|
+
end
|
59
|
+
instance
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018 Patrick Thomas. All rights reserved.
|
3
|
+
#
|
4
|
+
#
|
5
|
+
require 'cayuga/tools/string'
|
6
|
+
require 'cayuga/tools/symbol'
|
7
|
+
require 'cayuga/tools/class'
|
8
|
+
require 'cayuga/tools/loggable'
|
9
|
+
|
10
|
+
module Cayuga
|
11
|
+
module Object
|
12
|
+
module Object
|
13
|
+
def log_file
|
14
|
+
@log_file ||= "#{factory.logs_directory}/#{self.class.filenamify('.log')}"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2018 Patrick Thomas. All rights reserved.
|
3
|
+
#
|
4
|
+
module Cayuga
|
5
|
+
module Object
|
6
|
+
# Cayuga Object Singleton
|
7
|
+
module Singleton
|
8
|
+
|
9
|
+
def create(factory)
|
10
|
+
raise "#{self.stringify} already registered" if factory.registered?(self)
|
11
|
+
factory.register(new(factory), self)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|