micon 0.1.17 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -25,7 +25,6 @@ files:
25
25
  - lib/micon/helper.rb
26
26
  - lib/micon/metadata.rb
27
27
  - lib/micon/module.rb
28
- - lib/micon/rad.rb
29
28
  - lib/micon/spec.rb
30
29
  - lib/micon/support.rb
31
30
  - lib/micon.rb
@@ -39,16 +38,6 @@ files:
39
38
  - spec/constants_spec/get_constant_component/lib/components/TheController.rb
40
39
  - spec/constants_spec.rb
41
40
  - spec/custom_scope_spec.rb
42
- - spec/example_spec/lib/components/controller.rb
43
- - spec/example_spec/lib/components/logger.production.yml
44
- - spec/example_spec/lib/components/logger.rb
45
- - spec/example_spec/lib/components/logger.yml
46
- - spec/example_spec/lib/components/request.rb
47
- - spec/example_spec/lib/components/router.rb
48
- - spec/example_spec/lib/pages_controller.rb
49
- - spec/example_spec/lib/rack_adapter.rb
50
- - spec/example_spec/lib/request.rb
51
- - spec/example_spec.rb
52
41
  - spec/initialization_spec.rb
53
42
  - spec/managed_spec.rb
54
43
  - spec/miscellaneous_spec/autoload/lib/components/some_value.rb
