mushin 0.18.0 → 0.19.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 +4 -4
- data/{lib/mushin → hacks}/cqrs/command.rb +23 -16
- data/{lib/mushin → hacks}/cqrs/query.rb +85 -1
- data/hacks/domain.rb +35 -0
- data/hacks/dsl.rb +39 -0
- data/hacks/dsl_builder.rb +29 -0
- data/lib/mushin/logger.rb +119 -0
- data/lib/mushin/main.rb +146 -0
- data/lib/mushin/test_helper.rb +1 -1
- data/lib/mushin/version.rb +1 -1
- data/lib/mushin.rb +11 -54
- data/mushin.gemspec +4 -1
- data/samples/sample2.rb +132 -0
- data/samples/sample3.rb +132 -0
- metadata +14 -13
- data/.ssd/eventstream/11_29_2016.ssd +0 -2
- data/.ssd/eventstream/11_30_2016.ssd +0 -9
- data/lib/mushin/domain.rb +0 -21
- data/lib/mushin/dsl.rb +0 -10
- data/lib/mushin/dsl_builder.rb +0 -23
- /data/{lib/mushin → hacks}/bot.rb +0 -0
- /data/{lib/mushin → hacks}/es/event.rb +0 -0
- /data/{lib/mushin → hacks}/es/event_stream.rb +0 -0
- /data/{lib/mushin → hacks}/generator.rb +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a0fb43972864c2456988f71464106b71c234b037
         | 
| 4 | 
            +
              data.tar.gz: dcbe3219ab4b0eb6e85f6555a4afb15cd3abf1e8
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6787fee036117fed47a8741556104fa2079f5359f3d39005d3cd6e7a2eb90d42e6ef3414f41e169a3a7b6bacf4e6b5ea0e0d57ea7e703c7863433b938ba1d69f
         | 
| 7 | 
            +
              data.tar.gz: b5e8b3fb501cb4b00fd1dc516197d8b552669016278e8ba1f32336840099068943b59d1ac9846278cec12b1b6231c4907952a3661ff2c10f556ac1fee47fca49
         | 
| @@ -6,18 +6,26 @@ module Mushin | |
| 6 6 |  | 
| 7 7 | 
             
            	# attr for a dsl context constructor class
         | 
| 8 8 | 
             
            	attr_accessor :app_dsl_context_klass
         | 
| 9 | 
            +
            	attr_accessor :constructs
         | 
| 9 10 |  | 
| 10 11 | 
             
            	def initialize context_keyword, &block
         | 
| 12 | 
            +
            	  dsl_module = Module.new do
         | 
| 13 | 
            +
            	  end
         | 
| 14 | 
            +
            	  Mushin.const_set(:DSL, dsl_module)
         | 
| 15 | 
            +
            	  Mushin::Domain.send :include, Mushin::DSL
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            	  @constructs = []
         | 
| 18 | 
            +
            	  #@app_dsl_context_klass = app_dsl_context_access_method_and_klass(context_keyword, dsl_module)
         | 
| 11 19 | 
             
            	  @app_dsl_context_klass = app_dsl_context_access_method_and_klass(context_keyword, Mushin::DSL)
         | 
| 12 20 | 
             
            	  instance_eval &block
         | 
| 13 21 | 
             
            	end
         | 
| 14 22 |  | 
| 15 23 | 
             
            	def construct construct_keyword, &block
         | 
| 16 | 
            -
            	  Construct.new | 
| 24 | 
            +
            	  @constructs << Construct.new(construct_keyword, @app_dsl_context_klass, &block)
         | 
| 17 25 | 
             
            	end
         | 
| 18 26 |  | 
| 19 27 | 
             
            	def app_dsl_context_access_method_and_klass(context_keyword, parent_klass)
         | 
| 20 | 
            -
            	  $log. | 
| 28 | 
            +
            	  $log.debug "dynamically building app dsl context access method for: #{context_keyword}, inside: #{parent_klass}" #.reverse_color
         | 
| 21 29 |  | 
| 22 30 | 
             
            	  parent_klass.class_eval do
         | 
| 23 31 | 
             
            	    define_method(context_keyword) do |&block|
         | 
| @@ -30,27 +38,25 @@ module Mushin | |
| 30 38 | 
             
            	      instance_eval &block
         | 
| 31 39 | 
             
            	    end
         | 
| 32 40 | 
             
            	  end
         | 
| 33 | 
            -
            	   | 
| 41 | 
            +
            	  # check if the const is already defined to avoid warnings
         | 
| 42 | 
            +
            	  parent_klass.const_set(context_keyword.capitalize, k) unless parent_klass.const_defined?(context_keyword.capitalize)   
         | 
| 34 43 |  | 
| 35 44 | 
             
            	  return parent_klass.const_get(context_keyword.capitalize)
         | 
| 36 45 | 
             
            	end
         | 
| 37 46 |  | 
| 38 47 | 
             
            	class Construct
         | 
| 39 | 
            -
            	  attr_accessor :context_klass, :construct_klass | 
| 48 | 
            +
            	  attr_accessor :context_klass, :construct_klass 
         | 
| 49 | 
            +
            	  attr_accessor :ext_set
         | 
| 40 50 |  | 
| 41 51 | 
             
            	  def initialize construct_keyword, context_klass, &block
         | 
| 42 52 | 
             
            	    @construct_keyword = construct_keyword
         | 
| 43 53 | 
             
            	    @context_klass = context_klass
         | 
| 44 | 
            -
            	    $log. | 
| 45 | 
            -
            	    $log.info "@ext_set inside #{self} equals []"
         | 
| 46 | 
            -
            	    $log.info "@ext_set inside #{self} equals []"
         | 
| 47 | 
            -
            	    $log.info "@ext_set inside #{self} equals []"
         | 
| 48 | 
            -
            	    $log.info "@ext_set inside #{self} equals []"
         | 
| 54 | 
            +
            	    $log.debug "@ext_set inside #{self} equals []"
         | 
| 49 55 | 
             
            	    @ext_set = []
         | 
| 50 56 |  | 
| 51 57 | 
             
            	    instance_eval &block
         | 
| 52 58 |  | 
| 53 | 
            -
            	    $log. | 
| 59 | 
            +
            	    $log.debug "@ext_set inside #{self} equals #{@ext_set}"
         | 
| 54 60 | 
             
            	    @construct_klass = dsl_construct_access_method_and_klass(@construct_keyword, @ext_set, @context_klass)
         | 
| 55 61 | 
             
            	  end
         | 
| 56 62 |  | 
| @@ -59,10 +65,10 @@ module Mushin | |
| 59 65 | 
             
            	  end
         | 
| 60 66 |  | 
| 61 67 | 
             
            	  def dsl_construct_access_method_and_klass(construct_keyword, ext_set, parent_klass)
         | 
| 62 | 
            -
            	    $log. | 
| 68 | 
            +
            	    $log.debug "dynamically building app dsl construct access method for: #{construct_keyword}, inside: #{parent_klass}"
         | 
| 63 69 | 
             
            	    ext_set.reverse!
         | 
| 64 70 |  | 
| 65 | 
            -
            	    $log. | 
| 71 | 
            +
            	    $log.debug "ext_set reserved inside #{self} equals #{ext_set}"
         | 
| 66 72 |  | 
| 67 73 | 
             
            	    parent_klass.class_eval do
         | 
| 68 74 | 
             
            	      define_method(construct_keyword) do |args = {}|
         | 
