dichotomy 0.0.1

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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.idea/.name +1 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/dichotomy.iml +87 -0
  6. data/.idea/encodings.xml +5 -0
  7. data/.idea/misc.xml +5 -0
  8. data/.idea/modules.xml +9 -0
  9. data/.idea/runConfigurations/example.xml +26 -0
  10. data/.idea/scopes/scope_settings.xml +5 -0
  11. data/.idea/vcs.xml +7 -0
  12. data/Gemfile +4 -0
  13. data/LICENSE.txt +22 -0
  14. data/README.md +38 -0
  15. data/Rakefile +2 -0
  16. data/dichotomy.gemspec +27 -0
  17. data/lib/dichotomy/base/extension/container_extension.rb +28 -0
  18. data/lib/dichotomy/base/extension/extension_context.rb +14 -0
  19. data/lib/dichotomy/base/managers/build_manager.rb +38 -0
  20. data/lib/dichotomy/base/managers/builder/build_context.rb +38 -0
  21. data/lib/dichotomy/base/managers/builder/build_stage.rb +24 -0
  22. data/lib/dichotomy/base/managers/builder/strategies/staged_strategy_chain.rb +37 -0
  23. data/lib/dichotomy/base/managers/builder/strategies/strategy_chain.rb +38 -0
  24. data/lib/dichotomy/container.rb +27 -0
  25. data/lib/dichotomy/extensions/default_extension.rb +40 -0
  26. data/lib/dichotomy/extensions/defaults/extension_methods.rb +32 -0
  27. data/lib/dichotomy/extensions/defaults/strategies/default_resolve_strategy.rb +19 -0
  28. data/lib/dichotomy/extensions/defaults/strategies/pre_creation_strategy.rb +17 -0
  29. data/lib/dichotomy/extensions/defaults/strategies/reflectors/class_reflector.rb +13 -0
  30. data/lib/dichotomy/extensions/defaults/strategies/reflectors/source/source_analyser.rb +31 -0
  31. data/lib/dichotomy/extensions/defaults/strategies/reflectors/source/source_interpreter.rb +59 -0
  32. data/lib/dichotomy/extensions/test_extension.rb +32 -0
  33. data/lib/dichotomy/extensions/tests/strategies/default_subject_strategy.rb +18 -0
  34. data/lib/dichotomy/version.rb +3 -0
  35. data/lib/dichotomy.rb +4 -0
  36. data/lib/example.rb +7 -0
  37. data/lib/example_dependency.rb +13 -0
  38. metadata +129 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8523505b7772c68240ab86e82e665b647a3af261
