micon 0.1.24 → 0.1.25

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.
@@ -1,22 +1,13 @@
1
- require 'yaml'
1
+ require 'micon/support'
2
2
 
3
3
  module Micon
4
+ autoload :Metadata, 'micon/metadata'
5
+ autoload :Config, 'micon/config'
6
+ autoload :Core, 'micon/core'
7
+ autoload :Metadata, 'micon/metadata'
4
8
  end
5
9
 
6
- %w{
7
- support
8
-
9
- metadata
10
- config
11
- core
12
- helper
13
-
14
- module
15
- class
16
- }.each{|f| require "micon/#{f}"}
17
-
18
10
  # Initializing Micon.
19
- Micon::Core.send :include, Micon::Helper
20
11
  micon = Micon::Core.new
21
12
  micon.initialize!
22
13
 
@@ -1,8 +0,0 @@
1
- class Class
2
- # Usage:
3
- # register_as :session, scope: :request
4
- # register_as :loggger
5
- def register_as *args
6
- ::MICON.register(*args){self.new}
7
- end
8
- end
@@ -11,6 +11,7 @@ class Micon::Config
11
11
 
12
12
  config = {}
13
13
  files.compact.each do |f|
14
+ require 'yaml'
14
15
  c = YAML.load_file(f)
15
16
  next unless c
16
17
  raise "component config must be a Hash (#{f})!" unless c.is_a? Hash
@@ -153,7 +153,6 @@ class Micon::Core
153
153
 
154
154
  def register key, options = {}, &initializer
155
155
  raise "key should not be nil or false value!" unless key
156
- options = options.symbolize_keys
157
156
 
158
157
  sname = options.delete(:scope) || :application
159
158
  dependencies = Array(options.delete(:require) || options.delete(:depends_on))
@@ -359,4 +358,30 @@ class Micon::Core
359
358
  ""
360
359
  end
361
360
  end
361
+
362
+ def raise_without_self message
363
+ raise RuntimeError, message, caller.select{|path| path !~ /\/lib\/micon\//}
364
+ end
365
+
366
+ # Generates helper methods, so you can use `micon.logger` instead of `micon[:logger]`
367
+ def method_missing m, *args, &block
368
+ super if args.size > 1 or block
369
+
370
+ key = m.to_s.sub(/[?=]$/, '').to_sym
371
+ self.class.class_eval do
372
+ define_method key do
373
+ self[key]
374
+ end
375
+
376
+ define_method "#{key}=" do |value|
377
+ self[key] = value
378
+ end
379
+
380
+ define_method "#{key}?" do
381
+ include? key
382
+ end
383
+ end
384
+
385
+ send m, *args
386
+ end
362
387
  end
@@ -1,16 +1,22 @@
1
- class Micon::Core
2
- protected
3
- def raise_without_self message
4
- raise RuntimeError, message, caller.select{|path| path !~ /\/lib\/micon\//}
5
- end
1
+ class Class
2
+ # Usage:
3
+ # register_as :session, scope: :request
4
+ # register_as :loggger
5
+ def register_as *args
6
+ ::MICON.register(*args){self.new}
7
+ end
6
8
  end
7
9
 
8
- class Hash
9
- unless method_defined? :symbolize_keys
10
- def symbolize_keys
11
- r = {}
12
- each{|k, v| r[k.to_sym] = v}
13
- r
10
+ Module.class_eval do
11
+ # Usage: `inject logger: :logger`.
12
+ def inject attributes
13
+ ::MICON.raise_without_self "Invalid argument!" unless attributes.is_a? Hash
14
+ attributes.each do |name, specificator|
15
+ ::MICON.raise_without_self "Attribute name should be a Symbol!" unless name.is_a? Symbol
16
+
17
+ define_method(name){::MICON[specificator]}
18
+ define_method("#{name}="){|value| ::MICON[specificator] = value}
19
+ define_method("#{name}?"){::MICON.include? specificator}
14
20
  end
15
21
  end
16
22
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'ostruct'
2
3
 
3
4
  describe "Configuration" do
4
5
  before{self.micon = Micon::Core.new}
@@ -1,9 +1,6 @@
1
- require 'rspec_ext'
2
- require 'ostruct'
3
-
4
1
  require "micon"
5
2
 
6
- Micon::Core.send :include, Micon::Helper
3
+ require 'rspec_ext'
7
4
 
8
5
  def micon; $micon end
9
6
  def micon= value
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.24
4
+ version: 0.1.25
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-24 00:00:00.000000000Z
12
+ date: 2011-10-27 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -22,9 +22,7 @@ files:
22
22
  - lib/micon/class.rb
23
23
  - lib/micon/config.rb
24
24
  - lib/micon/core.rb
25
- - lib/micon/helper.rb
26
25
  - lib/micon/metadata.rb
27
- - lib/micon/module.rb
28
26
  - lib/micon/spec.rb
29
27
  - lib/micon/support.rb
30
28
  - lib/micon.rb
@@ -1,23 +0,0 @@
1
- # Generates helper methods for Micon, so you can use micon.logger instead of micon[:logger]
2
- module Micon::Helper
3
- def method_missing m, *args, &block
4
- super if args.size > 1 or block
5
-
6
- key = m.to_s.sub(/[?=]$/, '').to_sym
7
- self.class.class_eval do
8
- define_method key do
9
- self[key]
10
- end
11
-
12
- define_method "#{key}=" do |value|
13
- self[key] = value
14
- end
15
-
16
- define_method "#{key}?" do
17
- include? key
18
- end
19
- end
20
-
21
- send m, *args
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- Module.class_eval do
2
- # Usage: `inject logger: :logger`.
3
- def inject attributes
4
- ::MICON.raise_without_self "Invalid argument!" unless attributes.is_a? Hash
5
- attributes.each do |name, specificator|
6
- ::MICON.raise_without_self "Attribute name should be a Symbol!" unless name.is_a? Symbol
7
-
8
- define_method(name){::MICON[specificator]}
9
- define_method("#{name}="){|value| ::MICON[specificator] = value}
10
- define_method("#{name}?"){::MICON.include? specificator}
11
- end
12
- end
13
- end