mushin 0.8.0 → 0.9.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: e80b77edeaa86c23fa83d52e191991a7c66325c1
4
- data.tar.gz: 46ded24456a4fb628e295f9a48456754dd88b90a
3
+ metadata.gz: 140ed42cc5d343e6daf4d8996a0a35f7947c338f
4
+ data.tar.gz: 631d955207007eb2ea568a7fcc33c42dfb1c2f9c
5
5
  SHA512:
6
- metadata.gz: 6040f8b9596de44e019ded4202b020259dbf06100105502d5e5978093160d433978ad03db8c869711a65f0dbe1c0d1679813e11c37ad31d98d5911500d978d32
7
- data.tar.gz: 206abca21b7f550b5900ac9633bfac2b46847e59b8aaa55f57dd4340a9c3bf4a40450ed3490d90d781e2bbd9c7f684e323fa6ae8d826518378b1092e08807b09
6
+ metadata.gz: f636a201415bd0f160ca69a8709ede7069fb3540934f0056229dd44ab4e142cd9d08f1526a2b143207f21460a471fc04a45d0d0ceb70da43980c483b6e98d2af
7
+ data.tar.gz: d312a250c3943e31a8011345350531afed055ad6ece23bb73445c81989643b51f0f61a209443b6f51932c43c24bb3503dab6ef5e1eac63938c017f4da268963a
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
8
  end
9
9
 
10
10
  task :default => :test
data/lib/mushin/domain.rb CHANGED
@@ -1,114 +1,5 @@
1
- # 1- an access method :context is defined in DSLBuilder(thats a module avialable as class methods to the domain class of the application.
2
- # 2- the :context takes a name, &block and pass instance_eval it aganist an object created from DSLBuilder::Context
3
- # 3- DSLBuilder::Context initialize takes a context_name say "torrent_bots" and create an app_context_klass and creates an access method with the :context_name inside DSL
4
- #
1
+ require_relative 'dsl_builder'
5
2
  module Mushin
6
- module DSLBuilder
7
- class Context
8
- attr_accessor :context_name
9
- # defines a DSL::Klass of type Context based on :name
10
- # Supplies the defined DSL::Klass with a method of the construct
11
- def initialize context_name, &block
12
- @context_name = context_name.capitalize
13
-
14
- app_context_klass = Class.new(Object) do
15
- def initialize &block
16
- instance_eval &block
17
- end
18
- end
19
- # creates a context klass dynamically
20
- DSL.const_set(context_name.capitalize, app_context_klass) unless DSL.const_defined?(context_name.capitalize)
21
- # creates an access method inside DSL for the dynamically created context klass
22
- DSL.send(:define_method, context_name) do |&block|
23
- DSL.const_get(context_name.capitalize).new &block unless context_name.nil?
24
- end
25
-
26
- instance_eval &block
27
- end
28
-
29
- # access method for DSLBuilder::Construct klass inside a context object &block
30
- def construct name, &block
31
- app_context_klass = DSL.const_get(@context_name)
32
- Construct.new(name, app_context_klass, &block) #.instance_eval &block
33
- end
34
- end
35
-
36
- class Construct
37
- attr_accessor :name, :stack, :app_context_klass
38
- def initialize name, app_context_klass, &block
39
- @name = name.capitalize
40
- @middlewares = []
41
- @stack = Mushin::Stack.new
42
- @app_context_klass = app_context_klass
43
-
44
- instance_eval &block
45
- $log.info "middlewares after instance_eval"
46
- $log.info middlewares = @middlewares
47
-
48
- app_construct_klass = Class.new(Object) do
49
- @@stack = Mushin::Stack.new
50
- @@env = {}
51
- @@ext_set = middlewares
52
-
53
- attr_accessor :env
54
- def initialize env = {}
55
- @env = env
56
- #p "merging #{@@env} with #{env_updates} for the result of #{env_updates.merge @@env}"
57
- #p "domaindsl construct is ready to activate calling the stack with #{env}"
58
- end
59
- end # end of app_construct_klass
60
-
61
- DSL.const_set(name.capitalize, app_construct_klass) unless DSL.const_defined?(name.capitalize)
62
- # Reopens most recent context klass and add method `def construct_name params; app_construct_class.new(params)`
63
- # access method for DSL::Construct dynamic klass inside a context object &block
64
- DSL.const_get(@app_context_klass.to_s).send(:define_method, name) do |env|
65
- # 1. populate :symbols inside opts and params with values from env
66
- @@ext_set.each do |ext|
67
- ext[:params].each do |key, value|
68
- env.each do |env_key, env_value|
69
- if env_key.to_sym == value then
70
- ext[:params][key] = env_value
71
- end
72
- end
73
- end
74
-
75
- ext[:opts].each do |key, value|
76
- env.each do |env_key, env_value|
77
- if env_key.to_sym == value then
78
- ext[:opts][key] = env_value
79
- end
80
- end
81
- end
82
- $log.info ext
83
- end
84
- # 2. insert
85
- @@ext_set.each do |ext|
86
- @@stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
87
- end
88
- # 3. call the stack
89
- @@stack.call
90
-
91
- DSL.const_get(name.capitalize).new env
92
- end
93
- #p DSL.constants
94
- end
95
-
96
- def use ext:, opts: {}, params: {}
97
- @middlewares << {:ext => ext, :opts => opts, :params => params}
98
- #p @middlewares
99
- # @stack.insert_before 0, ext, opts, params
100
- #@stack.call
101
- #@stack = Use.new(ext, opts, params, @stack)
102
- end
103
- end
104
-
105
- def context name, &block
106
- Context.new(name, &block) #.instance_eval &block
107
- end
108
- end
109
-
110
- module DSL
111
- end
112
3
 