| @@ -82,7 +88,7 @@ module Mushin | |
| 82 88 | 
             
            		    end
         | 
| 83 89 | 
             
            		  end
         | 
| 84 90 | 
             
            		end unless ext[:opts].nil?
         | 
| 85 | 
            -
            		$log. | 
| 91 | 
            +
            		$log.debug ext 
         | 
| 86 92 | 
             
            	      end
         | 
| 87 93 |  | 
| 88 94 | 
             
            	      parent_klass.const_get(construct_keyword.capitalize).new args, ext_set
         | 
| @@ -92,8 +98,8 @@ module Mushin | |
| 92 98 | 
             
            	    k = Class.new do
         | 
| 93 99 | 
             
            	      attr_accessor :stack
         | 
| 94 100 | 
             
            	      def initialize args={}, ext_set
         | 
| 95 | 
            -
            		 | 
| 96 | 
            -
            		 | 
| 101 | 
            +
            		$log.debug "hahahaha"
         | 
| 102 | 
            +
            		$log.debug  ext_set
         | 
| 97 103 | 
             
            		@stack = Mushin::Stack.new
         | 
| 98 104 |  | 
| 99 105 | 
             
            		ext_set.each do |ext|
         | 
| @@ -105,7 +111,8 @@ module Mushin | |
| 105 111 | 
             
            	      end
         | 
| 106 112 | 
             
            	    end
         | 
| 107 113 |  | 
| 108 | 
            -
            	     | 
| 114 | 
            +
            	    # check if the const is already defined to avoid warnings
         | 
| 115 | 
            +
            	    parent_klass.const_set(construct_keyword.capitalize, k) unless parent_klass.const_defined?(construct_keyword.capitalize)
         | 
| 109 116 |  | 
| 110 117 | 
             
            	    return parent_klass.const_get(construct_keyword.capitalize)
         | 
| 111 118 | 
             
            	  end
         | 
| @@ -100,7 +100,7 @@ module Mushin | |
| 100 100 | 
             
            		ext_set.each do |ext|
         | 
| 101 101 | 
             
            		  @stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
         | 
| 102 102 | 
             
            		end
         | 
| 103 | 
            -
            		 | 
| 103 | 
            +
            		$log.debug "printing the stack value  #{@stack.call}"
         | 
| 104 104 | 
             
            		return @stack.call
         | 
| 105 105 | 
             
            	      end
         | 
| 106 106 | 
             
            	    end
         | 
| @@ -114,3 +114,87 @@ module Mushin | |
| 114 114 | 
             
                end # end of CQRS module
         | 
| 115 115 | 
             
              end # end of DSLBuilder module
         | 
| 116 116 | 
             
            end # end of Mushin module
         | 
| 117 | 
            +
             | 
| 118 | 
            +
            #self.class.send :attr_accessor, construct_key
         | 
| 119 | 
            +
            #instance_eval("@#{construct_key} = 'koko'")
         | 
| 120 | 
            +
            #send :instance_variable_set, "@#{construct_key}", 'koko'
         | 
| 121 | 
            +
            #self.singleton_class.send(:attr_accessor, construct_key)
         | 
| 122 | 
            +
            #self.singleton_class.send :instance_variable_set, "@#{construct_key}", "koko"
         | 
| 123 | 
            +
            #
         | 
| 124 | 
            +
             | 
| 125 | 
            +
            =begin
         | 
| 126 | 
            +
            	      # CQRS query 
         | 
| 127 | 
            +
            	      def query &query_block 
         | 
| 128 | 
            +
            		@@dsl_tree.each do |context_set|
         | 
| 129 | 
            +
             | 
| 130 | 
            +
            		  context_set.each do |context_key, context_value|
         | 
| 131 | 
            +
            		    p "context_key #{context_key} | context_value #{context_value}"
         | 
| 132 | 
            +
            		    self.singleton_class.send :define_method, context_key do |&context_block|
         | 
| 133 | 
            +
            		      context_value.each do |c|
         | 
| 134 | 
            +
            			c.each do |construct_key, construct_value|
         | 
| 135 | 
            +
            			  p "construct_key #{construct_key} | construct_value #{construct_value}"
         | 
| 136 | 
            +
            			  self.singleton_class.send :define_method, construct_key do |data = Hash.new|
         | 
| 137 | 
            +
            			    p "------data-------"
         | 
| 138 | 
            +
            			    p data
         | 
| 139 | 
            +
            			    p data.class
         | 
| 140 | 
            +
            			    data.each do |k, v|
         | 
| 141 | 
            +
            			      p  k
         | 
| 142 | 
            +
            			      p v
         | 
| 143 | 
            +
            			    end
         | 
| 144 | 
            +
            			    p "------data-------"
         | 
| 145 | 
            +
            			    p construct_value.class
         | 
| 146 | 
            +
             | 
| 147 | 
            +
            			    @stack = Mushin::Stack.new
         | 
| 148 | 
            +
            			    construct_value.each do |ext|
         | 
| 149 | 
            +
            			      #p ext_hash
         | 
| 150 | 
            +
            			      #p ext_hash.keys
         | 
| 151 | 
            +
            			      ##p ext_hash.values
         | 
| 152 | 
            +
            			      p ext
         | 
| 153 | 
            +
            			      p ext[:params]
         | 
| 154 | 
            +
            			      ext[:params].each do |ext_key, ext_value|
         | 
| 155 | 
            +
            				p data
         | 
| 156 | 
            +
            				data.each do |data_key, data_value|
         | 
| 157 | 
            +
            				  if data_key.to_sym == ext_value then
         | 
| 158 | 
            +
            				    p data_value
         | 
| 159 | 
            +
            				    ext[:params][ext_key] = data_value
         | 
| 160 | 
            +
            				  end
         | 
| 161 | 
            +
            				end
         | 
| 162 | 
            +
            			      end unless ext[:params].nil?
         | 
| 163 | 
            +
             | 
| 164 | 
            +
            			      ext[:opts].each do |key, value|
         | 
| 165 | 
            +
            				data.each do |data_key, data_value|
         | 
| 166 | 
            +
            				  if data_key.to_sym == value then
         | 
| 167 | 
            +
            				    ext[:opts][key] = data_value
         | 
| 168 | 
            +
            				  end
         | 
| 169 | 
            +
            				end
         | 
| 170 | 
            +
            			      end unless ext[:opts].nil?
         | 
| 171 | 
            +
            			      p "insert_before 0 into stack: #{ext[:ext]}, #{ext[:opts]}, #{ext[:params]}"
         | 
| 172 | 
            +
            			      @stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
         | 
| 173 | 
            +
            			    end
         | 
| 174 | 
            +
            			    @stack.call
         | 
| 175 | 
            +
            			  end
         | 
| 176 | 
            +
            			  #instance_eval("undef :#{construct_key}")
         | 
| 177 | 
            +
            			end
         | 
| 178 | 
            +
            		      end
         | 
| 179 | 
            +
            		      instance_eval &context_block
         | 
| 180 | 
            +
             | 
| 181 | 
            +
             | 
| 182 | 
            +
            		      context_set[context_key].each do |construct_hash|
         | 
| 183 | 
            +
            			p "xxxxxx"
         | 
| 184 | 
            +
            			construct_hash.keys.each do |method_key| 
         | 
| 185 | 
            +
            			  p method_key
         | 
| 186 | 
            +
            			  instance_eval("undef :#{method_key}")
         | 
| 187 | 
            +
            			end
         | 
