Sutto-perennial 0.2.3.1 → 0.2.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/perennial.rb CHANGED
@@ -9,11 +9,12 @@ require 'perennial/exceptions'
9
9
 
10
10
  module Perennial
11
11
 
12
- VERSION = "0.2.3.1"
12
+ VERSION = "0.2.3.2"
13
13
 
14
14
  has_libary :dispatchable, :hookable, :loader, :logger,
15
15
  :loggable, :manifest, :settings, :argument_parser,
16
- :option_parser, :application, :generator, :daemon
16
+ :option_parser, :application, :generator, :daemon,
17
+ :delegateable
17
18
 
18
19
  def self.included(parent)
19
20
  parent.extend(Manifest::Mixin)
@@ -1,4 +1,7 @@
1
1
  # Require each individial core extension
2
2
  require 'perennial/core_ext/attribute_accessors'
3
3
  require 'perennial/core_ext/blank'
4
- require 'perennial/core_ext/misc'
4
+ require 'perennial/core_ext/misc'
5
+ require 'perennial/core_ext/hash_key_conversions'
6
+ require 'perennial/core_ext/inflections'
7
+ require 'perennial/core_ext/proxy'
@@ -0,0 +1,26 @@
1
+ class Hash
2
+ def symbolize_keys
3
+ hash = self.dup
4
+ hash.symbolize_keys!
5
+ return hash
6
+ end
7
+
8
+ def symbolize_keys!
9
+ hash = {}
10
+ self.each_pair { |k,v| hash[k.to_sym] = v }
11
+ replace hash
12
+ end
13
+
14
+ def stringify_keys!
15
+ hash = {}
16
+ self.each_pair { |k, v| hash[k.to_s] = v }
17
+ replace hash
18
+ end
19
+
20
+ def stringify_keys
21
+ hash = self.dup
22
+ hash.stringify_keys!
23
+ return hash
24
+ end
25
+
26
+ end
@@ -0,0 +1,33 @@
1
+ module Perennial
2
+ class Inflector
3
+ class << self
4
+
5
+ def underscore(camel_cased_word)
6
+ camel_cased_word.to_s.gsub(/::/, '/').
7
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
8
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
9
+ tr("-", "_").
10
+ downcase
11
+ end
12
+
13
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
14
+ if first_letter_in_uppercase
15
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
16
+ else
17
+ lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
25
+ class String
26
+ def underscore
27
+ Perennial::Inflector.underscore(self)
28
+ end
29
+
30
+ def camelize(capitalize_first_letter = true)
31
+ Perennial::Inflector.camelize(self, capitalize_first_letter)
32
+ end
33
+ end
@@ -3,30 +3,14 @@ class Object
3
3
  def metaclass
4
4
  class << self; self; end
5
5
  end
6
+
7
+ def meta_def(name, &blk)
8
+ metaclass.define_method(name, &blk)
9
+ end
6
10
 
7
11
  end
8
12
 
9
- class Inflector
10
- class << self
11
13
 
12
- def underscore(camel_cased_word)
13
- camel_cased_word.to_s.gsub(/::/, '/').
14
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
15
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
16
- tr("-", "_").
17
- downcase
18
- end
19
-
20
- def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
21
- if first_letter_in_uppercase
22
- lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
23
- else
24
- lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
25
- end
26
- end
27
-
28
- end
29
- end
30
14
 
31
15
  module Kernel
32
16
 
@@ -53,14 +37,6 @@ class String
53
37
  File.join(self, *args)
54
38
  end
55
39
 
56
- def underscore
57
- Inflector.underscore(self)
58
- end
59
-
60
- def camelize(capitalize_first_letter = true)
61
- Inflector.camelize(self, capitalize_first_letter)
62
- end
63
-
64
40
  def to_pathname
65
41
  Pathname.new(self)
66
42
  end
@@ -72,33 +48,6 @@ class Array
72
48
  end
73
49
  end
74
50
 
75
- class Hash
76
- def symbolize_keys
77
- hash = self.dup
78
- hash.symbolize_keys!
79
- return hash
80
- end
81
-
82
- def symbolize_keys!
83
- hash = {}
84
- self.each_pair { |k,v| hash[k.to_sym] = v }
85
- replace hash
86
- end
87
-
88
- def stringify_keys!
89
- hash = {}
90
- self.each_pair { |k, v| hash[k.to_s] = v }
91
- replace hash
92
- end
93
-
94
- def stringify_keys
95
- hash = self.dup
96
- hash.stringify_keys!
97
- return hash
98
- end
99
-
100
- end
101
-
102
51
  class Module