113
4
  class Domain
114
5
  def self.inherited(subclass)
@@ -117,6 +8,7 @@ module Mushin
117
8
  end
118
9
 
119
10
  def initialize &block
11
+ $log.info "Domain object #{self} is going to instance_eval"
120
12
  instance_eval &block
121
13
  end
122
14
  end
data/lib/mushin/dsl.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Mushin
2
+ # DSL module holds one klass and one access method along with
3
+ # one neseted klass and one nested access method
4
+ module DSL
5
+ def self.inherited(other)
6
+ puts other
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,120 @@
1
+ require 'mushin'
2
+ require_relative 'dsl'
3
+
4
+ module Mushin
5
+
6
+ module DSLBuilder
7
+
8
+ # The DSLBuilder context access method
9
+ def context context_keyword, &block
10
+ Context.new context_keyword, &block
11
+ end
12
+
13
+ class Context
14
+
15
+ # attr for a dsl context constructor class
16
+ attr_accessor :app_dsl_context_klass
17
+
18
+ def initialize context_keyword, &block
19
+ @app_dsl_context_klass = app_dsl_context_access_method_and_klass(context_keyword, Mushin::DSL)
20
+ instance_eval &block
21
+ end
22
+
23
+ def construct construct_keyword, &block
24
+ Construct.new construct_keyword, @app_dsl_context_klass, &block
25
+ end
26
+
27
+ def app_dsl_context_access_method_and_klass(context_keyword, parent_klass)
28
+ $log.info "dynamically building app dsl context access method for: #{context_keyword}, inside: #{parent_klass}".reverse_color
29
+ parent_klass.class_eval do
30
+ define_method(context_keyword) do |&block|
31
+ p context_keyword
32
+ parent_klass.const_get(context_keyword.capitalize).new &block #if block_given?
33
+ end
34
+ end
35
+
36
+ k = Class.new do
37
+ def initialize &block
38
+ instance_eval &block
39
+ p "shit in klass #{self}"
40
+ end
41
+ end
42
+ parent_klass.const_set(context_keyword.capitalize, k) unless parent_klass.const_defined?(context_keyword.capitalize)
43
+
44
+ return parent_klass.const_get(context_keyword.capitalize)
45
+ end
46
+
47
+ class Construct
48
+ attr_accessor :context_klass, :construct_klass, :ext_set
49
+
50
+ def initialize construct_keyword, context_klass, &block
51
+ @construct_keyword = construct_keyword
52
+ @context_klass = context_klass
53
+ @ext_set = []
54
+ instance_eval &block
55
+
56
+
57
+ @construct_klass = dsl_construct_access_method_and_klass(@construct_keyword, @ext_set, @context_klass)
58
+ #konstructor = @construct_klass.new
59
+
60
+ end
61
+
62
+ def use args = {}
63
+ p "**********************"
64
+ p args
65
+ p "************will replace with actual values from konstuctor object args**********"
66
+ @ext_set << args
67
+ end
68
+
69
+ def dsl_construct_access_method_and_klass(construct_keyword, ext_set, parent_klass)
70
+ $log.info "dynamically building app dsl construct access method for: #{construct_keyword}, inside: #{parent_klass}"
71
+
72
+ parent_klass.class_eval do
73
+ define_method(construct_keyword) do |args = {}|
74
+ p "here replace :symbols with values"
75
+ p args
76
+ ext_set.each do |ext|
77
+ ext[:params].each do |key, value|
78
+ args.each do |env_key, env_value|
79
+ if env_key.to_sym == value then
80
+ ext[:params][key] = env_value
81
+ end
82
+ end
83
+ end unless ext[:params].nil?
84
+
85
+ ext[:opts].each do |key, value|
86
+ args.each do |env_key, env_value|
87
+ if env_key.to_sym == value then
88
+ ext[:opts][key] = env_value
89
+ end
90
+ end
91
+ end unless ext[:opts].nil?
92
+ $log.info ext
93
+ end
94
+
95
+ parent_klass.const_get(construct_keyword.capitalize).new args, ext_set
96
+ end
97
+ end
98
+
99
+ k = Class.new do
100
+ attr_accessor :stack
101
+ def initialize args={}, ext_set
102
+ p "construct dynamic klass"
103
+ @stack = Mushin::Stack.new
104
+ ext_set.each do |ext|
105
+ p "inside the stack"
106
+ p ext
107
+ @stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
108
+ end
109
+ @stack.call
110
+ end
111
+ end
112
+ parent_klass.const_set(construct_keyword.capitalize, k) unless parent_klass.const_defined?(construct_keyword.capitalize)
113
+
114
+
115
+ return parent_klass.const_get(construct_keyword.capitalize)
116
+ end
117
+ end # end of Construct klass
118
+ end # end of Context klass
119
+ end # end of DSLBuilder module
120
+ end
@@ -9,8 +9,9 @@ module Mushin
9
9
  end