| 188 | 
            +
            			p "construct_key #{context_key} is undef-ed"
         | 
| 189 | 
            +
            		      end
         | 
| 190 | 
            +
            		    end
         | 
| 191 | 
            +
            		  end
         | 
| 192 | 
            +
            		end
         | 
| 193 | 
            +
             | 
| 194 | 
            +
            		if !query_block.nil? then 
         | 
| 195 | 
            +
            		  instance_eval &query_block 
         | 
| 196 | 
            +
            		else
         | 
| 197 | 
            +
            		  fail "a query_block is required"
         | 
| 198 | 
            +
            		end
         | 
| 199 | 
            +
            	      end
         | 
| 200 | 
            +
            =end
         | 
    
        data/hacks/domain.rb
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            require_relative 'dsl_builder'
         | 
| 2 | 
            +
            module Mushin
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              class Domain
         | 
| 5 | 
            +
                # offers a virtual datastore for query requests on the domain object
         | 
| 6 | 
            +
                #attr_accessor :store, :event_stream
         | 
| 7 | 
            +
                #attr_accessor :dparams
         | 
| 8 | 
            +
                #attr_accessor :dsl_array
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              
         | 
| 11 | 
            +
                def self.inherited(subclass)
         | 
| 12 | 
            +
                  subclass.send :extend, DSLBuilder 
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def initialize &block
         | 
| 16 | 
            +
                  #def self.inherited(subclass)
         | 
| 17 | 
            +
                  #	subclass.send :extend, DSLBuilder 
         | 
| 18 | 
            +
                  #
         | 
| 19 | 
            +
                  #	dsl_module = Module.new do
         | 
| 20 | 
            +
                  #	end
         | 
| 21 | 
            +
                  #	Mushin.const_set(:DSL, dsl_module)
         | 
| 22 | 
            +
                  ##	subclass.send :include, DSL 
         | 
| 23 | 
            +
                  #      end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  #def initialize params={}, &block
         | 
| 26 | 
            +
                  #@dparams = params
         | 
| 27 | 
            +
                  #$log.debug "Domain object #{self} is going to instance_eval with dparams of #{@dparams}"
         | 
| 28 | 
            +
                  #@dsl_array = []
         | 
| 29 | 
            +
                  instance_eval &block
         | 
| 30 | 
            +
                  Mushin.send :remove_const, :DSL #, dsl_module)
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
                
         | 
| 33 | 
            +
               
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
    
        data/hacks/dsl.rb
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            =begin
         | 
| 2 | 
            +
            module Mushin
         | 
| 3 | 
            +
              # DSL module holds one klass and one access method along with 
         | 
| 4 | 
            +
              # one neseted klass and one nested access method
         | 
| 5 | 
            +
              module DSL
         | 
| 6 | 
            +
                def self.inherited(other)
         | 
| 7 | 
            +
                  $log.debug("#{self} is inherited in #{other}")
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
                def self.method_added(name)
         | 
| 10 | 
            +
                  $log.debug("method #{name} is added to #{self}")
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
                begin
         | 
| 13 | 
            +
                  tp = TracePoint.trace(:call) do |tp|                                                                               
         | 
| 14 | 
            +
            	if tp.method_id == :context then
         | 
| 15 | 
            +
            	  $log.debug "#{self} #{[tp.lineno, tp.defined_class, tp.method_id, tp.event]}"
         | 
| 16 | 
            +
            	end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            	if tp.method_id == :const_set then 
         | 
| 19 | 
            +
            	  #puts tp.definedmethods
         | 
| 20 | 
            +
            	  #puts "constant set" 
         | 
| 21 | 
            +
            	  #$log.info("#{self} is inherited in #{other}")
         | 
| 22 | 
            +
            	  #p self
         | 
| 23 | 
            +
            	  #$log.info "#{self} #{[tp.lineno, tp.defined_class, tp.method_id, tp.event, tp.class]}"
         | 
| 24 | 
            +
            	  #p "#{self} #{[tp.lineno, tp.defined_class, tp.method_id, tp.event, tp.class]}"
         | 
| 25 | 
            +
            	  #p self.methods
         | 
| 26 | 
            +
            	  #p constants
         | 
| 27 | 
            +
            	  #, :const_defined?
         | 
| 28 | 
            +
            	  #p tp
         | 
| 29 | 
            +
            	end 
         | 
| 30 | 
            +
            	#p "#{self} #{[tp.lineno, tp.defined_class, tp.method_id, tp.event, tp.class]}"
         | 
| 31 | 
            +
                  end 
         | 
| 32 | 
            +
                rescue Exception
         | 
| 33 | 
            +
                  puts "#{$!} (#{$!.class})"
         | 
| 34 | 
            +
                  $stdout.flush
         | 
| 35 | 
            +
                  raise $!
         | 
| 36 | 
            +
                end 
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
| 39 | 
            +
            =end
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            require_relative 'dsl'
         | 
| 2 | 
            +
            require_relative 'cqrs/command'
         | 
| 3 | 
            +
            require_relative 'cqrs/query'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Mushin
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              module DSLBuilder
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                @@commands = []
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                # The DSLBuilder context access method
         | 
| 12 | 
            +
                def context context_keyword, &block
         | 
| 13 | 
            +
                  $log.debug "printing self from inside DSLBuilder:context #{self}, dsl_array: #{@dsl_array}"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  @@commands << Mushin::DSLBuilder::CQRS::Command.new(context_keyword, &block)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def query &block 
         | 
| 19 | 
            +
                  $log.debug "printing self from inside DSLBuilder:query #{self}"
         | 
| 20 | 
            +
                  #@@commands << Mushin::DSLBuilder::CQRS::Query.new &block
         | 
| 21 | 
            +
                  Mushin::DSLBuilder::CQRS::Query.new &block
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def commands
         | 
| 25 | 
            +
                  @@commands
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              end # end of DSLBuilder module
         | 
| 29 | 
            +
            end # end of Mushin
         | 
| @@ -0,0 +1,119 @@ | |
| 1 | 
            +
            # Credits to https://gist.github.com/ab for source: https://gist.github.com/ab/3161648 
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # Colorizes the output of the standard library logger, depending on the logger level:
         | 
| 4 | 
            +
            # To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require 'logger' 
         | 
| 7 | 
            +
            require 'date'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            module Mushin
         | 
| 10 | 
            +
              # Colorizes the output of the standard library logger, depending on the logger level:
         | 
| 11 | 
            +
              # To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
         | 
| 12 | 
            +
              #
         | 
| 13 | 
            +
              # LEVELS
         | 
| 14 | 
            +
              #========
         | 
| 15 | 
            +
              # UNKNOWN: 	An unknown message that should always be logged.
         | 
| 16 | 
            +
              # FATAL: 	An unhandleable error that results in a program crash.
         | 
| 17 | 
            +
              # ERROR: 	A handleable error condition.
         | 
| 18 | 
            +
              # WARN: 	A warning.
         | 
| 19 | 
            +
              # INFO: 	Generic (useful) information about system operation.
         | 
| 20 | 
            +
              # DEBUG: 	Low-level information for developers.
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              class Logger < Logger
         | 
| 23 | 
            +
                module Colors
         | 
| 24 | 
            +
                  NOTHING      = '0;0'
         | 
| 25 | 
            +
                  BLACK        = '0;30'
         | 
| 26 | 
            +
                  RED          = '0;31'
         | 
| 27 | 
            +
                  GREEN        = '0;32'
         | 