4
+ data.tar.gz: bc8b4033a7681dca3b6c1282bbd32efc83e6dd30
5
+ SHA512:
6
+ metadata.gz: 2ba8e1f9400b02ca4ccb0f278724eae27257466ffc8be773eb5c12620a9fe20fcf08af6a92df6d027e891971facc360bad0798d5b75128c5c34bba0b617083f4
7
+ data.tar.gz: 5e160e7477764bc59be47239b19577162302a288917575d23986f85972272626ae12a6341674e9845dce42a1c2352da2eddd285a962e8d8539f035d09b803697
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.idea/.name ADDED
@@ -0,0 +1 @@
1
+ dichotomy
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build dichotomy-0.0.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install dichotomy-0.0.1.gem into system gems" fullCmd="install" taksId="install" /><RakeTask description="Create tag v0.0.1 and build and push dichotomy-0.0.1.gem to Rubygems" fullCmd="release" taksId="release" /></RakeGroup></Settings>
@@ -0,0 +1,87 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="ModuleRunConfigurationManager">
13
+ <configuration default="false" name="example" type="RubyRunConfigurationType" factoryName="Ruby">
14
+ <module name="dichotomy" />
15
+ <RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
16
+ <RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/lib" />
17
+ <RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
18
+ <RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
19
+ <RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
20
+ <envs />
21
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
22
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
23
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
24
+ <COVERAGE_PATTERN ENABLED="true">
25
+ <PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
26
+ </COVERAGE_PATTERN>
27
+ </EXTENSION>
28
+ <EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
29
+ <RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/lib/example.rb" />
30
+ <RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
31
+ <RunnerSettings RunnerId="RubyDebugRunner" />
32
+ <RunnerSettings RunnerId="RubyRunner" />
33
+ <ConfigurationWrapper RunnerId="RubyDebugRunner" />
34
+ <ConfigurationWrapper RunnerId="RubyRunner" />
35
+ <method />
36
+ </configuration>
37
+ <configuration default="false" name="dichotomy" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
38
+ <module name="dichotomy" />
39
+ <RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
40
+ <RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/lib" />
41
+ <RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
42
+ <RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
43
+ <RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
44
+ <envs />
45
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
46
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
47
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
48
+ <COVERAGE_PATTERN ENABLED="true">
49
+ <PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
50
+ </COVERAGE_PATTERN>
51
+ </EXTENSION>
52
+ <EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
53
+ <RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/lib/dichotomy.rb" />
54
+ <RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
55
+ <RunnerSettings RunnerId="RubyRunner" />
56
+ <ConfigurationWrapper RunnerId="RubyRunner" />
57
+ <method />
58
+ </configuration>
59
+ </component>
60
+ <component name="NewModuleRootManager">
61
+ <content url="file://$MODULE_DIR$">
62
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
63
+ </content>
64
+ <orderEntry type="jdk" jdkName="RVM: ruby-2.1.2" jdkType="RUBY_SDK" />
65
+ <orderEntry type="sourceFolder" forTests="false" />
66
+ <orderEntry type="module-library">
67
+ <library name="dichotomy (v0.0.1, /Users/rinojohnsen/RubymineProjects/dichotomy) [path][gem]">
68
+ <CLASSES>
69
+ <root url="file://$MODULE_DIR$/bin" />
70
+ <root url="file://$MODULE_DIR$/lib" />
71
+ <root url="file://$MODULE_DIR$/.idea" />
72
+ </CLASSES>
73
+ <SOURCES>
74
+ <root url="file://$MODULE_DIR$/bin" />
75
+ <root url="file://$MODULE_DIR$/lib" />
76
+ <root url="file://$MODULE_DIR$/.idea" />
77
+ </SOURCES>
78
+ </library>
79
+ </orderEntry>
80
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.0.0, RVM: ruby-2.1.2) [gem]" level="application" />
81
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.2, RVM: ruby-2.1.2) [gem]" level="application" />
82
+ <orderEntry type="library" scope="PROVIDED" name="parser (v2.1.9, RVM: ruby-2.1.2) [gem]" level="application" />
83
+ <orderEntry type="library" scope="PROVIDED" name="rake (v0.9.6, RVM: ruby-2.1.2) [gem]" level="application" />
84
+ <orderEntry type="library" scope="PROVIDED" name="slop (v3.5.0, RVM: ruby-2.1.2) [gem]" level="application" />
85
+ </component>
86
+ </module>
87
+
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
5
+
data/.idea/misc.xml ADDED
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.3-p547 [global]" project-jdk-type="RUBY_SDK" />
4
+ </project>
5
+
data/.idea/modules.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/dichotomy.iml" filepath="$PROJECT_DIR$/.idea/dichotomy.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
9
+
@@ -0,0 +1,26 @@
1
+ <component name="ProjectRunConfigurationManager">
2
+ <configuration default="false" name="example" type="RubyRunConfigurationType" factoryName="Ruby">
3
+ <module name="dichotomy" />
4
+ <RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
5
+ <RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/lib" />
6
+ <RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
7
+ <RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
8
+ <RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
9
+ <envs />
10
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
11
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
12
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
13
+ <COVERAGE_PATTERN ENABLED="true">
14
+ <PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
15
+ </COVERAGE_PATTERN>
16
+ </EXTENSION>
17
+ <EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
18
+ <RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/lib/example.rb" />
19
+ <RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
20
+ <RunnerSettings RunnerId="RubyDebugRunner" />
21
+ <RunnerSettings RunnerId="RubyRunner" />
22
+ <ConfigurationWrapper RunnerId="RubyDebugRunner" />
23
+ <ConfigurationWrapper RunnerId="RubyRunner" />
24
+ <method />
25
+ </configuration>
26
+ </component>
@@ -0,0 +1,5 @@
1
+ <component name="DependencyValidationManager">
2
+ <state>
3
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
4
+ </state>
5
+ </component>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
7
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dichotomy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rino André Johnsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Dichotomy
2
+
3
+ Dichotomy is an Inversion of Control Container for Ruby applications.
4
+
5
+ Dichotomy provides architectural plumbing that allows you to create and manage application components, and acts as the Application Composition layer.
6
+
7
+ ## Features
8
+
9
+ Dichotomy provides:
10
+
11
+ * Simple, dependency injection
12
+ * More to come here
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'dichotomy'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install dichotomy
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/rinoandrejohnsen/dichotomy/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
data/dichotomy.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dichotomy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'dichotomy'
8
+ spec.version = Dichotomy::VERSION
9
+ spec.authors = ['Rino André Johnsen']
10
+ spec.email = ['rinoandrejohnsen@gmail.com']
11
+ spec.summary = %q{Dichotomy is an Inversion of Control Container for Ruby applications.}
12
+ spec.description = %q{Dichotomy provides architectural plumbing that allows you to create and manage application components, and acts as the Application Composition layer.}
13
+ spec.homepage = 'https://github.com/rinoandrejohnsen/dichotomy'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake', '~> 0.9'
23
+
24
+ spec.add_runtime_dependency 'parser', '~> 2.1', '>= 2.1.9'
25
+
26
+ spec.required_ruby_version = '~> 2.0'
27
+ end
@@ -0,0 +1,28 @@
1
+ module Dichotomy
2
+ module Base
3
+ module Extension
4
+ class ContainerExtension
5
+ def initialize_extension(extension_context)
6
+ @context = extension_context
7
+ @context.container.add_observer(self)
8
+ @context.build_manager.add_observer(self)
9
+ initialize_context
10
+ end
11
+
12
+ def update(symbol, type)
13
+ observed_notifications(symbol, type)
14
+ end
15
+
16
+ protected
17
+
18
+ def initialize_context
19
+ raise 'SubclassResponsibility'
20
+ end
21
+
22
+ def observed_notifications(symbol, type)
23
+ raise 'SubclassResponsibility'
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ module Dichotomy
2
+ module Base
3
+ module Extension
4
+ class ExtensionContext
5
+ attr_accessor :container, :build_manager
6
+
7
+ def initialize(container, build_manager)
8
+ @container = container
9
+ @build_manager = build_manager
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ require 'dichotomy/base/managers/builder/strategies/staged_strategy_chain'
2
+ require 'dichotomy/base/managers/builder/build_stage'
3
+ require 'dichotomy/base/managers/builder/build_context'
4
+
5
+ module Dichotomy
6
+ module Base
7
+ module Managers
8
+ class BuildManager
9
+ attr_reader :strategies, :registered_listeners
10
+
11
+ def initialize
12
+ @strategies = Builder::Strategies::StagedStrategyChain.new(Builder::BuildStage)
13
+ @registered_listeners = Array.new
14
+ end
15
+
16
+ def add_observer(klass)
17
+ @registered_listeners.push(klass)
18
+ end
19
+
20
+ def build(type)
21
+ context = Builder::BuildContext.new(@strategies.make_strategy_chain, type, self)
22
+
23
+ @strategies.clear_strategies
24
+
25
+ @registered_listeners.each do |klass|
26
+ context.add_observer(klass)
27
+ end
28
+
29
+ context.strategies.execute_build_up(context)
30
+ end
31
+
32
+ def reset_strategies
33
+ @strategies.clear_strategies
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'observer'
2
+
3
+ module Dichotomy
4
+ module Base
5
+ module Managers
6
+ module Builder
7
+ class BuildContext
8
+ include Observable
9
+
10
+ attr_accessor :strategies, :original_type, :built_type
11
+
12
+ def initialize(strategies, type, build_manager)
13
+ @strategies = strategies
14
+ @original_type = type
15
+ @built_type = nil
16
+ @build_manager = build_manager
17
+ end
18
+
19
+ def new_build_up(type)
20
+ #notify the build_manager that a new build is happening
21
+ changed
22
+
23
+ #submit the type and method name called, so the extensions can add
24
+ #the appropriate strategy for the change
25
+ notify_observers(:new_build_up, type)
26
+
27
+ context = Builder::BuildContext.new(@build_manager.strategies.make_strategy_chain, type, @build_manager)
28
+ @build_manager.registered_listeners.each do |klass|
29
+ context.add_observer(klass)
30
+ end
31
+
32
+ return context.strategies.execute_build_up(context)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ module Dichotomy
2
+ module Base
3
+ module Managers
4
+ module Builder
5
+ module BuildStage
6
+ # First stage. By default, nothing happens here.
7
+ SETUP = 0
8
+
9
+ # Second stage. Reflection over constructors, properties, etc. is performed here.
10
+ PRE_CREATION = 1
11
+
12
+ # Third stage. Instance creation happens here.
13
+ CREATION = 2
14
+
15
+ # Fourth stage. Property sets and method injection happens here.
16
+ INITIALIZATION = 3
17
+
18
+ # Fifth and final stage. By default, nothing happens here.
19
+ POST_INITIALIZATION = 4
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'dichotomy/base/managers/builder/strategies/strategy_chain'
2
+
3
+ module Dichotomy
4
+ module Base
5
+ module Managers
6
+ module Builder
7
+ module Strategies
8
+ class StagedStrategyChain
9
+ def initialize(build_stage)
10
+ @stages = Array.new(build_stage.constants(false).length) { Array.new }
11
+ end
12
+
13
+ def add(strategy, build_stage)
14
+ @stages[build_stage].push(strategy)
15
+ end
16
+
17
+ def make_strategy_chain
18
+ strategy_chain = StrategyChain.new
19
+
20
+ @stages.each do |stage|
21
+ strategy_chain.add_range(stage)
22
+ end
23
+
24
+ strategy_chain
25
+ end
26
+
27
+ def clear_strategies
28
+ @stages.each do |stage|
29
+ stage.clear
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ module Dichotomy
2
+ module Base
3
+ module Managers
4
+ module Builder
5
+ module Strategies
6
+ class StrategyChain
7
+ def initialize
8
+ @strategies = Array.new
9
+ end
10
+
11
+ def add(strategy)
12
+ @strategies.push(strategy)
13
+ end
14
+
15
+ def add_range(strategy_array)
16
+ strategy_array.each do |strategy|
17
+ @strategies.push(strategy)
18
+ end
19
+ end
20
+
21
+ def execute_build_up(build_context)
22
+ @strategies.each do |strategy|
23
+ strategy.pre_build_up(build_context)
24
+ end
25
+ @strategies.each do |strategy|
26
+ strategy.post_build_up(build_context)
27
+ end
28
+
29
+ puts 'completed the build'
30
+
31
+ build_context.built_type
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'observer'
2
+ require 'dichotomy/extensions/default_extension'
3
+ require 'dichotomy/extensions/test_extension'
4
+ require 'dichotomy/base/extension/extension_context'
5
+ require 'dichotomy/base/managers/build_manager'
6
+
7
+ module Dichotomy
8
+ class Container
9
+ include Observable
10
+
11
+ def initialize
12
+ @build_manager = Base::Managers::BuildManager.new
13
+ @extensions = Array.new
14
+ add_extension(Extensions::DefaultExtension.new)
15
+ add_extension(Extensions::TestExtension.new)
16
+ end
17
+
18
+ #methods mixed in from DefaultExtension
19
+ # - register_type(type) : returns Subject
20
+ # - resolve_type(type) : returns Object
21
+
22
+ def add_extension(extension)
23
+ @extensions.push(extension)
24
+ extension.initialize_extension(Base::Extension::ExtensionContext.new(self, @build_manager))
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,40 @@
1
+ require 'dichotomy/base/extension/container_extension'
2
+ require 'dichotomy/extensions/defaults/extension_methods'
3
+ require 'dichotomy/extensions/defaults/strategies/pre_creation_strategy'
4
+ require 'dichotomy/extensions/defaults/strategies/default_resolve_strategy'
5
+ require 'dichotomy/base/managers/builder/build_stage'
6
+
7
+ module Dichotomy
8
+ module Extensions
9
+ class DefaultExtension < Base::Extension::ContainerExtension
10
+ def initialize_context
11
+ @context.container.extend(Defaults::ExtensionMethods)
12
+ end
13
+
14
+ def observed_notifications(symbol, type)
15
+ if symbol === :register_type
16
+ on_register_type(type)
17
+ end
18
+
19
+ if symbol === :resolve_type
20
+ #if type == subject -> build_object
21
+ #if type != subject -> build_subject -> build_object
22
+
23
+ on_resolve_type(type)
24
+ end
25
+
26
+ if symbol === :new_build_up
27
+ on_register_type(type) # by example
28
+ end
29
+ end
30
+
31
+ def on_register_type(type)
32
+ @context.build_manager.strategies.add(Defaults::Strategies::PreCreationStrategy.new, Base::Managers::Builder::BuildStage::PRE_CREATION)
33
+ end
34
+
35
+ def on_resolve_type(type)
36
+ @context.build_manager.strategies.add(Defaults::Strategies::DefaultResolveStrategy.new, Base::Managers::Builder::BuildStage::PRE_CREATION)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ module Dichotomy
2
+ module Extensions
3
+ module Defaults
4
+ module ExtensionMethods
5
+ def register_type(type)
6
+ notify(:register_type, type)
7
+
8
+ #all the strategies are now added to the build manager from all the extensions
9
+ @build_manager.build(type)
10
+ end
11
+
12
+ def resolve_type(type)
13
+ notify(:resolve_type, type)
14
+
15
+ #all the strategies are now added to the build manager from all the extensions
16
+ @build_manager.build(type)
17
+ end
18
+
19
+ private
20
+
21
+ def notify(symbol, type)
22
+ #notify the extensions that a change has occurred
23
+ changed
24
+
25
+ #submit the type and method name called, so the extensions can add
26
+ #the appropriate strategy for the change
27
+ notify_observers(symbol, type)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Dichotomy
2
+ module Extensions
3
+ module Defaults
4
+ module Strategies
5
+ class DefaultResolveStrategy
6
+ def pre_build_up(build_context)
7
+ puts 'resolve_pre_build_up'
8
+
9
+ build_context.new_build_up(Class)
10
+ end
11
+
12
+ def post_build_up(build_context)
13
+ puts 'resolve_post_build_up'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Dichotomy
2
+ module Extensions
3
+ module Defaults
4
+ module Strategies
5
+ class PreCreationStrategy
6
+ def pre_build_up(build_context)
7
+ puts 'PreCreationStrategy_pre_build_up'
8
+ end
9
+
10
+ def post_build_up(build_context)
11
+ puts 'PreCreationStrategy_post_build_up'
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module Dichotomy
2
+ module Extensions
3
+ module Defaults
4
+ module Strategies
5
+ module Reflectors
6
+ class ClassReflector
7
+
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ require 'parser/current'
2
+
3
+ module Dichotomy
4
+ module Extensions
5
+ module Defaults
6
+ module Strategies
7
+ module Reflectors
8
+ module Source
9
+ class SourceAnalyser
10
+ def initialize
11
+ @parser = Parser::CurrentRuby.new
12
+ end
13
+
14
+ def analyse(filename)
15
+ buffer = Parser::Source::Buffer.new(filename).read
16
+ ast = @parser.parse(buffer)
17
+ source_interpreter = SourceInterpreter.new
18
+ subject = source_interpreter.create_subject(buffer, ast)
19
+
20
+ @parser.reset
21
+ p ast
22
+
23
+ subject
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,59 @@
1
+ require 'parser/current'
2
+
3
+ module Dichotomy
4
+ module Extensions
5
+ module Defaults
6
+ module Strategies
7
+ module Reflectors
8
+ module Source
9
+ class SourceInterpreter < Parser::Rewriter
10
+ def initialize
11
+ @subject = Common::Models::Subject.new('')
12
+ end
13
+
14
+ def on_begin(node)
15
+ @node = node
16
+
17
+ name = @node.location.expression.source_buffer.name
18
+ @subject.filename = name
19
+ @subject.name = name[/([^\/]+)$/].chomp('.rb')
20
+
21
+ find_methods
22
+ #find_dependencies
23
+ end
24
+
25
+ def create_subject(buffer, ast)
26
+ self.rewrite(buffer, ast)
27
+ @subject
28
+ end
29
+
30
+ private
31
+
32
+ def find_methods
33
+ @node.children.each do |child_node|
34
+ if child_node.location.kind_of?(Parser::Source::Map::Definition)
35
+ arguments_node = child_node.children[1]
36
+
37
+ argumentsHash = Array.new
38
+
39
+ arguments_node.children.each do |args_child_node|
40
+ args_child_node.children.each do |arg|
41
+ if child_node.children[0].eql? :initialize # add check for Symbol
42
+ @subject.dependencies.push(Common::Models::SubjectDependency.new(arg))
43
+ end
44
+
45
+ argumentsHash.push(arg)
46
+ end
47
+ end
48
+
49
+ @subject.methods.push(Common::Models::SubjectMethod.new(child_node.children[0], argumentsHash))
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,32 @@
1
+ require 'dichotomy/base/extension/container_extension'
2
+ require 'dichotomy/extensions/tests/strategies/default_subject_strategy'
3
+
4
+ module Dichotomy
5
+ module Extensions
6
+ class TestExtension < Base::Extension::ContainerExtension
7
+ def initialize_context
8
+
9
+ end
10
+
11
+ def on_register_type(type)
12
+ @context.build_manager.strategies.add(Tests::Strategies::TestSubjectStrategy.new, 1)
13
+ end
14
+
15
+ def observed_notifications(symbol, type)
16
+ # catches the event from DefaultStrategy
17
+ if symbol === :register_type
18
+ on_register_type(type)
19
+ end
20
+
21
+ #remove me after test
22
+ if symbol === :resolve_type
23
+ on_register_type(type)
24
+ end
25
+
26
+ if symbol === :new_build_up
27
+ on_register_type(type)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ module Dichotomy
2
+ module Extensions
3
+ module Tests
4
+ module Strategies
5
+ class TestSubjectStrategy
6
+ def pre_build_up(build_context)
7
+ puts 'test_pre_build_up'
8
+ build_context.built_type = Class.new
9
+ end
10
+
11
+ def post_build_up(build_context)
12
+ puts 'test_post_build_up'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Dichotomy
2
+ VERSION = '0.0.1'
3
+ end
data/lib/dichotomy.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Dichotomy
2
+ require 'dichotomy/version'
3
+ require 'dichotomy/container'
4
+ end
data/lib/example.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'dichotomy'
2
+ require 'example_dependency'
3
+
4
+ dichotomy_container = Dichotomy::Container.new
5
+ subject = dichotomy_container.register_type(ExampleDependency)
6
+
7
+ debug = nil
@@ -0,0 +1,13 @@
1
+ class ExampleDependency
2
+ def run
3
+ puts 'run'
4
+ end
5
+
6
+ def pause
7
+ puts 'pause'
8
+ end
9
+
10
+ def stop
11
+ puts 'stop'
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dichotomy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rino André Johnsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parser
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.1.9
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.1.9
61
+ description: Dichotomy provides architectural plumbing that allows you to create and
62
+ manage application components, and acts as the Application Composition layer.
63
+ email:
64
+ - rinoandrejohnsen@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - ".idea/.name"
71
+ - ".idea/.rakeTasks"
72
+ - ".idea/dichotomy.iml"
73
+ - ".idea/encodings.xml"
74
+ - ".idea/misc.xml"
75
+ - ".idea/modules.xml"
76
+ - ".idea/runConfigurations/example.xml"
77
+ - ".idea/scopes/scope_settings.xml"
78
+ - ".idea/vcs.xml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - dichotomy.gemspec
84
+ - lib/dichotomy.rb
85
+ - lib/dichotomy/base/extension/container_extension.rb
86
+ - lib/dichotomy/base/extension/extension_context.rb
87
+ - lib/dichotomy/base/managers/build_manager.rb
88
+ - lib/dichotomy/base/managers/builder/build_context.rb
89
+ - lib/dichotomy/base/managers/builder/build_stage.rb
90
+ - lib/dichotomy/base/managers/builder/strategies/staged_strategy_chain.rb
91
+ - lib/dichotomy/base/managers/builder/strategies/strategy_chain.rb
92
+ - lib/dichotomy/container.rb
93
+ - lib/dichotomy/extensions/default_extension.rb
94
+ - lib/dichotomy/extensions/defaults/extension_methods.rb
95
+ - lib/dichotomy/extensions/defaults/strategies/default_resolve_strategy.rb
96
+ - lib/dichotomy/extensions/defaults/strategies/pre_creation_strategy.rb
97
+ - lib/dichotomy/extensions/defaults/strategies/reflectors/class_reflector.rb
98
+ - lib/dichotomy/extensions/defaults/strategies/reflectors/source/source_analyser.rb
99
+ - lib/dichotomy/extensions/defaults/strategies/reflectors/source/source_interpreter.rb
100
+ - lib/dichotomy/extensions/test_extension.rb
101
+ - lib/dichotomy/extensions/tests/strategies/default_subject_strategy.rb
102
+ - lib/dichotomy/version.rb
103
+ - lib/example.rb
104
+ - lib/example_dependency.rb
105
+ homepage: https://github.com/rinoandrejohnsen/dichotomy
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Dichotomy is an Inversion of Control Container for Ruby applications.
129
+ test_files: []