mushin 0.20.0 → 0.21.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d775c97f25d67be4bf5097f4d9e8c929cd6d2d1
4
- data.tar.gz: 2eb69bef12544766c94fc57cab9ddb99102b96c0
3
+ metadata.gz: f67105bfa6f8dbfbdfd3e60fe89e887a4d42cc68
4
+ data.tar.gz: 5084494b7f7bf55fd132c2afb600d6ffb8e48340
5
5
  SHA512:
6
- metadata.gz: 98bea9dee28d88006ee3e7e0c01af2b84f5b79d36118d825026847f782dae77ecd530cda7962a407c463bcf6335d8c6fe0ec383bba148976c4540aa0e9deda58
7
- data.tar.gz: d858b14ab9e0882a47fd5014c2319ae48eb288dae7279665d129ade60ea88a065b8ed5f0f439b0c55407e56d72374f376926fb4040ac36cebe0eb8db98db956f
6
+ metadata.gz: 29fbdd6ab06b156d45ffdec6efe6588c12a094009daab4bf8532182114721238ce593752249483b4f396144d5421c7fc654afb0c1f1a41fe9704ef972c8a9aaf
7
+ data.tar.gz: 746f1c42cb702705c4af1cef8b09b571cea51e879e254f0c3c09a429288c26177a4bd50ed4e38cf803f96a316dfb050fca2a89e7f1dbfe4b8552297947ffbff7
data/lib/mushin/main.rb CHANGED
@@ -4,6 +4,7 @@ require 'set'
4
4
  #TODO release 1.0rc
5
5
 
6
6
  module Mushin
7
+ #TODO maybe use refinements instead of inheritance for `using Mushin::Ext`
7
8
  class Store < Mushin::Test::Sample::Ext
8
9
  def initialize(ext, opts = {}, params= {})
9
10
  @ext = ext
@@ -20,7 +21,7 @@ module Mushin
20
21
 
21
22
  module Domain
22
23
  refine Class do
23
- #TODO apply advanced centerlized logging automatically via TracePoint, DEBUG log level
24
+ #TODO apply advanced centerlized logging automatically via TracePoint, DEBUG log level, to save space of the other logging and make it more standarized style
24
25
  #trace = TracePoint.new(:c_call) do |tp| # p [tp.lineno, tp.defined_class, tp.method_id, tp.event]#end#trace.enable
25
26
  @@dsl_tree = Set.new
26
27
 
@@ -53,94 +54,100 @@ module Mushin
53
54
  def initialize &domain_block
54
55
  @data = Hash.new #should be a HASH
55
56
 
