cunfug 0.0.1 → 0.0.2

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,28 +1,34 @@
1
1
  module Cunfug
2
2
  module Configuration
3
- require 'active_support'
3
+ require 'active_support/concern'
4
+ require 'active_support/core_ext'
4
5
  require 'ostruct'
5
6
 
6
7
  extend ActiveSupport::Concern
7
8
 
8
9
  included do
9
- #
10
+ @config = OpenStruct.new
10
11
  end
11
12
 
12
13
  module ClassMethods
13
- def method_missing(method_name, *args)
14
- @config ||= OpenStruct.new
15
-
16
- if method_name.to_s.match(/^.+=$/)
17
- @config.send(method_name, args.first)
14
+ def method_missing(method_name_sym, *args, &block)
15
+ if method_name_sym.to_s.match(/^.+=$/)
16
+ config.send(method_name_sym, args.first)
18
17
  else
19
- @config.send(method_name)
18
+ if method_name_sym.to_s.match(/_class$/)
19
+ return config.send(:"#{method_name_sym}_name").constantize
20
+ end
21
+ config.send(method_name_sym) rescue nil
20
22
  end
21
23
  end
22
24
 
23
25
  def configure
24
26
  yield self
25
27
  end
28
+
29
+ def config
30
+ @config
31
+ end
26
32
  end
27
33
 
28
34
  end
@@ -1,3 +1,3 @@
1
1
  module Cunfug
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -11,6 +11,16 @@ describe Cunfug::Configuration do
11
11
  self.already_defined = "already defined"
12
12
  end
13
13
  end
14
+
15
+ describe "with a blank state" do
16
+ it "must return nil on any given method" do
17
+ module Bar
18
+ include Cunfug::Configuration
19
+ end
20
+
21
+ Bar.test.must_be_nil
22
+ end
23
+ end
14
24
 
15
25
  describe "when given a new config option" do
16
26
  it "must return the freshly set value" do
@@ -32,5 +42,12 @@ describe Cunfug::Configuration do
32
42
  Foo.already_defined.must_equal "bla"
33
43
  end
34
44
  end
45
+
46
+ describe "when storing one or multiple class names" do
47
+ it "should generate additional reader methods that return constants" do
48
+ Foo.example_class_name = "Foo"
49
+ Foo.example_class.must_equal Foo
50
+ end
51
+ end
35
52
 
36
53
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cunfug
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease:
5
- version: 0.0.1
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
6
11
  platform: ruby
7
12
  authors:
8
13
  - Robert Glaser
@@ -47,12 +52,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
52
  requirements:
48
53
  - - ">="
49
54
  - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
50
58
  version: "0"
51
59
  required_rubygems_version: !ruby/object:Gem::Requirement
52
60
  none: false
53
61
  requirements:
54
62
  - - ">="
55
63
  - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
56
67
  version: "0"
57
68
  requirements: []
58
69