dichotomy 0.0.1 → 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 +4 -4
- data/.idea/dichotomy.iml +26 -15
- data/lib/dichotomy/base/managers/build_manager.rb +9 -2
- data/lib/dichotomy/base/managers/builder/build_context.rb +4 -3
- data/lib/dichotomy/base/managers/builder/strategies/strategy_chain.rb +3 -1
- data/lib/dichotomy/container.rb +15 -4
- data/lib/dichotomy/extensions/default_extension.rb +9 -4
- data/lib/dichotomy/extensions/defaults/strategies/creation_strategy.rb +29 -0
- data/lib/dichotomy/extensions/defaults/strategies/default_resolve_strategy.rb +3 -3
- data/lib/dichotomy/extensions/defaults/strategies/pre_creation_strategy.rb +8 -2
- data/lib/dichotomy/extensions/defaults/strategies/reflectors/class_reflector.rb +42 -0
- data/lib/dichotomy/extensions/defaults/strategies/reflectors/source/{source_analyser.rb → analyser.rb} +6 -5
- data/lib/dichotomy/extensions/defaults/strategies/reflectors/source/interpreter.rb +97 -0
- data/lib/dichotomy/extensions/defaults/strategies/reflectors/source/rapport.rb +28 -0
- data/lib/dichotomy/extensions/defaults/strategies/types/subject.rb +26 -0
- data/lib/dichotomy/extensions/tests/strategies/default_subject_strategy.rb +4 -3
- data/lib/dichotomy/version.rb +1 -1
- data/lib/example.rb +5 -1
- data/lib/example_dependency.rb +4 -0
- data/lib/example_dependency_two.rb +15 -0
- metadata +9 -5
- data/lib/dichotomy/extensions/defaults/strategies/reflectors/source/source_interpreter.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dffbc24f094d52d7e9d7d031ae5aceda1ed9054
|
4
|
+
data.tar.gz: 9873026454c3399da28af783758554904c685f00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 533d135534e7d20bd8de474b68b1bcc217785ab821b2d0529984fd3bf9a115e66b75794b3f76744fe61ad10a4ca69b9462be065440f09ebd97621948178563b9
|
7
|
+
data.tar.gz: 21a84c6b0ce5f78b8eadc373ad2a829f35f63a28981187bef34ebd9725ab414bd74c830a6d3e12809970eb22d87ffdde2ed040ac00f71560af417f5fec8240d5
|
data/.idea/dichotomy.iml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="CompassSettings">
|
4
|
+
<option name="compassSupportEnabled" value="true" />
|
5
|
+
</component>
|
3
6
|
<component name="FacetManager">
|
4
7
|
<facet type="gem" name="Ruby Gem">
|
5
8
|
<configuration>
|
@@ -56,6 +59,28 @@
|
|
56
59
|
<ConfigurationWrapper RunnerId="RubyRunner" />
|
57
60
|
<method />
|
58
61
|
</configuration>
|
62
|
+
<configuration default="false" name="container" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
|
63
|
+
<module name="dichotomy" />
|
64
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
65
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/lib/dichotomy" />
|
66
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
67
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
68
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
69
|
+
<envs />
|
70
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
71
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
72
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
73
|
+
<COVERAGE_PATTERN ENABLED="true">
|
74
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
75
|
+
</COVERAGE_PATTERN>
|
76
|
+
</EXTENSION>
|
77
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
78
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/lib/dichotomy/container.rb" />
|
79
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
80
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
81
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
82
|
+
<method />
|
83
|
+
</configuration>
|
59
84
|
</component>
|
60
85
|
<component name="NewModuleRootManager">
|
61
86
|
<content url="file://$MODULE_DIR$">
|
@@ -63,22 +88,8 @@
|
|
63
88
|
</content>
|
64
89
|
<orderEntry type="jdk" jdkName="RVM: ruby-2.1.2" jdkType="RUBY_SDK" />
|
65
90
|
<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
91
|
<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.
|
92
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.6.3, RVM: ruby-2.1.2) [gem]" level="application" />
|
82
93
|
<orderEntry type="library" scope="PROVIDED" name="parser (v2.1.9, RVM: ruby-2.1.2) [gem]" level="application" />
|
83
94
|
<orderEntry type="library" scope="PROVIDED" name="rake (v0.9.6, RVM: ruby-2.1.2) [gem]" level="application" />
|
84
95
|
<orderEntry type="library" scope="PROVIDED" name="slop (v3.5.0, RVM: ruby-2.1.2) [gem]" level="application" />
|
@@ -11,6 +11,7 @@ module Dichotomy
|
|
11
11
|
def initialize
|
12
12
|
@strategies = Builder::Strategies::StagedStrategyChain.new(Builder::BuildStage)
|
13
13
|
@registered_listeners = Array.new
|
14
|
+
@registered_types = Array.new
|
14
15
|
end
|
15
16
|
|
16
17
|
def add_observer(klass)
|
@@ -18,7 +19,7 @@ module Dichotomy
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def build(type)
|
21
|
-
context = Builder::BuildContext.new(@strategies.make_strategy_chain, type, self)
|
22
|
+
context = Builder::BuildContext.new(@strategies.make_strategy_chain, type, self, @registered_types)
|
22
23
|
|
23
24
|
@strategies.clear_strategies
|
24
25
|
|
@@ -26,7 +27,13 @@ module Dichotomy
|
|
26
27
|
context.add_observer(klass)
|
27
28
|
end
|
28
29
|
|
29
|
-
context.strategies.execute_build_up(context)
|
30
|
+
type = context.strategies.execute_build_up(context)
|
31
|
+
|
32
|
+
if (type)
|
33
|
+
@registered_types.push(type)
|
34
|
+
end
|
35
|
+
|
36
|
+
type
|
30
37
|
end
|
31
38
|
|
32
39
|
def reset_strategies
|
@@ -7,13 +7,14 @@ module Dichotomy
|
|
7
7
|
class BuildContext
|
8
8
|
include Observable
|
9
9
|
|
10
|
-
attr_accessor :strategies, :original_type, :built_type
|
10
|
+
attr_accessor :strategies, :original_type, :built_type, :registered_types
|
11
11
|
|
12
|
-
def initialize(strategies, type, build_manager)
|
12
|
+
def initialize(strategies, type, build_manager, types)
|
13
13
|
@strategies = strategies
|
14
14
|
@original_type = type
|
15
15
|
@built_type = nil
|
16
16
|
@build_manager = build_manager
|
17
|
+
@registered_types = types
|
17
18
|
end
|
18
19
|
|
19
20
|
def new_build_up(type)
|
@@ -24,7 +25,7 @@ module Dichotomy
|
|
24
25
|
#the appropriate strategy for the change
|
25
26
|
notify_observers(:new_build_up, type)
|
26
27
|
|
27
|
-
context = Builder::BuildContext.new(@build_manager.strategies.make_strategy_chain, type, @build_manager)
|
28
|
+
context = Builder::BuildContext.new(@build_manager.strategies.make_strategy_chain, type, @build_manager, @registered_types)
|
28
29
|
@build_manager.registered_listeners.each do |klass|
|
29
30
|
context.add_observer(klass)
|
30
31
|
end
|
@@ -19,6 +19,8 @@ module Dichotomy
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def execute_build_up(build_context)
|
22
|
+
|
23
|
+
|
22
24
|
@strategies.each do |strategy|
|
23
25
|
strategy.pre_build_up(build_context)
|
24
26
|
end
|
@@ -26,7 +28,7 @@ module Dichotomy
|
|
26
28
|
strategy.post_build_up(build_context)
|
27
29
|
end
|
28
30
|
|
29
|
-
puts 'completed the build'
|
31
|
+
puts ' --**-- completed the build --**-- '
|
30
32
|
|
31
33
|
build_context.built_type
|
32
34
|
end
|
data/lib/dichotomy/container.rb
CHANGED
@@ -15,13 +15,24 @@ module Dichotomy
|
|
15
15
|
add_extension(Extensions::TestExtension.new)
|
16
16
|
end
|
17
17
|
|
18
|
-
#methods mixed in from DefaultExtension
|
19
|
-
# - register_type(type) : returns Subject
|
20
|
-
# - resolve_type(type) : returns Object
|
21
|
-
|
22
18
|
def add_extension(extension)
|
23
19
|
@extensions.push(extension)
|
24
20
|
extension.initialize_extension(Base::Extension::ExtensionContext.new(self, @build_manager))
|
25
21
|
end
|
22
|
+
|
23
|
+
def method_missing(m, *args, &block)
|
24
|
+
symbol = m.to_sym
|
25
|
+
type = args[0]
|
26
|
+
|
27
|
+
notify(symbol, type)
|
28
|
+
|
29
|
+
@build_manager.build(type)
|
30
|
+
end
|
31
|
+
|
32
|
+
def notify(symbol, type)
|
33
|
+
changed
|
34
|
+
|
35
|
+
notify_observers(symbol, type)
|
36
|
+
end
|
26
37
|
end
|
27
38
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'dichotomy/base/extension/container_extension'
|
2
2
|
require 'dichotomy/extensions/defaults/extension_methods'
|
3
3
|
require 'dichotomy/extensions/defaults/strategies/pre_creation_strategy'
|
4
|
+
require 'dichotomy/extensions/defaults/strategies/creation_strategy'
|
4
5
|
require 'dichotomy/extensions/defaults/strategies/default_resolve_strategy'
|
5
6
|
require 'dichotomy/base/managers/builder/build_stage'
|
6
7
|
|
@@ -8,28 +9,32 @@ module Dichotomy
|
|
8
9
|
module Extensions
|
9
10
|
class DefaultExtension < Base::Extension::ContainerExtension
|
10
11
|
def initialize_context
|
11
|
-
|
12
|
+
#@context.container.extend(Defaults::ExtensionMethods)
|
12
13
|
end
|
13
14
|
|
14
15
|
def observed_notifications(symbol, type)
|
15
16
|
if symbol === :register_type
|
16
17
|
on_register_type(type)
|
18
|
+
|
19
|
+
puts "Running: " + symbol.to_s
|
17
20
|
end
|
18
21
|
|
19
22
|
if symbol === :resolve_type
|
20
|
-
#if type == subject -> build_object
|
21
|
-
#if type != subject -> build_subject -> build_object
|
22
|
-
|
23
23
|
on_resolve_type(type)
|
24
|
+
|
25
|
+
puts "Running: " + symbol.to_s
|
24
26
|
end
|
25
27
|
|
26
28
|
if symbol === :new_build_up
|
27
29
|
on_register_type(type) # by example
|
30
|
+
|
31
|
+
puts "Running: " + symbol.to_s
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def on_register_type(type)
|
32
36
|
@context.build_manager.strategies.add(Defaults::Strategies::PreCreationStrategy.new, Base::Managers::Builder::BuildStage::PRE_CREATION)
|
37
|
+
@context.build_manager.strategies.add(Defaults::Strategies::CreationStrategy.new, Base::Managers::Builder::BuildStage::CREATION)
|
33
38
|
end
|
34
39
|
|
35
40
|
def on_resolve_type(type)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'dichotomy/extensions/defaults/strategies/types/subject'
|
2
|
+
|
3
|
+
module Dichotomy
|
4
|
+
module Extensions
|
5
|
+
module Defaults
|
6
|
+
module Strategies
|
7
|
+
class CreationStrategy
|
8
|
+
def pre_build_up(build_context)
|
9
|
+
built_type = build_context.built_type
|
10
|
+
|
11
|
+
subject = Types::Subject.new
|
12
|
+
subject.name = build_context.original_type.to_s.to_sym
|
13
|
+
subject.methods = built_type.methods
|
14
|
+
subject.properties = built_type.properties
|
15
|
+
subject.dependencies = built_type.dependencies
|
16
|
+
subject.filename = built_type.filename
|
17
|
+
subject.id = built_type.id
|
18
|
+
|
19
|
+
build_context.built_type = subject
|
20
|
+
end
|
21
|
+
|
22
|
+
def post_build_up(build_context)
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -4,13 +4,13 @@ module Dichotomy
|
|
4
4
|
module Strategies
|
5
5
|
class DefaultResolveStrategy
|
6
6
|
def pre_build_up(build_context)
|
7
|
-
puts 'resolve_pre_build_up'
|
8
7
|
|
9
|
-
|
8
|
+
|
9
|
+
#build_context.new_build_up(Class)
|
10
10
|
end
|
11
11
|
|
12
12
|
def post_build_up(build_context)
|
13
|
-
|
13
|
+
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -1,14 +1,20 @@
|
|
1
|
+
require 'dichotomy/extensions/defaults/strategies/reflectors/class_reflector'
|
2
|
+
|
1
3
|
module Dichotomy
|
2
4
|
module Extensions
|
3
5
|
module Defaults
|
4
6
|
module Strategies
|
5
7
|
class PreCreationStrategy
|
6
8
|
def pre_build_up(build_context)
|
7
|
-
|
9
|
+
original_type = build_context.original_type
|
10
|
+
|
11
|
+
class_reflector = Reflectors::ClassReflector.new
|
12
|
+
|
13
|
+
build_context.built_type = class_reflector.create_rapport(original_type)
|
8
14
|
end
|
9
15
|
|
10
16
|
def post_build_up(build_context)
|
11
|
-
|
17
|
+
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
@@ -1,10 +1,52 @@
|
|
1
|
+
require 'dichotomy/extensions/defaults/strategies/reflectors/source/analyser'
|
2
|
+
|
1
3
|
module Dichotomy
|
2
4
|
module Extensions
|
3
5
|
module Defaults
|
4
6
|
module Strategies
|
5
7
|
module Reflectors
|
6
8
|
class ClassReflector
|
9
|
+
def initialize
|
10
|
+
@analyser = Source::Analyser.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_rapport(klass)
|
14
|
+
source_location = get_source_location(klass)
|
15
|
+
rapport = @analyser.analyse(source_location[0]) # perhaps support all files?
|
16
|
+
rapport
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_source_location(klass)
|
22
|
+
source_locations = is_class(klass)
|
23
|
+
if source_locations.empty?
|
24
|
+
methods = defined_methods(klass)
|
25
|
+
raise ArgumentError, (methods.empty? ? "#{klass} has no methods" : "#{klass} only has built-in methods (#{methods.size} in total)")
|
26
|
+
end
|
27
|
+
source_locations[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_class(klass)
|
31
|
+
methods = defined_methods(klass)
|
32
|
+
file_groups = methods.group_by{|sl| sl[0]}
|
33
|
+
file_counts = file_groups.map do |file, sls|
|
34
|
+
lines = sls.map{|sl| sl[1]}
|
35
|
+
count = lines.size
|
36
|
+
line = lines.min
|
37
|
+
{file: file, count: count, line: line}
|
38
|
+
end
|
39
|
+
file_counts.sort_by!{|fc| fc[:count]}
|
40
|
+
source_locations = file_counts.map{|fc| [fc[:file], fc[:line]]}
|
41
|
+
source_locations
|
42
|
+
end
|
7
43
|
|
44
|
+
def defined_methods(klass)
|
45
|
+
methods = klass.methods(false).map{|m| klass.method(m)} + klass.instance_methods(false).map{|m| klass.instance_method(m)}
|
46
|
+
methods.map!(&:source_location)
|
47
|
+
methods.compact!
|
48
|
+
methods
|
49
|
+
end
|
8
50
|
end
|
9
51
|
end
|
10
52
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'parser/current'
|
2
|
+
require 'dichotomy/extensions/defaults/strategies/reflectors/source/interpreter'
|
2
3
|
|
3
4
|
module Dichotomy
|
4
5
|
module Extensions
|
@@ -6,7 +7,7 @@ module Dichotomy
|
|
6
7
|
module Strategies
|
7
8
|
module Reflectors
|
8
9
|
module Source
|
9
|
-
class
|
10
|
+
class Analyser
|
10
11
|
def initialize
|
11
12
|
@parser = Parser::CurrentRuby.new
|
12
13
|
end
|
@@ -14,13 +15,13 @@ module Dichotomy
|
|
14
15
|
def analyse(filename)
|
15
16
|
buffer = Parser::Source::Buffer.new(filename).read
|
16
17
|
ast = @parser.parse(buffer)
|
17
|
-
|
18
|
-
|
18
|
+
interpreter = Interpreter.new
|
19
|
+
rapport = interpreter.create_rapport(buffer, ast)
|
19
20
|
|
20
21
|
@parser.reset
|
21
|
-
p ast
|
22
|
+
#p ast
|
22
23
|
|
23
|
-
|
24
|
+
rapport
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'parser/current'
|
2
|
+
require 'dichotomy/extensions/defaults/strategies/reflectors/source/rapport'
|
3
|
+
|
4
|
+
module Dichotomy
|
5
|
+
module Extensions
|
6
|
+
module Defaults
|
7
|
+
module Strategies
|
8
|
+
module Reflectors
|
9
|
+
module Source
|
10
|
+
class Interpreter < Parser::Rewriter
|
11
|
+
def initialize
|
12
|
+
@rapport = Rapport.new('')
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_begin(node)
|
16
|
+
@node = node
|
17
|
+
|
18
|
+
name = @node.location.expression.source_buffer.name
|
19
|
+
@rapport.filename = name
|
20
|
+
@rapport.name = name[/([^\/]+)$/].chomp('.rb')
|
21
|
+
|
22
|
+
find_methods
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_rapport(buffer, ast)
|
26
|
+
self.rewrite(buffer, ast)
|
27
|
+
@rapport
|
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
|
+
if child_node.children[0].eql? :initialize # add check for Symbol
|
36
|
+
if child_node.children[1].children[0] != nil
|
37
|
+
find_dependencies(child_node)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
arguments_hash = Array.new
|
41
|
+
|
42
|
+
if child_node.children[1].children[0] != nil
|
43
|
+
child_node.children[1].children.each do |argument_variable|
|
44
|
+
arguments_hash.push(argument_variable.children[0])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
@rapport.methods.push({child_node.children[0] => arguments_hash})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def find_dependencies(node)
|
55
|
+
node.children[1].children.each_with_index do |dependency_variable, index|
|
56
|
+
if node.children[2]
|
57
|
+
variable = node.children[2].children[index]
|
58
|
+
|
59
|
+
if (variable.kind_of?(Symbol))
|
60
|
+
@rapport.dependencies[dependency_variable.children[0]] = look_for_methods_on_variable(variable)
|
61
|
+
else
|
62
|
+
if variable.children[0].kind_of?(Symbol)
|
63
|
+
@rapport.dependencies[dependency_variable.children[0]] = look_for_methods_on_variable(variable.children[0])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def look_for_methods_on_variable(variables)
|
72
|
+
methods = Array.new
|
73
|
+
@node.children.each do |child_node|
|
74
|
+
if child_node.location.kind_of?(Parser::Source::Map::Definition) && !child_node.children[0].eql?(:initialize)
|
75
|
+
argumentsHash = Array.new
|
76
|
+
|
77
|
+
child_node.children[2].children.each do |variable|
|
78
|
+
if variable.location.kind_of?(Parser::Source::Map::Send)
|
79
|
+
variable.children[0].children.each do |tt|
|
80
|
+
if tt === variables
|
81
|
+
methods.push({:method => variable.children[1]})
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
methods
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Dichotomy
|
2
|
+
module Extensions
|
3
|
+
module Defaults
|
4
|
+
module Strategies
|
5
|
+
module Reflectors
|
6
|
+
module Source
|
7
|
+
class Rapport
|
8
|
+
attr_accessor :id, :name, :methods, :properties, :dependencies, :filename
|
9
|
+
|
10
|
+
def initialize(name, methods = Array.new, properties = Array.new, dependencies = Hash.new, filename = '')
|
11
|
+
@name = name
|
12
|
+
@methods = methods
|
13
|
+
@properties = properties
|
14
|
+
@dependencies = dependencies
|
15
|
+
@filename = filename
|
16
|
+
@id = rand(36**8).to_s(36) # a simple solution
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_dependencies?
|
20
|
+
return !@dependencies.empty?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Dichotomy
|
2
|
+
module Extensions
|
3
|
+
module Defaults
|
4
|
+
module Strategies
|
5
|
+
module Types
|
6
|
+
class Subject
|
7
|
+
attr_accessor :id, :name, :methods, :properties, :dependencies, :filename
|
8
|
+
|
9
|
+
def initialize(name = '', methods = Array.new, properties = Array.new, dependencies = Array.new, filename = '')
|
10
|
+
@name = name
|
11
|
+
@methods = methods
|
12
|
+
@properties = properties
|
13
|
+
@dependencies = dependencies
|
14
|
+
@filename = filename
|
15
|
+
@id = rand(36**8).to_s(36) # a simple solution
|
16
|
+
end
|
17
|
+
|
18
|
+
def has_dependencies?
|
19
|
+
return !@dependencies.empty?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,12 +4,13 @@ module Dichotomy
|
|
4
4
|
module Strategies
|
5
5
|
class TestSubjectStrategy
|
6
6
|
def pre_build_up(build_context)
|
7
|
-
|
8
|
-
build_context.built_type = Class.new
|
7
|
+
|
8
|
+
#build_context.built_type = Class.new
|
9
|
+
#build_context
|
9
10
|
end
|
10
11
|
|
11
12
|
def post_build_up(build_context)
|
12
|
-
|
13
|
+
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
data/lib/dichotomy/version.rb
CHANGED
data/lib/example.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'dichotomy'
|
2
2
|
require 'example_dependency'
|
3
|
+
require 'example_dependency_two'
|
3
4
|
|
4
5
|
dichotomy_container = Dichotomy::Container.new
|
5
|
-
|
6
|
+
example_dependency_subject = dichotomy_container.register_type(ExampleDependency)
|
7
|
+
example_dependency_subject_two = dichotomy_container.register_type(ExampleDependencyTwo)
|
8
|
+
|
9
|
+
dichotomy_container.resolve_type(example_dependency_subject_two)
|
6
10
|
|
7
11
|
debug = nil
|
data/lib/example_dependency.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dichotomy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rino André Johnsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,16 +92,20 @@ files:
|
|
92
92
|
- lib/dichotomy/container.rb
|
93
93
|
- lib/dichotomy/extensions/default_extension.rb
|
94
94
|
- lib/dichotomy/extensions/defaults/extension_methods.rb
|
95
|
+
- lib/dichotomy/extensions/defaults/strategies/creation_strategy.rb
|
95
96
|
- lib/dichotomy/extensions/defaults/strategies/default_resolve_strategy.rb
|
96
97
|
- lib/dichotomy/extensions/defaults/strategies/pre_creation_strategy.rb
|
97
98
|
- lib/dichotomy/extensions/defaults/strategies/reflectors/class_reflector.rb
|
98
|
-
- lib/dichotomy/extensions/defaults/strategies/reflectors/source/
|
99
|
-
- lib/dichotomy/extensions/defaults/strategies/reflectors/source/
|
99
|
+
- lib/dichotomy/extensions/defaults/strategies/reflectors/source/analyser.rb
|
100
|
+
- lib/dichotomy/extensions/defaults/strategies/reflectors/source/interpreter.rb
|
101
|
+
- lib/dichotomy/extensions/defaults/strategies/reflectors/source/rapport.rb
|
102
|
+
- lib/dichotomy/extensions/defaults/strategies/types/subject.rb
|
100
103
|
- lib/dichotomy/extensions/test_extension.rb
|
101
104
|
- lib/dichotomy/extensions/tests/strategies/default_subject_strategy.rb
|
102
105
|
- lib/dichotomy/version.rb
|
103
106
|
- lib/example.rb
|
104
107
|
- lib/example_dependency.rb
|
108
|
+
- lib/example_dependency_two.rb
|
105
109
|
homepage: https://github.com/rinoandrejohnsen/dichotomy
|
106
110
|
licenses:
|
107
111
|
- MIT
|
@@ -122,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
126
|
version: '0'
|
123
127
|
requirements: []
|
124
128
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.3.0
|
126
130
|
signing_key:
|
127
131
|
specification_version: 4
|
128
132
|
summary: Dichotomy is an Inversion of Control Container for Ruby applications.
|
@@ -1,59 +0,0 @@
|
|
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
|