56
- # both CQRS command & CQRS query code here as well
57
- @@dsl_tree.each do |context_set|
58
-
59
- context_set.each do |context_key, context_value|
60
-
61
- self.singleton_class.send :define_method, context_key do |&context_block|
62
- context_value.each do |construct_set|
63
-
64
- construct_set.each do |construct_key, construct_value|
65
- $log.debug "construct_key #{construct_key} | construct_value #{construct_value}"
66
-
67
- self.singleton_class.send :define_method, construct_key do |data = Hash.new|
68
- query_data = []
69
- @stack = Mushin::Stack.new
70
-
71
- construct_value.each do |ext|
72
- ext[:params].each do |ext_key, ext_value|
73
- data.each do |data_key, data_value|
74
- if data_key.to_sym == ext_value then
75
- $log.debug data_value
76
- ext[:params][ext_key] = data_value
77
- end
78
- end
79
- end unless ext[:params].nil?
80
-
81
- ext[:opts].each do |key, value|
82
- data.each do |data_key, data_value|
83
- if data_key.to_sym == value then
84
- ext[:opts][key] = data_value
85
- end
86
- end
87
- end unless ext[:opts].nil?
88
-
89
- $log.debug "insert_before 0 into stack: #{ext[:ext]}, #{ext[:opts]}, #{ext[:params]}"
90
- @stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
57
+ #NOTE CQRS
58
+ @@dsl_tree.each do |klass_context_set|
59
+ klass_context_set.each do |klass_context_key, klass_context_value|
60
+ self.singleton_class.send :define_method, klass_context_key do |&context_block|
61
+ klass_context_value.each do |klass_construct_set|
62
+ $log.debug "the whole construct_set: #{klass_construct_set}"
63
+ klass_construct_set.each do |klass_construct_key, klass_construct_value|
64
+ $log.debug "klass_construct_key #{klass_construct_key} | klass_construct_value #{klass_construct_value}"
65
+ $log.debug "#{@@dsl_tree}"
66
+
67
+ # creates an instance method with the name of the klass_construct_key
68
+ self.singleton_class.send :define_method, klass_construct_key do |instance_hash = Hash.new|
69
+ @stack = Mushin::Stack.new
70
+
71
+ klass_construct_value.each do |klass_ext|
72
+ ext_hash = Hash.new
73
+ ext_hash[:ext] = klass_ext[:ext]
74
+ ext_hash[:params] = Hash.new
75
+ ext_hash[:opts] = Hash.new
76
+
77
+ klass_opts_hash = klass_ext[:opts]
78
+ klass_params_hash = klass_ext[:params]
79
+
80
+ #NOTE provides an ext_hash via binding of instance_hash values to klass_hashs(opts & params) keys
81
+ instance_hash.each do |instance_hash_key, instance_hash_value|
82
+ ext_hash[:opts][klass_opts_hash.invert[instance_hash_key]] = instance_hash_value unless klass_opts_hash.invert[instance_hash_key].nil?
83
+ ext_hash[:params][klass_params_hash.invert[instance_hash_key]] = instance_hash_value unless klass_params_hash.invert[instance_hash_key].nil?
84
+ end
85
+
86
+ $log.debug "insert_before 0 into stack: #{ext_hash[:ext]}, #{ext_hash[:opts]}, #{ext_hash[:params]}"
87
+ @stack.insert_before 0, ext_hash[:ext], ext_hash[:opts], ext_hash[:params]
91
88
  end
92
89
 
93
- if context_key == "query" then
94
- $log.debug "construct_key #{construct_key} | construct_value #{construct_value}"
95
- $log.debug "this method returns a Hash of all the requested shit "
90
+ if klass_context_key == "query" then
91
+ # CQRS Query
92
+ $log.debug "klass_construct_key #{klass_construct_key} | klass_construct_value #{klass_construct_value}"
96
93
  @stack.insert_before 0, Mushin::Store, {}, {}
97
94
  stack_data = @stack.call
98
- store(data_key: construct_key.to_sym, data_value: stack_data)
95
+ store(data_key: klass_construct_key.to_sym, data_value: stack_data)
99
96
  else
97
+ # CQRS Command
100
98
  @stack.call
101
99
  end
102
100
  end
103
101
  end
104
102
  end
103
+
105
104
  instance_eval &context_block
106
105
 
107
- context_set[context_key].each do |construct_hash|
108
- construct_hash.keys.each do |method_key|
106
+ klass_context_set[klass_context_key].each do |klass_construct_hash|
107
+ klass_construct_hash.keys.each do |method_key|
109
108
  instance_eval("undef :#{method_key}")
110
109
  end
111
- $log.debug "construct_key #{context_key} is undef-ed"
110
+ $log.debug "construct_key #{klass_context_key} is undef-ed"
112
111
  end
112
+
113
113
  end
114
114
  end
115
115
  end
116
-
117
- if !domain_block.nil? then
118
- instance_eval &domain_block
119
- else
120
- fail "a domain_block is required"
121
- end
116
+ (!domain_block.nil?) ? (instance_eval &domain_block;) : (fail "a domain_block is required";)
122
117
  end
123
118
  end
124
119
  end
