nyanko 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nyanko/config.rb +4 -2
- data/lib/nyanko/controller.rb +1 -1
- data/lib/nyanko/function.rb +6 -6
- data/lib/nyanko/helper.rb +2 -2
- data/lib/nyanko/unit.rb +9 -5
- data/lib/nyanko/unit_proxy.rb +3 -3
- data/lib/nyanko/unit_proxy_provider.rb +3 -3
- data/lib/nyanko/version.rb +1 -1
- data/spec/nyanko/exception_handler_spec.rb +2 -4
- data/spec/nyanko/helper_spec.rb +1 -1
- data/spec/nyanko/invoker_spec.rb +3 -5
- data/spec/nyanko/logger_spec.rb +6 -12
- data/spec/nyanko/unit_proxy_provider_spec.rb +21 -1
- data/spec/spec_helper.rb +5 -1
- metadata +2 -2
data/lib/nyanko/config.rb
CHANGED
@@ -2,9 +2,9 @@ module Nyanko
|
|
2
2
|
module Config
|
3
3
|
class << self
|
4
4
|
attr_accessor(
|
5
|
+
:auto_reload,
|
5
6
|
:backtrace_limit,
|
6
7
|
:cache_units,
|
7
|
-
:clear_units_cache,
|
8
8
|
:compatible_css_class,
|
9
9
|
:enable_logger,
|
10
10
|
:proxy_method_name,
|
@@ -13,8 +13,10 @@ module Nyanko
|
|
13
13
|
)
|
14
14
|
|
15
15
|
def reset
|
16
|
+
self.auto_reload = Rails.env.development? || Rails.env.test?
|
16
17
|
self.backtrace_limit = 10
|
17
|
-
self.
|
18
|
+
self.cache_units = false
|
19
|
+
self.compatible_css_class = false
|
18
20
|
self.enable_logger = true
|
19
21
|
self.proxy_method_name = :unit
|
20
22
|
self.raise_error = Rails.env.development?
|
data/lib/nyanko/controller.rb
CHANGED
data/lib/nyanko/function.rb
CHANGED
@@ -30,14 +30,14 @@ module Nyanko
|
|
30
30
|
if Config.compatible_css_class
|
31
31
|
%W[
|
32
32
|
extension
|
33
|
-
ext_#{unit.
|
34
|
-
ext_#{unit.
|
33
|
+
ext_#{unit.unit_name}
|
34
|
+
ext_#{unit.unit_name}-#{label}
|
35
35
|
]
|
36
36
|
else
|
37
37
|
%W[
|
38
38
|
unit
|
39
|
-
unit__#{unit.
|
40
|
-
unit__#{unit.
|
39
|
+
unit__#{unit.unit_name}
|
40
|
+
unit__#{unit.unit_name}__#{label}
|
41
41
|
]
|
42
42
|
end
|
43
43
|
end
|
@@ -55,11 +55,11 @@ module Nyanko
|
|
55
55
|
|
56
56
|
def with_unit_view_path(context)
|
57
57
|
if context.view?
|
58
|
-
context.view_paths.unshift unit.
|
58
|
+
context.view_paths.unshift unit.resolver
|
59
59
|
end
|
60
60
|
yield
|
61
61
|
ensure
|
62
|
-
context.view_paths.paths.
|
62
|
+
context.view_paths.paths.shift if context.view?
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
data/lib/nyanko/helper.rb
CHANGED
data/lib/nyanko/unit.rb
CHANGED
@@ -30,7 +30,7 @@ module Nyanko
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def helpers(&block)
|
33
|
-
Helper.define(
|
33
|
+
Helper.define(unit_name, &block)
|
34
34
|
end
|
35
35
|
|
36
36
|
def models(&block)
|
@@ -49,16 +49,16 @@ module Nyanko
|
|
49
49
|
ActiveIf::Any.new(*labels)
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
name.underscore.to_sym
|
52
|
+
def unit_name
|
53
|
+
@unit_name ||= name.underscore.to_sym
|
54
54
|
end
|
55
55
|
|
56
56
|
def to_prefix
|
57
|
-
UnitProxy.generate_prefix(
|
57
|
+
UnitProxy.generate_prefix(unit_name)
|
58
58
|
end
|
59
59
|
|
60
60
|
def view_path
|
61
|
-
"#{Config.units_directory_path}/#{
|
61
|
+
"#{Config.units_directory_path}/#{unit_name}/views"
|
62
62
|
end
|
63
63
|
|
64
64
|
def find_function(identifier, label)
|
@@ -80,6 +80,10 @@ module Nyanko
|
|
80
80
|
@shared_methods ||= {}
|
81
81
|
end
|
82
82
|
|
83
|
+
def resolver
|
84
|
+
@resolver ||= ActionView::OptimizedFileSystemResolver.new(view_path)
|
85
|
+
end
|
86
|
+
|
83
87
|
def extender
|
84
88
|
@extender ||= Extender.new(to_prefix)
|
85
89
|
end
|
data/lib/nyanko/unit_proxy.rb
CHANGED
@@ -4,8 +4,8 @@ module Nyanko
|
|
4
4
|
class UnitProxy
|
5
5
|
attr_reader :unit
|
6
6
|
|
7
|
-
def self.generate_prefix(
|
8
|
-
|
7
|
+
def self.generate_prefix(unit_name)
|
8
|
+
"__#{unit_name}_"
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(unit, context)
|
@@ -20,7 +20,7 @@ module Nyanko
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def prefix
|
23
|
-
self.class.generate_prefix(@unit.
|
23
|
+
self.class.generate_prefix(@unit.unit_name)
|
24
24
|
end
|
25
25
|
|
26
26
|
def method_missing(method_name, *args, &block)
|
@@ -8,10 +8,10 @@ module Nyanko
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def method_missing(method_name, *args, &block)
|
11
|
-
if
|
12
|
-
class_eval do
|
11
|
+
if Array.wrap(Config.proxy_method_name).include?(method_name)
|
12
|
+
UnitProxyProvider.class_eval do
|
13
13
|
define_method(method_name) do |*_args|
|
14
|
-
name = _args.first || Function.current_unit.try(:
|
14
|
+
name = _args.first || Function.current_unit.try(:unit_name)
|
15
15
|
if name && unit = Loader.load(name)
|
16
16
|
UnitProxy.new(unit, self)
|
17
17
|
end
|
data/lib/nyanko/version.rb
CHANGED
@@ -3,10 +3,8 @@ require "spec_helper"
|
|
3
3
|
module Nyanko
|
4
4
|
describe ExceptionHandler do
|
5
5
|
context "when Config.raise_error is truthy" do
|
6
|
-
|
7
|
-
|
8
|
-
example.run
|
9
|
-
Config.raise_error = origin
|
6
|
+
before do
|
7
|
+
Config.raise_error = true
|
10
8
|
end
|
11
9
|
|
12
10
|
it "raises up error" do
|
data/spec/nyanko/helper_spec.rb
CHANGED
data/spec/nyanko/invoker_spec.rb
CHANGED
@@ -50,11 +50,9 @@ module Nyanko
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context "when
|
54
|
-
|
55
|
-
|
56
|
-
example.run
|
57
|
-
Config.compatible_css_class = origin
|
53
|
+
context "when Config.compatible_css_class is true" do
|
54
|
+
before do
|
55
|
+
Config.compatible_css_class = true
|
58
56
|
end
|
59
57
|
|
60
58
|
it "invokes and returns result surrounded by div" do
|
data/spec/nyanko/logger_spec.rb
CHANGED
@@ -40,10 +40,8 @@ module Nyanko
|
|
40
40
|
end
|
41
41
|
|
42
42
|
context "when Config.enable_logger is true" do
|
43
|
-
|
44
|
-
|
45
|
-
example.run
|
46
|
-
Config.enable_logger = origin
|
43
|
+
before do
|
44
|
+
Config.enable_logger = true
|
47
45
|
end
|
48
46
|
|
49
47
|
context "when given Exception" do
|
@@ -53,10 +51,8 @@ module Nyanko
|
|
53
51
|
end
|
54
52
|
|
55
53
|
context "when Config.backtrace_limit is configured" do
|
56
|
-
|
57
|
-
|
58
|
-
example.run
|
59
|
-
Config.backtrace_limit = origin
|
54
|
+
before do
|
55
|
+
Config.backtrace_limit = 5
|
60
56
|
end
|
61
57
|
|
62
58
|
it "prints backtrace up to configured depth" do
|
@@ -75,10 +71,8 @@ module Nyanko
|
|
75
71
|
end
|
76
72
|
|
77
73
|
context "when Config.enable_logger is false" do
|
78
|
-
|
79
|
-
|
80
|
-
example.run
|
81
|
-
Config.enable_logger = origin
|
74
|
+
before do
|
75
|
+
Config.enable_logger = false
|
82
76
|
end
|
83
77
|
|
84
78
|
it "logs nothing" do
|
@@ -33,16 +33,36 @@ module Nyanko
|
|
33
33
|
context "when Config.proxy_method_name is configured" do
|
34
34
|
around do |example|
|
35
35
|
origin, Config.proxy_method_name = Config.proxy_method_name, :proxy
|
36
|
+
described_class.class_eval { remove_method origin } if view.respond_to?(origin)
|
36
37
|
example.run
|
37
|
-
|
38
|
+
described_class.class_eval { remove_method :proxy }
|
38
39
|
end
|
39
40
|
|
40
41
|
it "change this method name with it" do
|
42
|
+
view.should_not be_respond_to(:proxy)
|
41
43
|
proxy = view.proxy(:example_unit)
|
42
44
|
proxy.should be_a UnitProxy
|
43
45
|
view.should be_respond_to(:proxy)
|
44
46
|
end
|
45
47
|
end
|
48
|
+
|
49
|
+
context "when Config.proxy_method_name is configured as Array" do
|
50
|
+
around do |example|
|
51
|
+
origin, Config.proxy_method_name = Config.proxy_method_name, [:proxy1, :proxy2]
|
52
|
+
described_class.class_eval { remove_method origin } if view.respond_to?(origin)
|
53
|
+
example.run
|
54
|
+
described_class.class_eval { remove_method :proxy1, :proxy2 }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "change this method name with it" do
|
58
|
+
view.should_not be_respond_to(:proxy1)
|
59
|
+
view.should_not be_respond_to(:proxy2)
|
60
|
+
view.proxy1(:example_unit).should be_a UnitProxy
|
61
|
+
view.proxy2(:example_unit).should be_a UnitProxy
|
62
|
+
view.should be_respond_to(:proxy1)
|
63
|
+
view.should be_respond_to(:proxy2)
|
64
|
+
end
|
65
|
+
end
|
46
66
|
end
|
47
67
|
end
|
48
68
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,7 +6,6 @@ end
|
|
6
6
|
|
7
7
|
ENV["RAILS_ENV"] ||= "test"
|
8
8
|
require "nyanko"
|
9
|
-
Nyanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)
|
10
9
|
|
11
10
|
require File.expand_path("../dummy/config/environment", __FILE__)
|
12
11
|
require "rspec/rails"
|
@@ -18,4 +17,9 @@ RSpec.configure do |config|
|
|
18
17
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
19
18
|
config.run_all_when_everything_filtered = true
|
20
19
|
config.filter_run :focus
|
20
|
+
|
21
|
+
config.after do
|
22
|
+
Nyanko::Config.reset
|
23
|
+
Nyanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)
|
24
|
+
end
|
21
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nyanko
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
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: 2013-01-
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|