| 28 | 
            +
                  BROWN        = '0;33'
         | 
| 29 | 
            +
                  BLUE         = '0;34'
         | 
| 30 | 
            +
                  PURPLE       = '0;35'
         | 
| 31 | 
            +
                  CYAN         = '0;36'
         | 
| 32 | 
            +
                  LIGHT_GRAY   = '0;37'
         | 
| 33 | 
            +
                  DARK_GRAY    = '1;30'
         | 
| 34 | 
            +
                  LIGHT_RED    = '1;31'
         | 
| 35 | 
            +
                  LIGHT_GREEN  = '1;32'
         | 
| 36 | 
            +
                  YELLOW       = '1;33'
         | 
| 37 | 
            +
                  LIGHT_BLUE   = '1;34'
         | 
| 38 | 
            +
                  LIGHT_PURPLE = '1;35'
         | 
| 39 | 
            +
                  LIGHT_CYAN   = '1;36'
         | 
| 40 | 
            +
                  WHITE        = '1;37'
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  SCHEMA = {
         | 
| 43 | 
            +
            	STDOUT => %w[nothing green brown red purple cyan],
         | 
| 44 | 
            +
            	#STDERR => %w[nothing green yellow light_red light_purple light_cyan],
         | 
| 45 | 
            +
            	STDERR => %w[dark_gray nothing yellow light_red light_purple light_cyan],
         | 
| 46 | 
            +
                  }
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
             | 
| 50 | 
            +
                alias format_message_colorless format_message
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                def format_message(level, *args)
         | 
| 53 | 
            +
                  if self.class::Colors::SCHEMA[@logdev.dev] && @logdev.dev.tty?
         | 
| 54 | 
            +
            	begin
         | 
| 55 | 
            +
            	  index = self.class.const_get(level.sub('ANY','UNKNOWN'))
         | 
| 56 | 
            +
            	  color_name = self.class::Colors::SCHEMA[@logdev.dev][index]
         | 
| 57 | 
            +
            	  color = self.class::Colors.const_get(color_name.to_s.upcase)
         | 
| 58 | 
            +
            	rescue NameError
         | 
| 59 | 
            +
            	  color = '0;0'
         | 
| 60 | 
            +
            	end
         | 
| 61 | 
            +
            	"\e[#{color}m#{format_message_colorless(level, *args)}\e[0;0m"
         | 
| 62 | 
            +
                  else
         | 
| 63 | 
            +
            	format_message_colorless(level, *args)
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                def rainbow(*args)
         | 
| 68 | 
            +
                  SEV_LABEL.each_with_index do |level, i|
         | 
| 69 | 
            +
            	add(i, *args)
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
             
         | 
| 75 | 
            +
              def self.logger(shift_age: 'daily',
         | 
| 76 | 
            +
            		  datetime_format: '%Y-%m-%d %H:%M:%S',
         | 
| 77 | 
            +
            		  log_dir: 'log'
         | 
| 78 | 
            +
            		 )
         | 
| 79 | 
            +
                Dir.mkdir(log_dir) unless File.exists?(log_dir)
         | 
| 80 | 
            +
                logger_file = "#{log_dir}/#{DateTime.now.strftime('%m_%d_%Y')}.log"
         | 
| 81 | 
            +
                file = File.open(logger_file, File::APPEND | File::WRONLY | File::CREAT)
         | 
| 82 | 
            +
                file.sync = true
         | 
| 83 | 
            +
                #file = File.open(logger_file, File::WRONLY | File::APPEND) 
         | 
| 84 | 
            +
                @log = Mushin::Logger.new("| tee " + file.path, shift_age)
         | 
| 85 | 
            +
                @log.datetime_format = datetime_format
         | 
| 86 | 
            +
                #@log.progname = 'eventstream'
         | 
| 87 | 
            +
                
         | 
| 88 | 
            +
                #@log.format_message 'DEBUG', 
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                @log.info "Mushin Log Levels: DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN" 
         | 
| 91 | 
            +
                return @log
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            end
         | 
| 95 | 
            +
            =begin
         | 
| 96 | 
            +
              def black;          "\e[30m#{self}\e[0m" end
         | 
| 97 | 
            +
              def red;            "\e[31m#{self}\e[0m" end
         | 
| 98 | 
            +
              def green;          "\e[32m#{self}\e[0m" end
         | 
| 99 | 
            +
              def brown;          "\e[33m#{self}\e[0m" end
         | 
| 100 | 
            +
              def blue;           "\e[34m#{self}\e[0m" end
         | 
| 101 | 
            +
              def magenta;        "\e[35m#{self}\e[0m" end
         | 
| 102 | 
            +
              def cyan;           "\e[36m#{self}\e[0m" end
         | 
| 103 | 
            +
              def gray;           "\e[37m#{self}\e[0m" end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
              def bg_black;       "\e[40m#{self}\e[0m" end
         | 
| 106 | 
            +
              def bg_red;         "\e[41m#{self}\e[0m" end
         | 
| 107 | 
            +
              def bg_green;       "\e[42m#{self}\e[0m" end
         | 
| 108 | 
            +
              def bg_brown;       "\e[43m#{self}\e[0m" end
         | 
| 109 | 
            +
              def bg_blue;        "\e[44m#{self}\e[0m" end
         | 
| 110 | 
            +
              def bg_magenta;     "\e[45m#{self}\e[0m" end
         | 
| 111 | 
            +
              def bg_cyan;        "\e[46m#{self}\e[0m" end
         | 
| 112 | 
            +
              def bg_gray;        "\e[47m#{self}\e[0m" end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
              def bold;           "\e[1m#{self}\e[22m" end
         | 
| 115 | 
            +
              def italic;         "\e[3m#{self}\e[23m" end
         | 
| 116 | 
            +
              def underline;      "\e[4m#{self}\e[24m" end
         | 
| 117 | 
            +
              def blink;          "\e[5m#{self}\e[25m" end
         | 
| 118 | 
            +
              def reverse_color;  "\e[7m#{self}\e[27m" end
         | 
| 119 | 
            +
            =end
         | 
    
        data/lib/mushin/main.rb
    ADDED
    
    | @@ -0,0 +1,146 @@ | |
| 1 | 
            +
            require 'set'
         | 
| 2 | 
            +
            #TODO write fucken tests, move old specs to hacks dir, then select one big good spec
         | 
| 3 | 
            +
            #TODO write a good generator!
         | 
| 4 | 
            +
            #TODO release 1.0rc
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module Mushin
         | 
| 7 | 
            +
              class Store < Mushin::Test::Sample::Ext
         | 
| 8 | 
            +
                def initialize(ext, opts = {}, params= {})
         | 
| 9 | 
            +
                  @ext 	= ext 
         | 
| 10 | 
            +
                  @opts    	= opts 
         | 
| 11 | 
            +
                  @params  	= params 
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def call(env)
         | 
| 15 | 
            +
                  env ||= Hash.new 
         | 
| 16 | 
            +
                  @ext.call(env)
         | 
| 17 | 
            +
                  return env
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              module Domain
         | 
| 22 | 
            +
                refine Class do 
         | 
| 23 | 
            +
                  #TODO apply advanced centerlized logging automatically via TracePoint, DEBUG log level
         | 
| 24 | 
            +
                  #trace = TracePoint.new(:c_call) do |tp| #  p [tp.lineno, tp.defined_class, tp.method_id, tp.event]#end#trace.enable
         | 
| 25 | 
            +
                  @@dsl_tree = Set.new
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  def context keyword, &context_block
         | 