125
-
126
- if !construct_block.nil? then
127
- instance_eval &construct_block
128
- @context_hash[@context_keyword] << @construct_hash
129
- undef :use
130
- else
131
- fail "construct_block please"
132
- end
120
+ (!construct_block.nil?) ? (instance_eval &construct_block; @context_hash[@context_keyword] << @construct_hash; undef :use;) : (fail "construct_block please";)
133
121
  end
134
-
135
- if !context_block.nil? then
136
- instance_eval &context_block
137
- @@dsl_tree << @context_hash
138
- undef :construct
139
- else
140
- fail "context_block please"
141
- end
142
-
122
+ #TODO maybe i can define @@dsl_tree as an instance attribute and use it normally from inside the :initialize method of the object
123
+ (!context_block.nil?) ? (instance_eval &context_block; @@dsl_tree << @context_hash; undef :construct;) : (fail "context_block please";)
143
124
  end
144
125
  end
145
126
  end
146
127
  end
128
+
129
+ =begin
130
+ #$log.info "klass_ext_key: #{klass_ext_key}, klass_ext_value: #{klass_ext_value}, instance_hash: #{instance_hash}"
131
+ #
132
+ [klass_opts_hash, klass_params_hash].each do |klass_hash|
133
+ instance_hash.each do |instance_hash_key, instance_hash_value|
134
+ ext_hash[klass_hash.invert[instance_hash_key]] = instance_hash_value unless klass_hash.invert[instance_hash_key].nil?
135
+ end
136
+ end
137
+
138
+ [klass_ext[:params], klass_ext[:opts]].each do |klass_ext_hash|
139
+ klass_ext_hash.each do |klass_ext_key, klass_ext_value|
140
+ # this is an important log, figure it out to solve this!
141
+ $log.info "klass_ext_key: #{klass_ext_key}, klass_ext_value: #{klass_ext_value}, instance_hash: #{instance_hash}"
142
+
143
+ ext_instance_data.each do |data_key, data_value|
144
+ if data_key.to_sym == klass_ext_value then
145
+ $log.debug data_value
146
+ #ext[:params][ext_key] = data_value
147
+ instance_ext_hash[:params][klass_ext_key.to_sym] = data_value
148
+ end
149
+ end
150
+ end
151
+ end unless klass_ext[:opts].nil? || klass_ext[:params].nil?
152
+ =end
153
+
@@ -1,3 +1,3 @@
1
1
  module Mushin
2
- VERSION = "0.20.0"
2
+ VERSION = "0.21.0"
3
3
  end
data/samples/sample3.rb CHANGED
@@ -3,7 +3,8 @@ require_relative './../lib/mushin'
3
3
  module Sample
4
4
  class TBP < Mushin::Test::Sample::Ext; end
5
5
  class SSD < Mushin::Test::Sample::Ext; end
6
- class SSDS < Mushin::Test::Sample::Ext
6
+
7
+ class ExtA < Mushin::Test::Sample::Ext
7
8
  def initialize(ext, opts = {}, params= {})
8
9
  @ext = ext
9
10
  @opts = opts
@@ -12,27 +13,28 @@ module Sample
12
13
 
13
14
  def call(env)
14
15
  env ||= Hash.new
15
- env[:SSDS_middlewareEnvKey] = "SSDS"
16
+ p "XXXXXXXXX #{self}, params: #{@params} opts: #{@opts} XXXXXXXXXXXXXX"
17
+
18
+ env[:ExtA_params] = @params[:seeders]
19
+ env[:ExtA_opts] = @opts[:ssd_path]
16
20
  @ext.call(env)
17
- #super
18
- #return env
19
21
  end
20
22
  end
21
23
 
22
- class SSDA < Mushin::Test::Sample::Ext
24
+ class ExtB < Mushin::Test::Sample::Ext
23
25
  def initialize(ext, opts = {}, params= {})
24
- @ext = ext
26
+ @ext = ext
25
27
  @opts = opts
26
28
  @params = params
27
29
  end
28
30
 
29
31
  def call(env)