103
52
 
104
53
  def has_libary(*items)
@@ -0,0 +1,16 @@
1
+ module Perennial
2
+ # a super simple proxy class.
3
+ class Proxy
4
+
5
+ instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/ }
6
+
7
+ attr_accessor :__proxy_target__
8
+
9
+ protected
10
+
11
+ def method_missing(m, *args, &blk)
12
+ __proxy_target__.send(m, *args, &blk)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ module Perennial
2
+ # Objective-C / Cocoa style 'delegates'.
3
+ # Essentially proxies which dispatch only
4
+ # when an object responds to the method.
5
+ class DelegateProxy < Proxy
6
+
7
+ def initialize(t)
8
+ @__proxy_target__ = t
9
+ end
10
+
11
+ def respond_to?(method, inc_super = false)
12
+ true
13
+ end
14
+
15
+ protected
16
+
17
+ def method_missing(method, *args, &blk)
18
+ @__proxy_target__.send(method, *args, &blk) if @__proxy_target__.respond_to?(method)
19
+ end
20
+
21
+ end
22
+
23
+ module Delegateable
24
+
25
+ def self.included(parent)
26
+ parent.send(:include, InstanceMethods)
27
+ end
28
+
29
+ module InstanceMethods
30
+
31
+ def delegate=(value)
32
+ @delegate = DelegateProxy.new(value)
33
+ end
34
+
35
+ alias delegate_to delegate=
36
+
37
+ def delegate
38
+ @delegate ||= DelegateProxy.new(nil)
39
+ end
40
+
41
+ def real_delegate
42
+ @delegate && @delegate.__proxy_target__
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -5,8 +5,9 @@ module Perennial
5
5
 
6
6
  cattr_accessor :logger, :log_name
7
7
 
8
- @@log_name = "perennial.log"
9
- @@setup = false
8
+ @@log_name = "perennial.log"
9
+ @@setup = false
10
+ @@default_logger_path = nil
10
11
 
11
12
  class << self
12
13
 
@@ -26,7 +27,7 @@ module Perennial
26
27
  end
27
28
 
28
29
  def default_logger_path
29
- @@default_logger_path ||= (Settings.root / "log" / @@log_name.to_str)
30
+ @@default_logger_path || (Settings.root / "log" / @@log_name.to_str)
30
31
  end
31
32
 
32
33
  def setup!
@@ -5,9 +5,11 @@ module Perennial
5
5
 
6
6
  cattr_accessor :configuration, :log_level, :verbose, :daemon
7
7
 
8
- @@verbose = false
9
- @@log_level = :info
10
- @@daemon = false
8
+ @@verbose = false
9
+ @@log_level = :info
10
+ @@daemon = false
11
+ @@default_settings_path = nil
12
+ @@lookup_key_path = ["default"]
11
13
 
12
14
  class << self
13
15
 
@@ -40,7 +42,7 @@ module Perennial
40
42
  end
41
43
 
42
44
  def default_settings_path
43
- @@default_settings_path ||= (root / "config" / "settings.yml")
45
+ @@default_settings_path || (root / "config" / "settings.yml")
44
46
  end
45
47
 
46
48
  def default_settings_path=(value)
@@ -49,7 +51,7 @@ module Perennial
49
51
  end
50
52
 
51
53
  def lookup_key_path
52
- @@lookup_key_path ||= ["default"]
54
+ @@lookup_key_path ||= []
53
55
  end
54
56
 