data/lib/micon/rad.rb DELETED
@@ -1,8 +0,0 @@
1
- Micon::Core.include Micon::Helper
2
-
3
- micon = Micon::Core.new
4
- micon.initialize!
5
-
6
- def rad
7
- ::MICON
8
- end
data/spec/example_spec.rb DELETED
@@ -1,171 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Micon Overview" do
4
- before do
5
- self.micon = Micon::Core.new
6
- end
7
- after do
8
- remove_constants :Logger, :Router, :PagesController, :Request, :RackAdapter
9
- end
10
-
11
- it "example" do
12
- require 'micon'
13
-
14
- # Here's our Web Framework, let's call it Rad
15
-
16
- # Let's define shortcut to access the IoC API (optional
17
- # but handy step). I don't know how You would like to call it,
18
- # so I leave this step to You.
19
- class ::Object
20
- def rad; MICON end
21
- end
22
-
23
- # let's define some components
24
- # the :logger is one per application, it's a static component (like singleton)
25
- class Logger
26
- register_as :logger
27
- attr_accessor :log_file_path
28
- def info msg
29
- puts "#{msg} (writen to #{log_file_path})" unless defined?(RSpec)
30
- end
31
- end
32
-
33
- # To demostrate basics of working with compnents let's configure our :logger
34
- # explicitly (in the next example, it will be configured automatically).
35
- rad.logger.log_file_path = '/tmp/rad.log'
36
-
37
- # The :router requires complex initialization, so we use
38
- # another form of component registration.
39
- class Router
40
- def initialize routes; @routes = routes end
41
- def decode request;
42
- class_name, method = @routes[request.url]
43
- return eval(class_name), method # returning actual class
44
- end
45
- end
46
- rad.register :router do
47
- Router.new '/index' => ['PagesController', :index]
48
- end
49
-
50
- # The :controller component should be created and destroyed dynamically,
51
- # for each request, we specifying that component is dynamic
52
- # by declaring it's :scope.
53
- # And, we don't know beforehead what it actully will be, for different
54
- # request there can be different controllers,
55
- # so, here we just declaring it without any initialization block, it
56
- # will be created at runtime later.
57
- rad.register :controller, scope: :request
58
-
59
- # Let's define some of our controllers, the PagesController, note - we
60
- # don't register it as component.
61
- class PagesController
62
- # We need access to :logger and :request, let's inject them
63
- inject logger: :logger, request: :request
64
-
65
- def index
66
- # Here we can use injected component
67
- logger.info "Application: processing #{request}"
68
- end
69
- end
70
-
71
- # Request is also dynamic, and it also can't be created beforehead.
72
- # We also registering it without initialization, it will be
73
- # created at runtime later.
74
- class Request
75
- attr_reader :url
76
- def initialize url; @url = url end
77
- def to_s; @url end
78
- end
79
- # Registering without initialization block.
80
- rad.register :request, scope: :request
81
-
82
- # We need to integrate our application with web server, for example with the Rack.
83
- # When the server receive web request, it calls the :call method of our RackAdapter
84
- class RackAdapter
85
- # Injecting components
86
- inject request: :request, controller: :controller
87
-
88
- def call env
89
- # We need to tell Micon that the :request scope is started, so it will know
90
- # that some dynamic components should be created during this scope and
91
- # destroyed at the end of it.
92
- rad.activate :request, {} do
93
- # Here we manually creating the Request component
94
- self.request = Request.new '/index'
95
-
96
- # The :router also can be injected via :inject,
97
- # but we can also use another way to access components,
98
- # every component also availiable as rad.<component_name>
99
- controller_class, method = rad.router.decode request
100
-
101
- # Let's create and call our controller
102
- self.controller = controller_class.new
103
- controller.send method
104
- end
105
- end
106
- end
107
-
108
- # Let's pretend that there's a Web Server and run our application,
109
- # You should see something like this in the console:
110
- # Application: processing /index
111
- RackAdapter.new.call({})
112
- end
113
-
114
- describe 'real-life' do
115
- class_loader_available = begin
116
- require 'class_loader'
117
- require 'class_loader/spec'
118
- true
119
- rescue LoadError
120
- false
121
- end
122
-
123
- if class_loader_available
124
- with_load_path "#{spec_dir}/lib"
125
- with_autoload_path "#{spec_dir}/lib"
126
-
127
- it "example" do
128
- require 'micon'
129
- require 'class_loader'
130
-
131
- # Here's our Web Framework, let's call it Rad
132
-
133
- # Let's define shortcut to access the IoC API (optional
134
- # but handy step). I don't know how You would like to call it,
135
- # so I leave this step to You.
136
- class ::Object
137
- def rad; MICON end
138
- end
139
-
140
- # Auto-discovering:
141
- #
142
- # All components (:logger, :router, :request, :controller) are
143
- # defined in spec/example_spec/lib/components folder.
144
- # All classes (PagesController, RackAdapter) are
145
- # located in spec/example_spec/lib folder.
146
- #
147
- # Note that there's no any "require 'xxx'" clause, all components and
148
- # classes are loaded and dependecies are resolved automatically.
149
-
150
- # Auto-configuring
151
- #
152
- # Remember our manual configuration of "logger.log_file_path" from
153
- # the previous example?
154
- # This time it will be configured automatically, take a look at
155
- # the spec/example_spec/lib/components/logger.yml file.
156
- #
157
- # Note, that there are also logger.production.yml, configs are smart
158
- # and are merged in the following order:
159
- # logger.yml <- logger.<env>.yml <- <runtime_path>/config/logger.yml
160
- # (If you define :environment and :runtime_path variables).
161
-
162
- # Let's pretend that there's a Web Server and run our application,
163
- # You should see something like this in the console:
164
- # Application: processing /index
165
- RackAdapter.new.call({})
166
- end
167
- else
168
- warn "The 'real-life example' requires 'class_loader' gem, please install it"
169
- end
170
- end
171
- end
@@ -1,8 +0,0 @@
1
- # The :controller component should be created and destroyed dynamically,
2
- # for each request, we specifying that component is dynamic
3
- # by declaring it's :scope.
4
- # And, we don't know beforehead what it actully will be, for different
5
- # request there can be different controllers,
6
- # so, here we just declaring it without any initialization block, it
7
- # will be created at runtime later.
8
- rad.register :controller, scope: :request
@@ -1 +0,0 @@
1
- log_file_path: /tmp/rad.production.log
@@ -1,8 +0,0 @@
1
- # the :logger is one per application, it's a static component (like singleton)
2
- class Logger
3
- register_as :logger
4
- attr_accessor :log_file_path
5
- def info msg
6
- puts "#{msg} (writen to #{log_file_path})" unless defined?(RSpec)
7
- end
8
- end
@@ -1 +0,0 @@
1
- log_file_path: /tmp/rad.log
@@ -1,2 +0,0 @@
1
- # Registering without initialization block.
2
- rad.register :request, scope: :request
@@ -1,12 +0,0 @@
1
- # The :router requires complex initialization, so we use
2
- # another form of component registration.
3
- class Router
4
- def initialize routes; @routes = routes end
5
- def decode request;
6
- class_name, method = @routes[request.url]
7
- return eval(class_name), method # returning actual class
8
- end
9
- end
10
- rad.register :router do
11
- Router.new '/index' => ['PagesController', :index]
12
- end
@@ -1,11 +0,0 @@
1
- # Let's define some of our controllers, the PagesController, note - we
2
- # don't register it as component.
3
- class PagesController
4
- # We need access to :logger and :request, let's inject them
5
- inject logger: :logger, request: :request
6
-
7
- def index
8
- # Here we can use injected component
9
- logger.info "Application: processing #{request}"
10
- end
11
- end
@@ -1,25 +0,0 @@
1
- # We need to integrate our application with web server, for example with the Rack.
2
- # When the server receive web request, it calls the :call method of our RackAdapter
3
- class RackAdapter
4
- # Injecting components
5
- inject request: :request, controller: :controller
6
-
7
- def call env
8
- # We need to tell Micon that the :request scope is started, so it will know
9
- # that some dynamic components should be created during this scope and
10
- # destroyed at the end of it.
11
- rad.activate :request, {} do
12
- # Here we manually creating the Request component
13
- self.request = Request.new '/index'
14
-
15
- # The :router also can be injected via :inject,
16
- # but we can also use another way to access components,
17
- # every component also availiable as rad.<component_name>
18
- controller_class, method = rad.router.decode request
19
-
20
- # Let's create and call our controller
21
- self.controller = controller_class.new
22
- controller.send method
23
- end
24
- end
25
- end
@@ -1,8 +0,0 @@
1
- # Request is also dynamic, and it also can't be created beforehead.
2
- # We also registering it without initialization, it will be
3
- # created at runtime later.
4
- class Request
5
- attr_reader :url
6
- def initialize url; @url = url end
7
- def to_s; @url end
8
- end