| 28 | 
            +
            	@context_keyword = keyword
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            	@context_hash = Hash.new
         | 
| 31 | 
            +
            	@context_hash[@context_keyword] = []
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            	def construct keyword, &construct_block
         | 
| 34 | 
            +
            	  @construct_keyword = keyword
         | 
| 35 | 
            +
            	  @construct_hash = Hash.new
         | 
| 36 | 
            +
            	  @construct_hash[@construct_keyword] = []
         | 
| 37 | 
            +
            	  def use ext: nil, opts: nil, params: nil
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            	    $log.debug "use #{ext}, #{opts}, #{params}"
         | 
| 40 | 
            +
            	    @construct_hash[@construct_keyword]  << {ext: ext, opts: opts, params: params}
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            	    #NOTE defining Domain instance methods in this class_exec block
         | 
| 43 | 
            +
            	    class_exec do 
         | 
| 44 | 
            +
            	      def store data_key: nil, data_value: nil
         | 
| 45 | 
            +
            		if !data_key.nil? && !data_value.nil? then
         | 
| 46 | 
            +
            		  @data[data_key] = data_value
         | 
| 47 | 
            +
            		  return @data
         | 
| 48 | 
            +
            		else
         | 
| 49 | 
            +
            		  return @data
         | 
| 50 | 
            +
            		end
         | 
| 51 | 
            +
            	      end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            	      def initialize &domain_block
         | 
| 54 | 
            +
            		@data = Hash.new #should be a HASH
         | 
| 55 | 
            +
             | 
| 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]
         | 
| 91 | 
            +
            			    end
         | 
| 92 | 
            +
             | 
| 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 "
         | 
| 96 | 
            +
            			      @stack.insert_before 0, Mushin::Store, {}, {}
         | 
| 97 | 
            +
            			      stack_data = @stack.call
         | 
| 98 | 
            +
            			      store(data_key: construct_key.to_sym, data_value: stack_data)
         | 
| 99 | 
            +
            			    else
         | 
| 100 | 
            +
            			      @stack.call
         | 
| 101 | 
            +
            			    end
         | 
| 102 | 
            +
            			  end
         | 
| 103 | 
            +
            			end
         | 
| 104 | 
            +
            		      end
         | 
| 105 | 
            +
            		      instance_eval &context_block
         | 
| 106 | 
            +
             | 
| 107 | 
            +
            		      context_set[context_key].each do |construct_hash|
         | 
| 108 | 
            +
            			construct_hash.keys.each do |method_key| 
         | 
| 109 | 
            +
            			  instance_eval("undef :#{method_key}")
         | 
| 110 | 
            +
            			end
         | 
| 111 | 
            +
            			$log.debug "construct_key #{context_key} is undef-ed"
         | 
| 112 | 
            +
            		      end
         | 
| 113 | 
            +
            		    end
         | 
| 114 | 
            +
            		  end
         | 
| 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
         | 
| 122 | 
            +
            	      end
         | 
| 123 | 
            +
            	    end
         | 
| 124 | 
            +
            	  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
         | 
| 133 | 
            +
            	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 | 
            +
             | 
| 143 | 
            +
                  end 
         | 
| 144 | 
            +
                end
         | 
| 145 | 
            +
              end
         | 
| 146 | 
            +
            end
         | 
    
        data/lib/mushin/test_helper.rb
    CHANGED
    
    | @@ -11,7 +11,7 @@ module Mushin | |
| 11 11 | 
             
            	def call(env)
         | 
| 12 12 | 
             
            	  env ||= Hash.new #if env.nil?
         | 
| 13 13 | 
             
            	  $log.info "-----------------------------------------------------------------------"
         | 
| 14 | 
            -
            	  $log.info "Ext: #{self} is called with the following options: #{@opts} & params: #{@params}; and env: #{env}" | 
| 14 | 
            +
            	  $log.info "Ext: #{self} is called with the following options: #{@opts} & params: #{@params}; and env: #{env}"
         | 
| 15 15 | 
             
            	  $log.info "-----------------------------------------------------------------------"
         | 
| 16 16 |  | 
| 17 17 | 
             
            	  # Inbound maniuplation
         | 
    
        data/lib/mushin/version.rb
    CHANGED
    
    
    
        data/lib/mushin.rb
    CHANGED
    
    | @@ -1,66 +1,23 @@ | |
| 1 1 | 
             
            require 'middleware'
         | 
| 2 | 
            -
            require 'logger'
         | 
| 3 2 |  | 
| 4 3 | 
             
            require_relative "mushin/version"
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            #require_relative "mushin/es/event_stream"
         | 
| 4 | 
            +
            require_relative "mushin/logger"
         | 
| 7 5 | 
             
            require_relative "mushin/stack"
         | 
| 8 6 | 
             
            require_relative "mushin/ext"
         | 
| 9 | 
            -
            require_relative "mushin/domain"
         | 
| 10 | 
            -
            require_relative "mushin/generator"
         | 
| 11 7 | 
             
            require_relative "mushin/test_helper"
         | 
| 12 | 
            -
            require_relative "mushin/ | 
| 13 | 
            -
             | 
| 14 | 
            -
            class String
         | 
| 15 | 
            -
              def black;          "\e[30m#{self}\e[0m" end
         | 
| 16 | 
            -
              def red;            "\e[31m#{self}\e[0m" end
         | 
| 17 | 
            -
              def green;          "\e[32m#{self}\e[0m" end
         | 
| 18 | 
            -
              def brown;          "\e[33m#{self}\e[0m" end
         | 
| 19 | 
            -
              def blue;           "\e[34m#{self}\e[0m" end
         | 
| 20 | 
            -
              def magenta;        "\e[35m#{self}\e[0m" end
         | 
| 21 | 
            -
              def cyan;           "\e[36m#{self}\e[0m" end
         | 
| 22 | 
            -
              def gray;           "\e[37m#{self}\e[0m" end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
              def bg_black;       "\e[40m#{self}\e[0m" end
         | 
| 25 | 
            -
              def bg_red;         "\e[41m#{self}\e[0m" end
         | 
| 26 | 
            -
              def bg_green;       "\e[42m#{self}\e[0m" end
         | 
| 27 | 
            -
              def bg_brown;       "\e[43m#{self}\e[0m" end
         | 
| 28 | 
            -
              def bg_blue;        "\e[44m#{self}\e[0m" end
         | 
| 29 | 
            -
              def bg_magenta;     "\e[45m#{self}\e[0m" end
         | 
| 30 | 
            -
              def bg_cyan;        "\e[46m#{self}\e[0m" end
         | 
| 31 | 
            -
              def bg_gray;        "\e[47m#{self}\e[0m" end
         | 
| 8 | 
            +
            require_relative "mushin/main"
         | 
| 32 9 |  | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 10 | 
            +
            #NOTE maybe later
         | 
| 11 | 
            +
            #require_relative "mushin/es/event"
         | 
| 12 | 
            +
            #require_relative "mushin/es/event_stream"
         | 
| 13 | 
            +
            #require_relative "mushin/domain"
         | 
| 14 | 
            +
            #require_relative "mushin/generator"
         | 
| 15 | 
            +
            #require_relative "mushin/bot"
         | 
| 39 16 |  | 
| 40 17 | 
             
            module Mushin
         | 
| 41 | 
            -
              private
         | 
| 42 | 
            -
              # UNKNOWN: 	An unknown message that should always be logged.
         | 