10
10
 
11
11
  def call(env)
12
-
13
- $log.info "#{self} ext is called with the following options: #{@opts} & params: #{@params}; and env: #{env}"
12
+ $log.info "-----------------------------------------------------------------------"
13
+ $log.info "Ext: #{self} is called with the following options: #{@opts} & params: #{@params}; and env: #{env}".red
14
+ $log.info "-----------------------------------------------------------------------"
14
15
 
15
16
  # Inbound maniuplation
16
17
  env = Hash.new if env.nil?
@@ -1,3 +1,3 @@
1
1
  module Mushin
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/mushin.rb CHANGED
@@ -10,5 +10,28 @@ require_relative "mushin/test_helper"
10
10
 
11
11
  $log = Logger.new(STDOUT)
12
12
 
13
- #module Mushin
14
- #end
13
+ class String
14
+ def black; "\e[30m#{self}\e[0m" end
15
+ def red; "\e[31m#{self}\e[0m" end
16
+ def green; "\e[32m#{self}\e[0m" end
17
+ def brown; "\e[33m#{self}\e[0m" end
18
+ def blue; "\e[34m#{self}\e[0m" end
19
+ def magenta; "\e[35m#{self}\e[0m" end
20
+ def cyan; "\e[36m#{self}\e[0m" end
21
+ def gray; "\e[37m#{self}\e[0m" end
22
+
23
+ def bg_black; "\e[40m#{self}\e[0m" end
24
+ def bg_red; "\e[41m#{self}\e[0m" end
25
+ def bg_green; "\e[42m#{self}\e[0m" end
26
+ def bg_brown; "\e[43m#{self}\e[0m" end
27
+ def bg_blue; "\e[44m#{self}\e[0m" end
28
+ def bg_magenta; "\e[45m#{self}\e[0m" end
29
+ def bg_cyan; "\e[46m#{self}\e[0m" end
30
+ def bg_gray; "\e[47m#{self}\e[0m" end
31
+
32
+ def bold; "\e[1m#{self}\e[22m" end
33
+ def italic; "\e[3m#{self}\e[23m" end
34
+ def underline; "\e[4m#{self}\e[24m" end
35
+ def blink; "\e[5m#{self}\e[25m" end
36
+ def reverse_color; "\e[7m#{self}\e[27m" end
37
+ end
@@ -0,0 +1,114 @@
1
+ module Mushin
2
+ # 1- an access method :context is defined in DSLBuilder(thats a module avialable as class methods to the domain class of the application.
3
+ # 2- the :context takes a name, &block and pass instance_eval it aganist an object created from DSLBuilder::Context
4
+ # 3- DSLBuilder::Context initialize takes a context_name say "torrent_bots" and create an app_context_klass and creates an access method with the :context_name inside DSL
5
+ #
6
+ module DSLBuilder
7
+ class Context
8
+ attr_accessor :context_name
9
+ # defines a DSL::Klass of type Context based on :name
10
+ # Supplies the defined DSL::Klass with a method of the construct
11
+ def initialize context_name, &block
12
+ @context_name = context_name.capitalize
13
+
14
+ app_context_klass = Class.new(Object) do
15
+ def initialize &block
16
+ instance_eval &block
17
+ end
18
+ end
19
+ # creates a context klass dynamically
20
+ DSL.const_set(context_name.capitalize, app_context_klass) unless DSL.const_defined?(context_name.capitalize)
21
+ # creates an access method inside DSL for the dynamically created context klass
22
+ DSL.send(:define_method, context_name) do |&block|
23
+ DSL.const_get(context_name.capitalize).new &block unless context_name.nil?
24
+ end
25
+
26
+ instance_eval &block
27
+ end
28
+
29
+ # access method for DSLBuilder::Construct klass inside a context object &block
30
+ def construct name, &block
31
+ app_context_klass = DSL.const_get(@context_name)
32
+ Construct.new(name, app_context_klass, &block) #.instance_eval &block
33
+ end
34
+ end
35
+
36
+ class Construct
37
+ attr_accessor :name, :stack, :app_context_klass
38
+ def initialize name, app_context_klass, &block
39
+ @name = name.capitalize
40
+ @middlewares = []
41
+ @stack = Mushin::Stack.new
42
+ @app_context_klass = app_context_klass
43
+
44
+ instance_eval &block
45
+ $log.info "middlewares after instance_eval"
46
+ $log.info middlewares = @middlewares
47
+
48
+ app_construct_klass = Class.new(Object) do
49
+ @@stack = Mushin::Stack.new
50
+ @@env = {}
51
+ @@ext_set = middlewares
52
+ $log.info "@@ext_set"
53
+ $log.info @@ext_set
54
+
55
+ attr_accessor :env
56
+ def initialize env = {}
57
+ @env = env
58
+ #p "merging #{@@env} with #{env_updates} for the result of #{env_updates.merge @@env}"
59
+ #p "domaindsl construct is ready to activate calling the stack with #{env}"
60
+ end
61
+ end # end of app_construct_klass
62
+
63
+ DSL.const_set(name.capitalize, app_construct_klass) unless DSL.const_defined?(name.capitalize)
64
+ # Reopens most recent context klass and add method `def construct_name params; app_construct_class.new(params)`
65
+ # access method for DSL::Construct dynamic klass inside a context object &block
66
+ DSL.const_get(@app_context_klass.to_s).send(:define_method, name) do |env|
67
+ # 1. populate :symbols inside opts and params with values from env
68
+ @@ext_set.each do |ext|
69
+ ext[:params].each do |key, value|
70
+ env.each do |env_key, env_value|
71
+ if env_key.to_sym == value then
72
+ ext[:params][key] = env_value
73
+ end
74
+ end
75
+ end
76
+
77
+ ext[:opts].each do |key, value|
78
+ env.each do |env_key, env_value|
79
+ if env_key.to_sym == value then
80
+ ext[:opts][key] = env_value
81
+ end
82
+ end
83
+ end
84
+ $log.info ext
85
+ end
86
+ # 2. insert
87
+ @@ext_set.each do |ext|
88
+ @@stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
89
+ end
90
+ # 3. call the stack
91
+ @@stack.call
92
+
93
+ DSL.const_get(name.capitalize).new env
94
+ end
95
+ #p DSL.constants
96
+ end
97
+
98
+ def use ext:, opts: {}, params: {}
99
+ @middlewares << {:ext => ext, :opts => opts, :params => params}
100
+ #p @middlewares
101
+ # @stack.insert_before 0, ext, opts, params
102
+ #@stack.call
103
+ #@stack = Use.new(ext, opts, params, @stack)
104
+ end
105
+ end
106
+
107
+ def context name, &block
108
+ Context.new(name, &block) #.instance_eval &block
109
+ end
110
+ end
111
+
112
+ module DSL
113
+ end
114
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zotherstupidguy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,6 +129,8 @@ files:
129
129
  - exe/mushin
130
130
  - lib/mushin.rb
131
131
  - lib/mushin/domain.rb
132
+ - lib/mushin/dsl.rb
133
+ - lib/mushin/dsl_builder.rb
132
134
  - lib/mushin/ext.rb
133
135
  - lib/mushin/generator.rb
134
136
  - lib/mushin/stack.rb
@@ -136,6 +138,7 @@ files:
136
138
  - lib/mushin/version.rb
137
139
  - mushin.gemspec
138
140
  - samples/sample1.rb
141
+ - samples/sample2.rb
139
142
  homepage: http://mushin-rb.github.io/
140
143
  licenses:
141
144
  - MIT