micon 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/readme.md +58 -146
  3. metadata +3 -3
data/Rakefile CHANGED
@@ -6,5 +6,5 @@ project(
6
6
  summary: "Silent killer of dependencies and configs",
7
7
 
8
8
  author: "Alexey Petrushin",
9
- homepage: "http://github.com/alexeypetrushin/micon"
9
+ homepage: "http://alexeypetrushin.github.com/micon"
10
10
  )
data/readme.md CHANGED
@@ -1,179 +1,91 @@
1
- # Micon - silent killer of dependencies and configs
2
-
3
- Micon allows You easilly and transparently eliminate dependencies and configs. Usually, when You are building complex system there are following tasks should be solved:
4
-
5
- - where the component's code is located
6
- - in what order should it be loaded
7
- - what configs does the component needs to be properly initialized
8
- - where those configs are stored
9
- - how to change configs in different environments
10
- - where are dependencies for component and how they should be initialized
11
- - how to replace some components with custom implementation
12
- - how to assembly parts of application for specs/tests
13
- - how to restore state after each spec/test (isolate it from each other)
14
- - how to control life-cycle of dynamically created components
15
- - connecting components to assemble an application
1
+ **Documentation:** http://alexeypetrushin.github.com/micon
2
+
3
+ Silent killer of dependencies and configs
4
+
5
+ Micon allows You easilly and transparently eliminate dependencies and configs. Usually, when You are building complex system following tasks should be solved:
6
+
7
+ - where the component's code is located.
8
+ - in what order should it be loaded.
9
+ - what configs does the component needs to be properly initialized.
10
+ - where those configs are stored.
11
+ - how to change configs in different environments.
12
+ - where are dependencies for component and how they should be initialized.
13
+ - how to replace some components with custom implementation.
14
+ - how to assembly parts of application for specs/tests.
15
+ - how to restore state after each spec/test (isolate it from each other).
16
+ - how to control life-cycle of dynamically created components.
17
+ - connecting components to assemble an application.
16
18
 
17
19
  *By component I mean any parts of code logically grouped together.*
18
20
 
19
21
  Micon **solves all these tasks automatically**, and has the following **price** - You has to:
20
22
 
21
- - use the *register(component_name, &initialization_block)* method for component initialization
22
- - use the *inject(component_name)* to whire components toghether
23
- - place component definitions to the "lib/components" folder
23
+ - use the `register(component_name, &initialization_block)` method for component initialization.
24
+ - use the `inject(component_name)` to whire components toghether.
25
+ - place component definitions in the `lib/components` folder.
24
26
 
25
- That's all the price, not a big one, compared to the value, eh?
26
- That all You need to know to use 95% of it, there are also 2-3 more specific methods, but they are needed very rarelly.
27
+ That's all the price, not a big one, compared to the value, eh? It's all You need to know about it to use 95% of it, there are also 2-3 more specific methods, but they are needed very rarelly.
27
28
 
28
29
  Techincally Micon is sort of Dependency Injector, but because of its simplicity and invisibility it looks like an alien compared to its complex and bloated IoC / DI cousins.
29
30
 
30
- ## Basic example
31
+ Install Micon with Rubygems:
32
+
33
+ gem install micon
34
+
35
+ Once installed, You can proceed with the examples below.
36
+
37
+ The project hosted on [GitHub][project]. You can report bugs and discuss features on the [issues page][issues].
38
+
39
+ ### Basic example
31
40
 
32
41
  ``` ruby
33
42
  require 'micon'
34
- require 'logger' # standard ruby logger
43
+ require 'logger'
35
44
 
45
+ # Registering `:logger` component.
36
46
  micon.register(:logger){Logger.new STDOUT}
37
47
 
38
48
  class Application
49
+ # Whiring the `:logger` component and application together.
39
50
  inject logger: :logger
40
-
51
+
52
+ # Now You can use `:logger` as if it's an usual class member.
41
53
  def run
42
54
  logger.info 'running ...'
43
55
  end
44
56
  end
45
57
 
58
+ # Running our application, type:
59
+ #
60
+ # ruby docs/basics.rb
61
+ #
62
+ # And You should see in the console something like this:
63
+ #
64
+ # [2011-08-16T19:09:05.921238 #24944] INFO -- : running ...
65
+ #
46
66
  Application.new.run
47
- # You should see something like this in the console:
48
- # [2011-08-16T19:09:05.921238 #24944] INFO -- : running ...
49
- ```
50
-
51
- Code in examples/basics.rb
52
-
53
- ## Advanced example: let's build Web Framework
54
-
55
- This example is more complicated and requires about 3-7 minutes.
56
-
57
- Let's pretend that we are building an Ultimate Framework, the RoR Killer. There will be lot's of modules and dependencies, let's see how Micon can eliminate them. There will be only two components: router, request.
58
- Let's build it in two steps, at the first we'll build it as usual, and at the second refactor it using Micon.
59
-
60
- First step, building our framework **without Micon**.
61
-
62
- ``` ruby
63
- # setting load paths
64
- dir = File.dirname __FILE__
65
- $LOAD_PATH << "#{dir}/lib"
66
-
67
-
68
- # Assembling Ultima Framework
69
- module Ultima
70
- class << self
71
- attr_accessor :router, :config
72
-
73
- def run url
74
- request = Request.new url
75
-
76
- controller_class, method = router.decode url
77
-
78
- controller = controller_class.new
79
- controller.request = request
80
- controller.send method
81
- end
82
- end
83
- end
84
-
85
- # reading application config
86
- require 'yaml'
87
- Ultima.config = YAML.load_file "#{dir}/config/config.yml"
88
-
89
- # initializing router
90
- require 'router'
91
- router = Router.new
92
- router.url_root = Ultima.config['url_root']
93
- Ultima.router = router
94
-
95
- # loading request and controller
96
- require 'request'
97
- require 'controller'
98
-
99
-
100
- # Assemblilng Application
101
- require 'pages_controller'
102
-
103
- Ultima.router.add_route '/index', PagesController, :index
104
-
105
-
106
- # Let's run it
107
- Ultima.run '/index'
108
- # You should see something like this in the console:
109
- # PagesController: displaying the :index page.
110
67
  ```