| 43 | 
            -
              # FATAL: 	An unhandleable error that results in a program crash.
         | 
| 44 | 
            -
              # ERROR: 	A handleable error condition.
         | 
| 45 | 
            -
              # WARN: 	A warning.
         | 
| 46 | 
            -
              # INFO: 	Generic (useful) information about system operation.
         | 
| 47 | 
            -
              # DEBUG: 	Low-level information for developers.
         | 
| 48 | 
            -
              def self.logger(shift_age: 'daily',
         | 
| 49 | 
            -
            	     datetime_format: '%Y-%m-%d %H:%M:%S',
         | 
| 50 | 
            -
            	     log_dir: 'log'
         | 
| 51 | 
            -
            	    )
         | 
| 52 | 
            -
                Dir.mkdir(log_dir) unless File.exists?(log_dir)
         | 
| 53 | 
            -
                logger_file = "#{log_dir}/#{DateTime.now.strftime('%m_%d_%Y')}.log"
         | 
| 54 | 
            -
                file = File.open(logger_file, File::APPEND | File::WRONLY | File::CREAT)
         | 
| 55 | 
            -
                file.sync = true
         | 
| 56 | 
            -
                #file = File.open(logger_file, File::WRONLY | File::APPEND) 
         | 
| 57 | 
            -
                @log = Logger.new("| tee " + file.path, shift_age)
         | 
| 58 | 
            -
                @log.datetime_format = datetime_format
         | 
| 59 | 
            -
                #@log.progname = 'eventstream'
         | 
| 60 18 |  | 
| 61 | 
            -
             | 
| 62 | 
            -
                return @log
         | 
| 63 | 
            -
              end
         | 
| 19 | 
            +
              $log = Mushin.logger #Logger.new(STDOUT)
         | 
| 64 20 |  | 
| 65 | 
            -
               | 
| 21 | 
            +
              # Set logging level to info 
         | 
| 22 | 
            +
              $log.level = Logger::INFO
         | 
| 66 23 | 
             
            end
         | 
    
        data/mushin.gemspec
    CHANGED
    
    | @@ -42,7 +42,10 @@ Gem::Specification.new do |spec| | |
| 42 42 | 
             
              spec.add_runtime_dependency "cinch" #, "~> 0.3"
         | 
| 43 43 |  | 
| 44 44 | 
             
              # favouring ore for gem generation over bundler, as it providers a fine-grained customization
         | 
| 45 | 
            -
              spec.add_runtime_dependency  | 
| 45 | 
            +
              spec.add_runtime_dependency 'ore' #, '~> 0.3'
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              #spec.add_runtime_dependency 'logger-colors', '~> 1.0'
         | 
| 48 | 
            +
             | 
| 46 49 |  | 
| 47 50 | 
             
              #TODO http://guides.rubygems.org/security/
         | 
| 48 51 | 
             
            end
         | 
    
        data/samples/sample2.rb
    CHANGED
    
    | @@ -112,3 +112,135 @@ module Mushin | |
| 112 112 | 
             
              module DSL
         | 
| 113 113 | 
             
              end
         | 
| 114 114 | 
             
            end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            #self.singleton_class.send :remove_method, construct_key.to_sym
         | 
| 117 | 
            +
            #self.singleton_class.send :remove_method, context_key.to_sym
         | 
| 118 | 
            +
            #self.singleton_class.send :undef, context_key.to_sym
         | 
| 119 | 
            +
            #
         | 
| 120 | 
            +
             | 
| 121 | 
            +
             | 
| 122 | 
            +
            # tree is a set
         | 
| 123 | 
            +
            # each context is a set
         | 
| 124 | 
            +
            # each construct is a hash where construct_name is key, and [ext, params, opts] are array
         | 
| 125 | 
            +
            #tree = [{:torrent_bots => [{:tpb => [["TPB", "params hash", "opts hash"], ["SSD", "params hash", "opts hash"]}]
         | 
| 126 | 
            +
             | 
| 127 | 
            +
             | 
| 128 | 
            +
            =begin
         | 
| 129 | 
            +
              module DSL
         | 
| 130 | 
            +
                refine Class do
         | 
| 131 | 
            +
                end
         | 
| 132 | 
            +
              end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
            	    if  Mushin::DSL.const_defined? @context_keyword.capitalize then
         | 
| 135 | 
            +
            	      Mushin::DSL.const_set "#{@context_keyword.capitalize}", Module.new do 
         | 
| 136 | 
            +
            		send :define_method, :build_dsl do |dsl_tree= @dsl_tree, &block|
         | 
| 137 | 
            +
            		  p "passed the tree to the dsl_module #{dsl_tree}"
         | 
| 138 | 
            +
            		  #p dsl_tree
         | 
| 139 | 
            +
            		end
         | 
| 140 | 
            +
            	      end
         | 
| 141 | 
            +
            	    else
         | 
| 142 | 
            +
            	      p "prepend the module here"
         | 
| 143 | 
            +
            	    end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
            =end
         | 
| 146 | 
            +
            =begin
         | 
| 147 | 
            +
            module DSL
         | 
| 148 | 
            +
                def self.included base
         | 
| 149 | 
            +
                  base.class_eval do
         | 
| 150 | 
            +
            	#attr_accessor :keyword_array 
         | 
| 151 | 
            +
            	def initialize &block
         | 
| 152 | 
            +
            	  #@keyword_array = []
         | 
| 153 | 
            +
            	  instance_eval &block
         | 
| 154 | 
            +
            	end
         | 
| 155 | 
            +
                  end
         | 
| 156 | 
            +
                  minis.each do |m| 
         | 
| 157 | 
            +
            	p m
         | 
| 158 | 
            +
            	p m
         | 
| 159 | 
            +
            	p m
         | 
| 160 | 
            +
            	p m
         | 
| 161 | 
            +
            	base.send :include, m
         | 
| 162 | 
            +
                  end
         | 
| 163 | 
            +
                end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                def self.minis
         | 
| 166 | 
            +
                  constants.collect {|const_name| const_get(const_name)}.select {|const| const.class == Module}
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
                end
         | 
| 169 | 
            +
            =end
         | 
| 170 | 
            +
             | 
| 171 | 
            +
            #NOTE can be Module.new("Mushin::DSL" + context_keyword.capitalize) to differeniate the minidsls dynamically added to an object in testing
         | 
| 172 | 
            +
            #dsl_module = Module.new(Mushin::DSL) do 
         | 
| 173 | 
            +
            #end
         | 
| 174 | 
            +
            #p context_keyword = @context_keyword 
         | 
| 175 | 
            +
            #p construct_keyword = @construct_keyword 
         | 
| 176 | 
            +
             | 
| 177 | 
            +
            =begin
         | 
| 178 | 
            +
            def self.included base
         | 
| 179 | 
            +
              base.class_eval do
         | 
| 180 | 
            +
                attr_accessor :keyword_array 
         | 
| 181 | 
            +
                def initialize &block
         | 
| 182 | 
            +
                  @keyword_array = []
         | 
| 183 | 
            +
                  instance_eval &block
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
              end
         | 
| 186 | 
            +
            end
         | 
| 187 | 
            +
            =end
         | 
| 188 | 
            +
             | 
| 189 | 
            +
            =begin
         | 
| 190 | 
            +
            	      #define_method construct_keyword do |&block|
         | 
| 191 | 
            +
            	      #self.extend dsl
         | 
| 192 | 
            +
            	      #	instance_eval &block
         | 
