nyanko 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,8 @@ module Nyanko
18
18
  end
19
19
  end
20
20
 
21
+ attr_reader :conditions, :options
22
+
21
23
  def initialize(*conditions, &block)
22
24
  @options = conditions.extract_options!
23
25
  @conditions = conditions
@@ -30,7 +32,7 @@ module Nyanko
30
32
 
31
33
  def blocks
32
34
  @blocks ||= begin
33
- @conditions.map do |condition|
35
+ conditions.map do |condition|
34
36
  condition.is_a?(Any) ? condition.to_block : self.class.find(condition)
35
37
  end << @block
36
38
  end.compact
@@ -23,7 +23,7 @@ module Nyanko
23
23
  with_unit_view_path(context) do
24
24
  capture_exception(context) do
25
25
  result = context.instance_eval(&block)
26
- result = decorate(result, context, options[:type]) if context.view?
26
+ result = decorate(result, context, options[:type]) if context.view? && result.present?
27
27
  result
28
28
  end
29
29
  end
@@ -33,14 +33,18 @@ module Nyanko
33
33
  def method_missing(method_name, *args, &block)
34
34
  if shared_method = __find_shared_method(method_name)
35
35
  instance_exec(*args, &shared_method)
36
- elsif args.empty? && local = __find_unit_local(method_name)
37
- local
36
+ elsif args.empty? && __find_unit_local(method_name)
37
+ __fetch_unit_local(method_name)
38
38
  else
39
39
  super
40
40
  end
41
41
  end
42
42
 
43
43
  def __find_unit_local(method_name)
44
+ __current_unit_locals.has_key?(method_name)
45
+ end
46
+
47
+ def __fetch_unit_local(method_name)
44
48
  __current_unit_locals[method_name]
45
49
  end
46
50
 
@@ -5,7 +5,7 @@ module Nyanko
5
5
  ::Logger::Severity.constants.each do |level|
6
6
  method_name = level.downcase
7
7
  define_method(method_name) do |message|
8
- logger.send(method_name, decorate(message)) if Config.enable_logger
8
+ logger.try(method_name, decorate(message)) if Config.enable_logger
9
9
  end
10
10
  end
11
11
 
@@ -1,7 +1,13 @@
1
1
  module Nyanko
2
2
  module Test
3
- def self.activations
4
- @activations ||= {}
3
+ class << self
4
+ def activations
5
+ @activations ||= {}
6
+ end
7
+
8
+ def included(base)
9
+ base.send :include, UnitProxyProvider
10
+ end
5
11
  end
6
12
 
7
13
  def enable_unit(unit_name)
@@ -37,9 +37,10 @@ module Nyanko
37
37
  %w[belongs_to has_many has_one].each do |method_name|
38
38
  class_eval <<-EOS
39
39
  def #{method_name}(*args, &block)
40
- name = @prefix + args.shift.to_s
40
+ label = args.shift.to_s
41
+ name = @prefix + label
41
42
  options = args.extract_options!
42
- options = options.reverse_merge(:class_name => @mod.to_s)
43
+ options = options.reverse_merge(:class_name => label.singularize.camelize)
43
44
  args << options
44
45
  @mod.#{method_name}(name.to_sym, *args, &block)
45
46
  end
@@ -4,7 +4,6 @@ module Nyanko
4
4
 
5
5
  included do
6
6
  extend UnitProxyProvider
7
- include Helper
8
7
  end
9
8
 
10
9
  # Define #unit method in this class when #unit is called in first time.
@@ -1,3 +1,3 @@
1
1
  module Nyanko
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -44,6 +44,10 @@ module ExampleUnit
44
44
  key
45
45
  end
46
46
 
47
+ function(:falsy) do
48
+ key.nil?
49
+ end
50
+
47
51
  function(:shared) do
48
52
  shared("args")
49
53
  end
@@ -59,6 +63,10 @@ module ExampleUnit
59
63
  function(:render) do
60
64
  render "/test", :local => "test"
61
65
  end
66
+
67
+ function(:blank) do
68
+ " "
69
+ end
62
70
  end
63
71
 
64
72
  helpers do
@@ -28,6 +28,11 @@ module Nyanko
28
28
  should == "value"
29
29
  end
30
30
 
31
+ it "invokes with falsy locals" do
32
+ view.invoke(:example_unit, :falsy, :locals => { :key => nil }, :type => :plain).
33
+ should == true
34
+ end
35
+
31
36
  it "invokes with shared method" do
32
37
  view.invoke(:example_unit, :shared, :type => :plain).should == "shared args"
33
38
  end
@@ -74,11 +79,17 @@ module Nyanko
74
79
  end
75
80
 
76
81
  context "when type is :plain" do
77
- it "invokes defined function for current context and return result" do
82
+ it "does not surround result with html element" do
78
83
  view.invoke(:example_unit, :test, :type => :plain).should == "test"
79
84
  end
80
85
  end
81
86
 
87
+ context "when the result is blank" do
88
+ it "does not surround result with html element" do
89
+ view.invoke(:example_unit, :blank).should == " "
90
+ end
91
+ end
92
+
82
93
  context "when type is :inline" do
83
94
  it "invokes and returns result surrounded by span" do
84
95
  view.invoke(:example_unit, :test, :type => :inline).should ==
@@ -80,5 +80,15 @@ module Nyanko
80
80
  log.should == ""
81
81
  end
82
82
  end
83
+
84
+ context "when Rails.logger is nil" do
85
+ before do
86
+ Rails.stub(:logger)
87
+ end
88
+
89
+ it "does notihng" do
90
+ expect { described_class.debug(exception) }.not_to raise_error(NoMethodError)
91
+ end
92
+ end
83
93
  end
84
94
  end
@@ -122,6 +122,8 @@ module Nyanko
122
122
  expand(:ExampleModel) do
123
123
  scope :active, lambda { where(:deleted_at => nil) }
124
124
 
125
+ has_one :user
126
+
125
127
  def test
126
128
  "test"
127
129
  end
@@ -144,6 +146,12 @@ module Nyanko
144
146
  define_method(name) { "scoped" }
145
147
  end
146
148
  end
149
+
150
+ def self.has_one(name, *args)
151
+ singleton_class.class_eval do
152
+ define_method(name) { args }
153
+ end
154
+ end
147
155
  end
148
156
  end
149
157
 
@@ -155,9 +163,13 @@ module Nyanko
155
163
  ExampleModel.__example_unit_test.should == "test"
156
164
  end
157
165
 
158
- it "defines association methods with prefix" do
166
+ it "defines scope method with prefix" do
159
167
  ExampleModel.__example_unit_active.should == "scoped"
160
168
  end
169
+
170
+ it "defines has_one association method with prefix" do
171
+ ExampleModel.__example_unit_user.should == [:class_name => "User"]
172
+ end
161
173
  end
162
174
 
163
175
  describe ".view_path" do
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.8
4
+ version: 0.0.9
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-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -375,3 +375,4 @@ test_files:
375
375
  - spec/nyanko/unit_proxy_spec.rb
376
376
  - spec/nyanko/unit_spec.rb
377
377
  - spec/spec_helper.rb
378
+ has_rdoc: