mushin 0.0.0.pre53 → 0.0.0.pre55

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: 4ce885be69161e374cfd40f005fc06db0fa5a27d
4
- data.tar.gz: 100fb96ad91036e2e5392e502e6a3bc9f78109f0
3
+ metadata.gz: 884ae94e93a1a1165ce87ea3e14e9f79ce08b504
4
+ data.tar.gz: ab9b87746c7ef9545d5a0bf104c03584d6393ad9
5
5
  SHA512:
6
- metadata.gz: 54e7eb81992036afa41a7d3af590b85a8afb9b813f3cf7db9c55e0e22499328a12ba9ec43279effe8fc7b99888248c19c0d9431e0b2f28c8715a12ec78b1c263
7
- data.tar.gz: c5a52b00b6508781105f3614fcef8640369e74adb197405bbeb6a5eeb2571fb6c821768af8406e34b57da2031d1c994d9cbad6355d0e6af43683ec9bc64edad2
6
+ metadata.gz: f9c66cb155dfa1ba03c9b0d076c961caec5f874259f959d6cbc0bb2cc247e898a4b25b54f0750d8f896047f1cd4818692b1273a5a5a8ec459841920c921b62ed
7
+ data.tar.gz: 3ba4a08ad2bec98a2f4e02dfe17bba3f02fbfa696315353ba63121a873570a5b6d4de4c489e75779b05f366a6233ca81acc383c7b7c3caf26c2ee5f7442d4885
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.pre53
4
+ version: 0.0.0.pre55
5
5
  platform: ruby
6
6
  authors:
7
7
  - theotherstupidguy
@@ -20,14 +20,12 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - bin/mushin
22
22
  - lib/mushin.rb
23
- - lib/mushin/base.rb
24
- - lib/mushin/middleware/builder.rb
25
- - lib/mushin/middleware/runner.rb
26
23
  homepage: https://github.com/mushin-rb/mushin
27
24
  licenses:
28
25
  - MIT
29
26
  metadata: {}
30
- post_install_message:
27
+ post_install_message: |2
28
+ ! Mushin is kinda Awesome.
31
29
  rdoc_options: []
32
30
  require_paths:
33
31
  - lib