| 193 | 
            +
            	      #      end
         | 
| 194 | 
            +
             | 
| 195 | 
            +
            	      dsl.send :define_method, construct_keyword do |&block|
         | 
| 196 | 
            +
            		p "inside the instance construct #{self}"
         | 
| 197 | 
            +
            		p self
         | 
| 198 | 
            +
            		p self
         | 
| 199 | 
            +
            	      end
         | 
| 200 | 
            +
             | 
| 201 | 
            +
            	      define_method context_keyword do |&block|
         | 
| 202 | 
            +
            		p "inside the instance context #{self} with context_keyword #{context_keyword}"
         | 
| 203 | 
            +
            		instance_eval &block # self is the dsl module
         | 
| 204 | 
            +
            	      end
         | 
| 205 | 
            +
            =end
         | 
| 206 | 
            +
             | 
| 207 | 
            +
            #dsl.send :define_method, @context_keyword do |&block|
         | 
| 208 | 
            +
            #  p self
         | 
| 209 | 
            +
            #  instance_eval &block
         | 
| 210 | 
            +
            #end
         | 
| 211 | 
            +
             | 
| 212 | 
            +
            #dsl.send 
         | 
| 213 | 
            +
            #self.class.send :define_method, @construct_keyword do |&block|
         | 
| 214 | 
            +
            #  instance_eval &block
         | 
| 215 | 
            +
            #end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
            # alias_method + refinment + dynamically created module that is included(maybe that wouldn't be passed)
         | 
| 218 | 
            +
            =begin
         | 
| 219 | 
            +
              module DSL
         | 
| 220 | 
            +
                def self.included base
         | 
| 221 | 
            +
                  base.class_eval do
         | 
| 222 | 
            +
            	def initialize &block
         | 
| 223 | 
            +
            	  instance_eval &block
         | 
| 224 | 
            +
            	end
         | 
| 225 | 
            +
                  end
         | 
| 226 | 
            +
                end
         | 
| 227 | 
            +
              end
         | 
| 228 | 
            +
            =end
         | 
| 229 | 
            +
            #define_method @context_keyword do |&block|
         | 
| 230 | 
            +
            #self.send :include, Mushin::DSL #self.send :prepend, Mushin::DSL
         | 
| 231 | 
            +
            =begin
         | 
| 232 | 
            +
            Mushin::DSL.send :define_method, @context_keyword do |&block|
         | 
| 233 | 
            +
            	    p "inside the domain obj"
         | 
| 234 | 
            +
            	    #self.class.send :define_method, construct_keyword do |&block|
         | 
| 235 | 
            +
            	    #end
         | 
| 236 | 
            +
            	    p self 
         | 
| 237 | 
            +
            	    p construct_keyword
         | 
| 238 | 
            +
            	    p "....."
         | 
| 239 | 
            +
            	    instance_eval &block
         | 
| 240 | 
            +
            	  end
         | 
| 241 | 
            +
            =end
         | 
| 242 | 
            +
            #p "context #{@context_keyword} is defined in Mushin::DSL"
         | 
| 243 | 
            +
            #Mushin::DSL.send :remove_method, @context_keyword 
         | 
| 244 | 
            +
            # Foo.instance_eval { undef :color }
         | 
| 245 | 
            +
            # removed_method removes method of receiver class where as undef_method removed all methods from inherited class including receiver class. 
         | 
| 246 | 
            +
            #base.send :prepend, DSL
         | 
    
        data/samples/sample3.rb
    ADDED
    
    | @@ -0,0 +1,132 @@ | |
| 1 | 
            +
            require_relative './../lib/mushin'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Sample
         | 
| 4 | 
            +
              class TBP < Mushin::Test::Sample::Ext; end
         | 
| 5 | 
            +
              class SSD < Mushin::Test::Sample::Ext; end
         | 
| 6 | 
            +
              class SSDS < Mushin::Test::Sample::Ext
         | 
| 7 | 
            +
                def initialize(ext, opts = {}, params= {})
         | 
| 8 | 
            +
                  @ext 	= ext 
         | 
| 9 | 
            +
                  @opts    	= opts 
         | 
| 10 | 
            +
                  @params  	= params 
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def call(env)
         | 
| 14 | 
            +
                  env ||= Hash.new 
         | 
| 15 | 
            +
                  env[:SSDS_middlewareEnvKey] = "SSDS"
         | 
| 16 | 
            +
                  @ext.call(env)
         | 
| 17 | 
            +
                  #super
         | 
| 18 | 
            +
                  #return env
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              class SSDA < Mushin::Test::Sample::Ext
         | 
| 23 | 
            +
                def initialize(ext, opts = {}, params= {})
         | 
| 24 | 
            +
                  @ext 		= ext 
         | 
| 25 | 
            +
                  @opts    	= opts 
         | 
| 26 | 
            +
                  @params  	= params 
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def call(env)
         | 
| 30 | 
            +
                  env ||= Hash.new 
         | 
| 31 | 
            +
                  env[:nana] = "nana_what"
         | 
| 32 | 
            +
                  env[:SSDA_middlewareEnvKey] = "SSDA"
         | 
| 33 | 
            +
                  @ext.call(env)
         | 
| 34 | 
            +
                  env[:superman_real_nameB] = "where are you now dada"
         | 
| 35 | 
            +
                  #return env
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              class RUTracker < Mushin::Test::Sample::Ext 
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
              class Mongodb < Mushin::Test::Sample::Ext; end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              class Domain
         | 
| 44 | 
            +
                using Mushin::Domain
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                context "torrent_bots" do
         | 
| 47 | 
            +
                  construct "tpb" do
         | 
| 48 | 
            +
            	use ext: Sample::TBP, params: {}, opts: {"search_results" => :search_result_max}
         | 
| 49 | 
            +
            	use ext: Sample::SSD, params: {}, opts: {"ssd_path"=> :storage_path}
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  construct "rutracker" do
         | 
| 53 | 
            +
            	use ext: RUTracker, params: {}, opts: {"search_results" => :search_result_max}
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                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}
         | 
| 61 | 
            +
                  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 | 
            +
                  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}
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
                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 | 
            +
              end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
              class App
         | 
| 85 | 
            +
                mydomain = Domain.new do
         | 
| 86 | 
            +
                  params = {}
         | 
| 87 | 
            +
                  params[:secret] = "8888"
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  torrent_bots do
         | 
| 90 | 
            +
            	tpb search_result_max: "20", storage_path:"crazypath_here"
         | 
| 91 | 
            +
            	rutracker search_result_max: params[:secret]
         | 
| 92 | 
            +
                  end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                  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"
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                  #=begin 
         | 
| 101 | 
            +
                  #TODO it 'must only accepts things for that had been defined'
         | 
| 102 | 
            +
                  #ss do
         | 
| 103 | 
            +
                  #end
         | 
| 104 | 
            +
                  #torrent_bots do
         | 
| 105 | 
            +
                  #TODO it 'must only accepts things for that had been defined'
         | 
| 106 | 
            +
                  #stpb do
         | 
| 107 | 
            +
                  #end
         | 
| 108 | 
            +
                  #tpb "this is good"
         | 
| 109 | 
            +
                  #  tpb search_result_max: "202", storage_path:"crazypath_here2"
         | 
| 110 | 
            +
                  #end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                  #TODO it 'should be nested correctly"
         | 
| 113 | 
            +
                  #tpb "this is should be nested and shouldn't be allowed to work"
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                  #ztorrent_bots do
         | 
