micon 0.1.26 → 0.1.27
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.
- data/Rakefile +2 -3
- data/lib/micon/config.rb +2 -2
- data/lib/micon/core.rb +15 -7
- data/lib/micon/support.rb +12 -8
- data/readme.md +1 -1
- data/spec/helpers_spec.rb +40 -0
- data/spec/miscellaneous_spec.rb +5 -5
- metadata +3 -3
- data/spec/managed_spec.rb +0 -51
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'rake_ext'
|
2
2
|
|
3
|
-
project
|
3
|
+
project \
|
4
4
|
name: "micon",
|
5
5
|
gem: true,
|
6
6
|
summary: "Silent killer of dependencies and configs",
|
7
7
|
|
8
8
|
author: "Alexey Petrushin",
|
9
|
-
homepage: "http://alexeypetrushin.github.com/micon"
|
10
|
-
)
|
9
|
+
homepage: "http://alexeypetrushin.github.com/micon"
|
data/lib/micon/config.rb
CHANGED
@@ -7,7 +7,7 @@ class Micon::Config
|
|
7
7
|
def load
|
8
8
|
files = []
|
9
9
|
files.push *config_paths.collect{|path| find_file(path, $LOAD_PATH)}
|
10
|
-
files.push *runtime_config_paths.collect{|path| find_file(path, [micon.runtime_path])}
|
10
|
+
files.push *runtime_config_paths.collect{|path| find_file(path, [micon.runtime_path])}
|
11
11
|
|
12
12
|
config = {}
|
13
13
|
files.compact.each do |f|
|
@@ -41,7 +41,7 @@ class Micon::Config
|
|
41
41
|
|
42
42
|
def find_file path, directories
|
43
43
|
files = directories.collect{|dir| "#{dir}#{path}"}.select{|f| File.exist? f}
|
44
|
-
raise
|
44
|
+
raise %(multiple configs for :#{name} component ('#{files.join("', '")}')) if files.size > 1
|
45
45
|
files.first
|
46
46
|
end
|
47
47
|
end
|
data/lib/micon/core.rb
CHANGED
@@ -5,7 +5,7 @@ class Micon::Core
|
|
5
5
|
|
6
6
|
attr_accessor :custom_scopes
|
7
7
|
|
8
|
-
def activate sname, container, &block
|
8
|
+
def activate sname, container = {}, &block
|
9
9
|
raise_without_self "Only custom scopes can be activated!" if sname == :application or sname == :instance
|
10
10
|
raise "container should have type of Hash but has #{container.class.name}" unless container.is_a? Hash
|
11
11
|
|
@@ -237,7 +237,7 @@ class Micon::Core
|
|
237
237
|
end
|
238
238
|
|
239
239
|
# `runtime_path` is used to search for component configurations, it may be `app/runtime` for example..
|
240
|
-
def runtime_path; @runtime_path
|
240
|
+
def runtime_path; @runtime_path ||= File.expand_path('.') end
|
241
241
|
def runtime_path= runtime_path
|
242
242
|
runtime_path, force = runtime_path
|
243
243
|
raise "some components has been already initialized before You set :runtime_path!" unless empty? or force
|
@@ -248,7 +248,7 @@ class Micon::Core
|
|
248
248
|
# `mode` used to search for component configuration, examples:
|
249
249
|
# - `app/runtime/logger.production.yml`
|
250
250
|
# - `app/runtime/production/logger.yml`
|
251
|
-
def mode; @mode
|
251
|
+
def mode; @mode ||= :development end
|
252
252
|
def mode= mode
|
253
253
|
mode, force = mode
|
254
254
|
raise "some components has been already initialized before You set :mode!" unless empty? or force
|
@@ -256,6 +256,18 @@ class Micon::Core
|
|
256
256
|
end
|
257
257
|
def mode?; !!@mode end
|
258
258
|
|
259
|
+
def development?; mode == :development end
|
260
|
+
def production?; mode == :production end
|
261
|
+
def test?; mode == :test end
|
262
|
+
|
263
|
+
def development █ block.call if development? end
|
264
|
+
def production █ block.call if production? end
|
265
|
+
def test █ block.call if test? end
|
266
|
+
|
267
|
+
def raise_without_self message
|
268
|
+
raise RuntimeError, message, caller.select{|path| path !~ /\/lib\/micon\//}
|
269
|
+
end
|
270
|
+
|
259
271
|
protected
|
260
272
|
def autoload_component_definition key, bang = true
|
261
273
|
begin
|
@@ -359,10 +371,6 @@ class Micon::Core
|
|
359
371
|
end
|
360
372
|
end
|
361
373
|
|
362
|
-
def raise_without_self message
|
363
|
-
raise RuntimeError, message, caller.select{|path| path !~ /\/lib\/micon\//}
|
364
|
-
end
|
365
|
-
|
366
374
|
# Generates helper methods, so you can use `micon.logger` instead of `micon[:logger]`
|
367
375
|
def method_missing m, *args, &block
|
368
376
|
super if args.size > 1 or block
|
data/lib/micon/support.rb
CHANGED
@@ -8,15 +8,19 @@ class Class
|
|
8
8
|
end
|
9
9
|
|
10
10
|
Module.class_eval do
|
11
|
-
# Usage: `inject logger: :logger`.
|
12
|
-
def inject attributes
|
13
|
-
|
14
|
-
attributes.each
|
15
|
-
::MICON.raise_without_self "Attribute name should be a Symbol!" unless name.is_a? Symbol
|
11
|
+
# Usage: `inject :logger` or `inject logger: :logger`.
|
12
|
+
def inject *attributes
|
13
|
+
options = attributes.last.is_a?(Hash) ? attributes.pop : {}
|
14
|
+
attributes.each{|name| options[name] = name}
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
options.each do |attr_name, component_name|
|
17
|
+
unless attr_name.is_a? Symbol
|
18
|
+
::MICON.raise_without_self "attribute name #{attr_name} should be a Symbol!"
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method(attr_name){::MICON[component_name]}
|
22
|
+
define_method("#{attr_name}="){|component| ::MICON[component_name] = component}
|
23
|
+
define_method("#{attr_name}?"){::MICON.include? component_name}
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
data/readme.md
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Helpers" do
|
4
|
+
before{self.micon = Micon::Core.new}
|
5
|
+
after{remove_constants :Tmp}
|
6
|
+
|
7
|
+
it "register_as" do
|
8
|
+
class Tmp
|
9
|
+
micon.should_receive :register do |name, &initializer|
|
10
|
+
name.should == :an_object
|
11
|
+
initializer.call.class.should == Tmp
|
12
|
+
end
|
13
|
+
|
14
|
+
register_as :an_object
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "inject" do
|
19
|
+
class Tmp
|
20
|
+
inject :an_object
|
21
|
+
end
|
22
|
+
tmp = Tmp.new
|
23
|
+
|
24
|
+
micon.should_receive(:[]).with :an_object
|
25
|
+
tmp.an_object
|
26
|
+
|
27
|
+
micon.should_receive(:[]=).with :an_object, 'An Object'
|
28
|
+
tmp.an_object = 'An Object'
|
29
|
+
|
30
|
+
micon.should_receive(:include?).with :an_object
|
31
|
+
tmp.an_object?
|
32
|
+
|
33
|
+
# Another form.
|
34
|
+
class Tmp
|
35
|
+
inject other: :other_object
|
36
|
+
end
|
37
|
+
micon.should_receive(:[]).with :other_object
|
38
|
+
tmp.other
|
39
|
+
end
|
40
|
+
end
|
data/spec/miscellaneous_spec.rb
CHANGED
@@ -54,19 +54,19 @@ describe "Miscellaneous" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should allow circullar dependencies in :after callback" do
|
57
|
-
micon.register :
|
57
|
+
micon.register :an_environment do
|
58
58
|
'environment'
|
59
59
|
end
|
60
60
|
|
61
|
-
micon.register :
|
61
|
+
micon.register :a_router, depends_on: :an_environment do
|
62
62
|
'router'
|
63
63
|
end
|
64
64
|
|
65
|
-
micon.after :
|
66
|
-
micon[:
|
65
|
+
micon.after :an_environment do
|
66
|
+
micon[:a_router]
|
67
67
|
end
|
68
68
|
|
69
|
-
micon[:
|
69
|
+
micon[:a_router]
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
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.
|
4
|
+
version: 0.1.27
|
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-10-
|
12
|
+
date: 2011-10-30 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -36,8 +36,8 @@ files:
|
|
36
36
|
- spec/constants_spec/get_constant_component/lib/components/TheController.rb
|
37
37
|
- spec/constants_spec.rb
|
38
38
|
- spec/custom_scope_spec.rb
|
39
|
+
- spec/helpers_spec.rb
|
39
40
|
- spec/initialization_spec.rb
|
40
|
-
- spec/managed_spec.rb
|
41
41
|
- spec/miscellaneous_spec/autoload/lib/components/some_value.rb
|
42
42
|
- spec/miscellaneous_spec/autoload/lib/components/TheRad/TheView.rb
|
43
43
|
- spec/miscellaneous_spec/autoload/lib/components/TheRouter.rb
|
data/spec/managed_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Managed" do
|
4
|
-
before :all do
|
5
|
-
self.micon = Micon::Core.new
|
6
|
-
|
7
|
-
class ManagedObject
|
8
|
-
register_as :managed_object
|
9
|
-
inject object: :object_key
|
10
|
-
|
11
|
-
class << self
|
12
|
-
inject object: :object_key
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
before do
|
18
|
-
micon.clear
|
19
|
-
end
|
20
|
-
|
21
|
-
it "scope" do
|
22
|
-
scope = micon.metadata[:managed_object]
|
23
|
-
initializer, dependencies = micon.metadata.initializers[:managed_object]
|
24
|
-
scope.should == :application
|
25
|
-
initializer.call.should be_a(ManagedObject)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "injection" do
|
29
|
-
the_object = "The Object"
|
30
|
-
micon.register(:object_key){the_object}
|
31
|
-
|
32
|
-
ManagedObject.object.should == the_object
|
33
|
-
o = ManagedObject.new
|
34
|
-
o.object.should == the_object
|
35
|
-
end
|
36
|
-
|
37
|
-
it "outjection" do
|
38
|
-
the_object = "The Object"
|
39
|
-
micon.register(:object_key)
|
40
|
-
|
41
|
-
-> {ManagedObject.object}.should raise_error(/no initializer/)
|
42
|
-
ManagedObject.object = the_object
|
43
|
-
ManagedObject.object.should == the_object
|
44
|
-
end
|
45
|
-
|
46
|
-
it "empty?" do
|
47
|
-
micon.should be_empty
|
48
|
-
micon[:managed_object]
|
49
|
-
micon.should_not be_empty
|
50
|
-
end
|
51
|
-
end
|