30
32
  env ||= Hash.new
31
- env[:nana] = "nana_what"
32
- env[:SSDA_middlewareEnvKey] = "SSDA"
33
+ p "XXXXXXXXX #{self}, params: #{@params} opts: #{@opts} XXXXXXXXXXXXXX"
34
+
35
+ env[:ExtB_opts] = @opts[:ssd_path]
36
+ env[:ExtB_params] = @params[:seeders]
33
37
  @ext.call(env)
34
- env[:superman_real_nameB] = "where are you now dada"
35
- #return env
36
38
  end
37
39
  end
38
40
 
@@ -55,30 +57,15 @@ module Sample
55
57
  end
56
58
 
57
59
  context "query" do
58
- construct 'xyz' do
59
- use ext: Sample::SSDS, params: {"seeders" => :seeders}, opts: {"ssd_path"=> :keyword}
60
- use ext: Sample::SSDA, params: {"seeders" => :seeders}, opts: {"ssd_path"=> :keyword}
60
+ construct 'torrentsA' do
61
+ use ext: Sample::ExtA, params: {:seeders => :seeders_valueA}, opts: {:ssd_path => :path_valueA}
62
+ use ext: Sample::ExtB, params: {:seeders => :seeders_valueB}, opts: {:ssd_path => :path_valueB}
61
63
  end
62
-
63
- construct 'torrentsC' do
64
- use ext: Sample::SSDS, params: {"seeders" => :seeders}, opts: {"ssd_path"=> :keyword}
65
- use ext: Sample::SSDA, params: {"seeders" => :seeders}, opts: {"ssd_path"=> :keyword}
66
- end
67
-
68
64
  construct 'torrentsB' do
69
- use ext: Sample::SSDS, params: {"seeders" => :seeders}, opts: {"ssd_path"=> :keyword}
70
- use ext: Sample::SSDA, params: {"seeders" => :seeders}, opts: {"ssd_path"=> :keyword}
65
+ use ext: Sample::ExtA, params: {:seeders => :seeders_valueA}, opts: {:ssd_path => :path_valueA}
66
+ use ext: Sample::ExtB, params: {:seeders => :seeders_valueB}, opts: {:ssd_path => :path_valueB}
71
67
  end
72
68
  end
73
-
74
- # context "ztorrent_bots" do
75
- # construct "zrutracker" do
76
- # use ext: "zRUTracker", params: "params", opts: "opts"
77
- # end
78
- # construct "zxy" do
79
- # use ext: "zTPB", params: "params", opts: "opts"
80
- # end
81
- # end
82
69
  end
83
70
 
84
71
  class App
@@ -92,9 +79,9 @@ module Sample
92
79
  end
93
80
 
94
81
  query do
95
- xyz keyword: "xyz query that shitxyzxyzxyz", seeders: "30"
96
- torrentsC keyword: "torrentsC nononononon", seeders: "30"
97
- torrentsB keyword: "torrentsB nononononon", seeders: "30"
82
+ torrentsA path_valueA: "this is a torrentsA pathvalueA", seeders_valueA: "30torrentA", path_valueB: "this is torrentsA pathvalueB", seedersvalueB: "30torrentB"
83
+ torrentsB path_value: "this is a torrentsB pathvalue", seeders_value: "30torrentB"
84
+ #torrentsB keyword: "torrentsB nononononon", seeders: "30"
98
85
  end
99
86
 
100
87
  #=begin
@@ -125,8 +112,8 @@ module Sample
125
112
  #p mydomain.store[:love]
126
113
  #p mydomain.store[:xyz]
127
114
  #p mydomain.store[:torrentsB][:nana]
128
- p mydomain.store[:torrentsC]
129
- p mydomain.store[:torrentsB]
115
+ #p mydomain.store[:torrentsC]
116
+ #p mydomain.store[:torrentsB]
130
117
  p mydomain.store
131
118
  end
132
119
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zotherstupidguy