55
57
  def lookup_key_path=(value)
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class DelegateableTest < Test::Unit::TestCase
4
+
5
+ context 'basic delegates' do
6
+
7
+ setup do
8
+ @klass = test_class_for(Perennial::Delegateable)
9
+ @delegateable = @klass.new
10
+ end
11
+
12
+ should 'define a delegate= method' do
13
+ assert @delegateable.respond_to?(:delegate=)
14
+ end
15
+
16
+ should 'define a delegate_to method' do
17
+ assert @delegateable.respond_to?(:delegate_to)
18
+ end
19
+
20
+ should 'let you get the delegate proxy' do
21
+ @delegateable.delegate_to :awesome
22
+ assert proxy = @delegateable.delegate
23
+ assert_nothing_raised { proxy.awesomesauce }
24
+ assert_nothing_raised { proxy.ninja_party }
25
+ assert_equal "awesome", proxy.to_s
26
+ end
27
+
28
+ should 'let you get the real target of the delegate' do
29
+ @delegateable.delegate_to :awesome
30
+ assert real = @delegateable.real_delegate
31
+ assert_raises(NoMethodError) { proxy.awesomesauce }
32
+ assert_raises(NoMethodError) { proxy.ninja_party }
33
+ assert_equal "awesome", real.to_s
34
+ end
35
+
36
+ end
37
+
38
+ end
data/test/logger_test.rb CHANGED
@@ -30,6 +30,8 @@ class LoggerTest < Test::Unit::TestCase
30
30
  assert Perennial::Logger.respond_to?(:log_exception)
31
31
  assert Perennial::Logger.logger.respond_to?(:log_exception)
32
32
  end
33
+
34
+ should 'let you configure a dir that logs are loaded from'
33
35
 
34
36
  end
35
37
 
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class ProxyTest < Test::Unit::TestCase
4
+
5
+ context 'basic proxies' do
6
+
7
+ setup do
8
+ @proxy = Perennial::Proxy.new
9
+ @proxy.__proxy_target__ = :awesome
10
+ end
11
+ should 'pass through the correct class' do
12
+ assert_equal Symbol, @proxy.class
13
+ assert_kind_of Symbol, @proxy
14
+ end
15
+
16
+ should 'not interfere with equals' do
17
+ assert @proxy == :awesome
18
+ end
19
+
20
+ should 'pass through to_s' do
21
+ assert_equal "awesome", @proxy.to_s
22
+ end
23
+
24
+ should 'let you send to an object' do
25
+ assert_equal "awesome", @proxy.send(:to_s)
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -94,6 +94,10 @@ class SettingsTest < Test::Unit::TestCase
94
94
  end
95
95
  end
96
96
 
97
+ should 'let you configure the lookup key path'
98
+
99
+ should 'let you configure the file settings are loaded from'
100
+
97
101
  end
98
102
 
99
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Sutto-perennial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.1
4
+ version: 0.2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darcy Laycock
@@ -38,9 +38,13 @@ files:
38
38
  - lib/perennial/core_ext
39
39
  - lib/perennial/core_ext/attribute_accessors.rb
40
40
  - lib/perennial/core_ext/blank.rb
41
+ - lib/perennial/core_ext/hash_key_conversions.rb
42
+ - lib/perennial/core_ext/inflections.rb
41
43
  - lib/perennial/core_ext/misc.rb
44
+ - lib/perennial/core_ext/proxy.rb
42
45
  - lib/perennial/core_ext.rb
43
46
  - lib/perennial/daemon.rb
47
+ - lib/perennial/delegateable.rb
44
48
  - lib/perennial/dispatchable.rb
45
49
  - lib/perennial/exceptions.rb
46
50
  - lib/perennial/generator.rb
@@ -52,11 +56,13 @@ files:
52
56
  - lib/perennial/option_parser.rb
53
57
  - lib/perennial/settings.rb
54
58
  - lib/perennial.rb
59
+ - test/delegateable_test.rb
55
60
  - test/dispatchable_test.rb
56
61
  - test/hookable_test.rb
57
62
  - test/loader_test.rb
58
63
  - test/loggable_test.rb
59
64
  - test/logger_test.rb
65
+ - test/proxy_test.rb
60
66
  - test/settings_test.rb
61
67
  - test/test_helper.rb
62
68
  - templates/application.erb
@@ -67,7 +73,6 @@ files:
67
73
  - templates/test_helper.erb
68
74
  has_rdoc: false
69
75
  homepage: http://sutto.net/
70
- licenses:
71
76
  post_install_message:
72
77
  rdoc_options: []
73
78
 
@@ -88,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
93
  requirements: []
89
94
 
90
95
  rubyforge_project:
91
- rubygems_version: 1.3.5
96
+ rubygems_version: 1.2.0
92
97
  signing_key:
93
98
  specification_version: 3
94
99
  summary: A simple (generally event-oriented) application library for Ruby