111
68
 
112
- Code in examples/ultima1/run.rb
113
-
114
- Below are the same example but refactored **with using Micon**. As You can see there's no any assembling or configuration code, because all the components are auto-discovered, auto-loaded and auto-configured.
115
-
116
- ``` ruby
117
- # Assembling Ultima Framework
118
- # All components: router, request, controller will be automatically loaded & configured.
119
- class Ultima
120
- inject router: :router
121
-
122
- def run url
123
- # we need to tell Micon about the :request scope, so the Request will be
124
- # created & destroyed during this scope automatically.
125
- micon.activate :request, {} do
126
- request = Request.new url
127
-
128
- controller_class, method = router.decode url
129
-
130
- controller = controller_class.new
131
- # no need to explicitly set request, it will be automatically injected
132
- controller.send method
133
- end
134
- end
135
- end
136
- micon.register(:ultima){Ultima.new}
137
-
138
- # No need for 'requre', all classes will be discowered & laoded automatically
69
+ ### Advanced example
139
70
 
140
- # No need for config, Micon will automatically discower config/router.yml
71
+ It's hard to see advantages of Dependency Injection using trivial example, so this example is
72
+ more complicated.
141
73
 
142
- # No need for manual router configuring, router.yml config will be applied automatically
74
+ Let's pretend that we are building the Ultimate Web Framework, RoR Killer. There will be lot's
75
+ of modules and dependencies, let's see how Micon can eliminate them.
143
76
 
77
+ We build our framework in two steps:
144
78
 
145
- # Assemblilng Application
146
- # Controller will be loaded automatically
147
- micon.router.add_route '/index', PagesController, :index
79
+ - the first version [ultima1.rb][ultima1] build **without Micon**.
80
+ - second version [ultima2.rb][ultima2] refactored **using Micon**.
148
81
 
82
+ You can compare these two examples and see advantages of using Dependency Injection.
149
83
 
150
- # Let's run it
151
- micon.ultima.run '/index'
152
- # You should see something like this in the console:
153
- # PagesController: displaying the :index page.
154
- ```
155
-
156
- Code in examples/ultima2/run.rb
157
-
158
- ## More samples
159
-
160
- If You are interested in more samples, please take a look at the [actual components][rad_core_components] used in the Rad Core Web Framework.
161
-
162
- ## Note
163
-
164
- Current wersion isn't thread-safe, and I did it intentially. Actually, the first version was implemented as thread-safe, but because there's no actual multithreading in Ruby, the only thing it does - adds complexity and performance losses, so I removed it.
165
- But if you really need it for some reason - it can be easily done.
166
-
167
- ## Installation
168
-
169
- ``` bash
170
- gem install micon
171
- ```
172
-
173
- ## License
84
+ If You are interested in more samples, please take a look at the [Rad SBS][rad_sbs] it's build using Micon.
174
85
 
175
- Copyright (c) Alexey Petrushin http://petrush.in, released under the MIT license.
86
+ [ultima1]: http://alexeypetrushin.github.com/micon/ultima1.html
87
+ [ultima2]: http://alexeypetrushin.github.com/micon/ultima3.html
176
88
 
177
- [ioc]: http://en.wikipedia.org/wiki/Inversion_of_control
178
- [rad_core]: https://github.com/alexeypetrushin/rad_core
179
- [rad_core_components]: https://github.com/alexeypetrushin/rad_core/tree/master/lib/components
89
+ [project]: https://github.com/alexeypetrushin/micon
90
+ [issues]: https://github.com/alexeypetrushin/micon/issues
91
+ [rad_sbs]: http://sbs.4ire.net
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.21
4
+ version: 0.1.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-22 00:00:00.000000000Z
12
+ date: 2011-09-24 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -47,7 +47,7 @@ files:
47
47
  - spec/nested_custom_scope_spec.rb
48
48
  - spec/spec_helper.rb
49
49
  - spec/static_scope_spec.rb
50
- homepage: http://github.com/alexeypetrushin/micon
50
+ homepage: http://alexeypetrushin.github.com/micon
51
51
  licenses: []
52
52
  post_install_message:
53
53
  rdoc_options: []