data/lib/mushin/base.rb DELETED
@@ -1,102 +0,0 @@
1
- require_relative './middleware/builder'
2
- require_relative './middleware/runner'
3
-
4
- module Mushin # Domain Frameworks Generator
5
- module Errors
6
- exceptions = %w[ UnkownDSLConstruct UnkownActivation UnknownOption ]
7
- exceptions.each { |e| const_set(e, Class.new(StandardError)) }
8
- end
9
-
10
- module Env
11
- def register &block
12
- module_eval &block
13
- end
14
-
15
- def set id, &block
16
- raise "Domain Framework must impelment set"
17
- end
18
- def get id
19
- raise "Domain Framework must impelment get"
20
- end
21
- end
22
- module Domain
23
- module Mushin::Domain::Middleware
24
- class << self
25
- attr_accessor :opts, :params
26
- def opts
27
- @opts ||= {}
28
- end
29
- def params
30
- @params ||= {}
31
- end
32
- end
33
- module Opts
34
- def self.[] key
35
- Mushin::Domain::Middleware.opts[key]
36
- end
37
- def self.[]= key, value
38
- Mushin::Domain::Middleware.opts.merge! Hash[key, value]
39
- end
40
- end
41
- module Params
42
- def self.[] key
43
- Mushin::Domain::Middleware.params[key]
44
- end
45
- def self.[]= key, value
46
- Mushin::Domain::Middleware.params.merge! Hash[key, value]
47
- end
48
- end
49
- end
50
- end
51
-
52
- module DSL
53
- class Context
54
- attr_accessor :title, :statments
55
- def initialize title
56
- @title = title
57
- @statments = []
58
- end
59
- end
60
- class Statment
61
- attr_accessor :title, :activations
62
- def initialize title
63
- @title = title
64
- @activations = []
65
- end
66
- end
67
- class Activation
68
- attr_accessor :name, :opts, :params
69
- def initialize name, opts={}, params={}
70
- @name = name
71
- @opts = opts
72
- @params = params
73
- end
74
- end
75
-
76
- class << self
77
- attr_accessor :contexts, :middlewares
78
- end
79
- Mushin::DSL.contexts = []
80
- def context title, &block
81
- @context = Mushin::DSL::Context.new title
82
- def statment statment=[], &block
83
- @statment = Mushin::DSL::Statment.new statment
84
- def activation name, opts={}, params={}
85
- @activation = Mushin::DSL::Activation.new name, opts, params
86
- @statment.activations << @activation
87
- end
88
- yield
89
- @context.statments << @statment
90
- end
91
- yield
92
- Mushin::DSL.contexts << @context
93
- end
94
- end
95
-
96
- module Engine
97
- attr_accessor :setup_middlewares
98
- def setup before_stack = []
99
- @setup_middlewares = before_stack
100
- end
101
- end
102
- end
@@ -1,139 +0,0 @@
1
- module Mushin
2
- module Middleware
3
- # This provides a DSL for building up a stack of middlewares.
4
- #
5
- # This code is based heavily off of `Rack::Builder` and
6
- # `ActionDispatch::MiddlewareStack` in Rack and Rails, respectively.
7
- #
8
- # # Usage
9
- #
10
- # Building a middleware stack is very easy:
11
- #
12
- # app = Middleware::Builder.new do
13
- # use A
14
- # use B
15
- # end
16
- #
17
- # # Call the middleware
18
- # app.call(7)
19
- #
20
- class Builder
21
- # Initializes the builder. An optional block can be passed which
22
- # will be evaluated in the context of the instance.
23
- #
24
- # Example:
25
- #
26
- # Builder.new do
27
- # use A
28
- # use B
29
- # end
30
- #
31
- # @param [Hash] opts Options hash
32
- # @option opts [Class] :runner_class The class to wrap the middleware stack
33
- # in which knows how to run them.
34
- # @yield [] Evaluated in this instance which allows you to use methods
35
- # like {#use} and such.
36
- #def game name, *dyx, &block
37
- def initialize(opts=nil, &block)
38
- opts ||= {}
39
- @runner_class = opts[:runner_class] || Runner
40
- instance_eval(&block) if block_given?
41
- end
42
-
43
- # Returns a mergeable version of the builder. If `use` is called with
44
- # the return value of this method, then the stack will merge, instead
45
- # of being treated as a separate single middleware.
46
- def flatten
47
- lambda do |env|
48
- self.call(env)
49
- end
50
- end
51
-
52
- # Adds a middleware class to the middleware stack. Any additional
53
- # args and a block, if given, are saved and passed to the initializer
54
- # of the middleware.
55
- #
56
- # @param [Class] middleware The middleware class
57
- def use(middleware, *args, &block)
58
- if middleware.kind_of?(Builder)
59
- # Merge in the other builder's stack into our own
60
- self.stack.concat(middleware.stack)
61
- else
62
- self.stack << [middleware, args, block]
63
- end
64
-
65
- self
66
- end
67
-
68
- # Inserts a middleware at the given index or directly before the
69
- # given middleware object.
70
- def insert(index, middleware, *args, &block)
71
- index = self.index(index) unless index.is_a?(Integer)
72
- raise "no such middleware to insert before: #{index.inspect}" unless index
73
- stack.insert(index, [middleware, args, block])
74
- end
75
-
76
- alias_method :insert_before, :insert
77
-
78
- # Inserts a middleware after the given index or middleware object.
79
- def insert_after(index, middleware, *args, &block)
80
- index = self.index(index) unless index.is_a?(Integer)
81
- raise "no such middleware to insert after: #{index.inspect}" unless index
82
- insert(index + 1, middleware, *args, &block)
83
- end
84
-
85
- # Replaces the given middleware object or index with the new
86
- # middleware.
87
- def replace(index, middleware, *args, &block)
88
- if index.is_a?(Integer)
89
- delete(index)
90
- insert(index, middleware, *args, &block)
91
- else
92
- insert_before(index, middleware, *args, &block)
93
- delete(index)
94
- end
95
- end
96
-
97
- # Deletes the given middleware object or index
98
- def delete(index)
99
- index = self.index(index) unless index.is_a?(Integer)
100
- stack.delete_at(index)
101
- end
102
-
103
- # Runs the builder stack with the given environment.
104
- def call(env = Hash.new)
105
- #def call(env=nil)
106
- to_app.call(env)
107
- end
108
-
109
- protected
110
-
111
- # Returns the numeric index for the given middleware object.
112
- #
113
- # @param [Object] object The item to find the index for
114
- # @return [Integer]
115
- def index(object)
116
- stack.each_with_index do |item, i|
117
- return i if item[0] == object
118
- end
119
-
120
- nil
121
- end
122
-
123
- # Returns the current stack of middlewares. You probably won't
124
- # need to use this directly, and it's recommended that you don't.
125
- #
126
- # @return [Array]
127
- def stack
128
- @stack ||= []
129
- end
130
-
131
- # Converts the builder stack to a runnable action sequence.
132
- #
133
- # @return [Object] A callable object
134
- def to_app
135
- @runner_class.new(stack.dup)
136
- end
137
- end
138
- end
139
- end
@@ -1,71 +0,0 @@
1
- module Mushin
2
- module Middleware
3
- # This is a basic runner for middleware stacks. This runner does
4
- # the default expected behavior of running the middleware stacks
5
- # in order, then reversing the order.
6
- class Runner
7
- # A middleware which does nothing
8
- EMPTY_MIDDLEWARE = lambda { |env| }
9
-
10
- # Build a new middleware runner with the given middleware
11
- # stack.
12
- #
13
- # Note: This class usually doesn't need to be used directly.
14
- # Instead, take a look at using the {Builder} class, which is
15
- # a much friendlier way to build up a middleware stack.
16
- #
17
- # @param [Array] stack An array of the middleware to run.
18
- def initialize(stack)
19
- # We need to take the stack of middleware and initialize them
20
- # all so they call the proper next middleware.
21
- @kickoff = build_call_chain(stack)
22
- end
23
-
24
- # Run the middleware stack with the given state bag.
25
- #
26
- # @param [Object] env The state to pass into as the initial
27
- # environment data. This is usual a hash of some sort.
28
- def call(env)
29
- # We just call the kickoff middleware, which is responsible
30
- # for properly calling the next middleware, and so on and so
31
- # forth.
32
- @kickoff.call(env)
33
- end
34
-
35
- protected
36
-
37
- # This takes a stack of middlewares and initializes them in a way
38
- # that each middleware properly calls the next middleware.
39
- def build_call_chain(stack)
40
- # We need to instantiate the middleware stack in reverse
41
- # order so that each middleware can have a reference to
42
- # the next middleware it has to call. The final middleware
43
- # is always the empty middleware, which does nothing but return.
44
- stack.reverse.inject(EMPTY_MIDDLEWARE) do |next_middleware, current_middleware|
45
- # Unpack the actual item
46
- klass, args, block = current_middleware
47
-
48
- # Default the arguments to an empty array. Otherwise in Ruby 1.8
49
- # a `nil` args will actually pass `nil` into the class. Not what
50
- # we want!
51
- args ||= []
52
-
53
- if klass.is_a?(Class)
54
- # If the klass actually is a class, then instantiate it with
55
- # the app and any other arguments given.
56
- klass.new(next_middleware, *args, &block)
57
- elsif klass.respond_to?(:call)
58
- # Make it a lambda which calls the item then forwards up
59
- # the chain.
60
- lambda do |env|
61
- klass.call(env)
62
- next_middleware.call(env)
63
- end
64
- else
65
- raise "Invalid middleware, doesn't respond to `call`: #{action.inspect}"
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end