| 116 | 
            +
                  #  zrutracker search_result_max: params[:secret2]
         | 
| 117 | 
            +
                  #  #zxy "god"
         | 
| 118 | 
            +
                  #end
         | 
| 119 | 
            +
                  #=end
         | 
| 120 | 
            +
                end
         | 
| 121 | 
            +
                #p "inspecting the domain object"
         | 
| 122 | 
            +
                #p mydomain.methods
         | 
| 123 | 
            +
                #p mydomain.inspect
         | 
| 124 | 
            +
                #p mydomain.instance_variable_get("@xyz")
         | 
| 125 | 
            +
                #p mydomain.store[:love]
         | 
| 126 | 
            +
                #p mydomain.store[:xyz]
         | 
| 127 | 
            +
                #p mydomain.store[:torrentsB][:nana]
         | 
| 128 | 
            +
                p mydomain.store[:torrentsC]
         | 
| 129 | 
            +
                p mydomain.store[:torrentsB]
         | 
| 130 | 
            +
                p mydomain.store
         | 
| 131 | 
            +
              end
         | 
| 132 | 
            +
            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. | 
| 4 | 
            +
              version: 0.19.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-12- | 
| 11 | 
            +
            date: 2016-12-09 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -173,8 +173,6 @@ extensions: [] | |
| 173 173 | 
             
            extra_rdoc_files: []
         | 
| 174 174 | 
             
            files:
         | 
| 175 175 | 
             
            - ".gitignore"
         | 
| 176 | 
            -
            - ".ssd/eventstream/11_29_2016.ssd"
         | 
| 177 | 
            -
            - ".ssd/eventstream/11_30_2016.ssd"
         | 
| 178 176 | 
             
            - ".travis.yml"
         | 
| 179 177 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 180 178 | 
             
            - Gemfile
         | 
| @@ -185,23 +183,26 @@ files: | |
| 185 183 | 
             
            - bin/console
         | 
| 186 184 | 
             
            - bin/setup
         | 
| 187 185 | 
             
            - exe/mushin
         | 
| 186 | 
            +
            - hacks/bot.rb
         | 
| 187 | 
            +
            - hacks/cqrs/command.rb
         | 
| 188 | 
            +
            - hacks/cqrs/query.rb
         | 
| 189 | 
            +
            - hacks/domain.rb
         | 
| 190 | 
            +
            - hacks/dsl.rb
         | 
| 191 | 
            +
            - hacks/dsl_builder.rb
         | 
| 192 | 
            +
            - hacks/es/event.rb
         | 
| 193 | 
            +
            - hacks/es/event_stream.rb
         | 
| 194 | 
            +
            - hacks/generator.rb
         | 
| 188 195 | 
             
            - lib/mushin.rb
         | 
| 189 | 
            -
            - lib/mushin/bot.rb
         | 
| 190 | 
            -
            - lib/mushin/cqrs/command.rb
         | 
| 191 | 
            -
            - lib/mushin/cqrs/query.rb
         | 
| 192 | 
            -
            - lib/mushin/domain.rb
         | 
| 193 | 
            -
            - lib/mushin/dsl.rb
         | 
| 194 | 
            -
            - lib/mushin/dsl_builder.rb
         | 
| 195 | 
            -
            - lib/mushin/es/event.rb
         | 
| 196 | 
            -
            - lib/mushin/es/event_stream.rb
         | 
| 197 196 | 
             
            - lib/mushin/ext.rb
         | 
| 198 | 
            -
            - lib/mushin/ | 
| 197 | 
            +
            - lib/mushin/logger.rb
         | 
| 198 | 
            +
            - lib/mushin/main.rb
         | 
| 199 199 | 
             
            - lib/mushin/stack.rb
         | 
| 200 200 | 
             
            - lib/mushin/test_helper.rb
         | 
| 201 201 | 
             
            - lib/mushin/version.rb
         | 
| 202 202 | 
             
            - mushin.gemspec
         | 
| 203 203 | 
             
            - samples/sample1.rb
         | 
| 204 204 | 
             
            - samples/sample2.rb
         | 
| 205 | 
            +
            - samples/sample3.rb
         | 
| 205 206 | 
             
            homepage: http://mushin-rb.github.io/
         | 
| 206 207 | 
             
            licenses:
         | 
| 207 208 | 
             
            - MIT
         | 
| @@ -1,9 +0,0 @@ | |
| 1 | 
            -
            ---
         | 
| 2 | 
            -
            2016-11-30 08:05:58 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
| 3 | 
            -
            2016-11-30 08:06:25 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
| 4 | 
            -
            2016-11-30 08:06:29 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
| 5 | 
            -
            2016-11-30 08:06:31 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
| 6 | 
            -
            2016-11-30 08:06:32 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
| 7 | 
            -
            2016-11-30 08:53:50 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
| 8 | 
            -
            2016-11-30 09:01:43 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
| 9 | 
            -
            2016-11-30 10:03:04 UTC_11_30_2016: !ruby/object:Mushin::ES::Event {}
         | 
    
        data/lib/mushin/domain.rb
    DELETED
    
    | @@ -1,21 +0,0 @@ | |
| 1 | 
            -
            require_relative 'dsl_builder'
         | 
| 2 | 
            -
            module Mushin
         | 
| 3 | 
            -
             | 
| 4 | 
            -
              class Domain
         | 
| 5 | 
            -
                # offers a virtual datastore for query requests on the domain object
         | 
| 6 | 
            -
                #attr_accessor :store, :event_stream
         | 
| 7 | 
            -
                attr_accessor :dparams
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                def self.inherited(subclass)
         | 
| 10 | 
            -
                  subclass.send :extend, DSLBuilder 
         | 
| 11 | 
            -
                  subclass.send :include, DSL 
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                def initialize params={}, &block
         | 
| 15 | 
            -
                  @dparams = params
         | 
| 16 | 
            -
                  $log.info "Domain object #{self} is going to instance_eval with dparams of #{@dparams}"
         | 
| 17 | 
            -
                  #TODO obj.send("#{prop_name}=", query_value)
         | 
| 18 | 
            -
                  instance_eval &block
         | 
| 19 | 
            -
                end
         | 
| 20 | 
            -
              end
         | 
| 21 | 
            -
            end
         | 
    
        data/lib/mushin/dsl.rb
    DELETED
    
    
    
        data/lib/mushin/dsl_builder.rb
    DELETED
    
    | @@ -1,23 +0,0 @@ | |
| 1 | 
            -
            #require 'mushin'
         | 
| 2 | 
            -
            require_relative 'dsl'
         | 
| 3 | 
            -
            require_relative 'cqrs/command'
         | 
| 4 | 
            -
            require_relative 'cqrs/query'
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            module Mushin
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              module DSLBuilder
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                # The DSLBuilder context access method
         | 
| 11 | 
            -
                def context context_keyword, &block
         | 
| 12 | 
            -
                  p "printing self from inside DSLBuilder:context #{self}"
         | 
| 13 | 
            -
                  Mushin::DSLBuilder::CQRS::Command.new context_keyword, &block
         | 
| 14 | 
            -
                  #Mushin::DSLBuilder::CQRS::Context
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                def query &block 
         | 
| 18 | 
            -
                  p "printing self from inside DSLBuilder:query #{self}"
         | 
| 19 | 
            -
                  Mushin::DSLBuilder::CQRS::Query.new &block
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
              end # end of DSLBuilder module
         | 
| 23 | 
            -
            end
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         |