nyanko 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -100,7 +100,6 @@ $ rails s
100
100
 
101
101
 
102
102
  ## Todo
103
- * auto-reloading
104
103
  * configuration
105
104
  * document
106
105
  * test (for now, test coverage is 100%)
data/lib/nyanko/config.rb CHANGED
@@ -1,30 +1,21 @@
1
1
  module Nyanko
2
2
  module Config
3
3
  class << self
4
- def units_directory_path
5
- @units_directory_path ||= "app/units"
6
- end
7
-
8
- def units_directory_path=(path)
9
- @units_directory_path = path
10
- end
11
-
12
- def raise_error
13
- @raise_error ||= lambda { Rails.env.development? }
14
- @raise_error.respond_to?(:call) ? @raise_error.call : @raise_error
15
- end
4
+ attr_accessor(
5
+ :backtrace_limit,
6
+ :cache_units,
7
+ :raise_error,
8
+ :units_directory_path
9
+ )
16
10
 
17
- def raise_error=(raise_error)
18
- @raise_error = raise_error
19
- end
20
-
21
- def backtrace_limit
22
- @backtrace_limit ||= 10
23
- end
24
-
25
- def backtrace_limit=(limit)
26
- @backtrace_limit = limit
11
+ def reset
12
+ self.backtrace_limit = 10
13
+ self.cache_units = !Rails.env.development?
14
+ self.raise_error = Rails.env.development?
15
+ self.units_directory_path = "app/units"
27
16
  end
28
17
  end
18
+
19
+ reset
29
20
  end
30
21
  end
data/lib/nyanko/loader.rb CHANGED
@@ -19,7 +19,11 @@ module Nyanko
19
19
  end
20
20
 
21
21
  def load
22
- loaded? ? load_from_cache : load_from_file
22
+ if loaded? && Config.cache_units
23
+ load_from_cache
24
+ else
25
+ load_from_file
26
+ end
23
27
  end
24
28
 
25
29
  def loaded?
@@ -31,7 +35,7 @@ module Nyanko
31
35
  end
32
36
 
33
37
  def load_from_file
34
- require_unit_files
38
+ add_autoload_path
35
39
  cache[@name] = constantize
36
40
  rescue Exception => exception
37
41
  ExceptionHandler.handle(exception)
@@ -39,12 +43,13 @@ module Nyanko
39
43
  nil
40
44
  end
41
45
 
42
- def require_unit_files
43
- paths.each {|path| require Rails.root.join(path) }
46
+ def add_autoload_path
47
+ ActiveSupport::Dependencies.autoload_paths << autoload_path
48
+ ActiveSupport::Dependencies.autoload_paths.uniq!
44
49
  end
45
50
 
46
- def paths
47
- Pathname.glob("#{directory_path}/#@name/#@name.rb").sort
51
+ def autoload_path
52
+ Rails.root.join("#{directory_path}/#@name").to_s
48
53
  end
49
54
 
50
55
  def directory_path
@@ -1,7 +1,5 @@
1
1
  module Nyanko
2
2
  module UnitProxyProvider
3
- NoUnitError = Class.new(StandardError)
4
-
5
3
  extend ActiveSupport::Concern
6
4
 
7
5
  included do
@@ -13,8 +11,6 @@ module Nyanko
13
11
  name ||= Function.current_unit.try(:to_key)
14
12
  if name && unit = Loader.load(name)
15
13
  UnitProxy.new(unit, self)
16
- else
17
- raise NoUnitError
18
14
  end
19
15
  end
20
16
  alias_method :ext, :unit
@@ -1,3 +1,3 @@
1
1
  module Nyanko
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -38,6 +38,20 @@ module Nyanko
38
38
  described_class.load(:non_existent_unit)
39
39
  end
40
40
  end
41
+
42
+ context "when Config.cache_unit is false" do
43
+ around do |example|
44
+ origin, Config.cache_units = Config.cache_units, false
45
+ example.run
46
+ Config.cache_units = origin
47
+ end
48
+
49
+ it "loads unit without cache" do
50
+ described_class.any_instance.should_not_receive(:load_from_cache)
51
+ described_class.load(:example_unit)
52
+ described_class.load(:example_unit)
53
+ end
54
+ end
41
55
  end
42
56
  end
43
57
  end
@@ -17,12 +17,6 @@ module Nyanko
17
17
  proxy.should be_a UnitProxy
18
18
  proxy.unit.should == ExampleUnit
19
19
  end
20
-
21
- context "when unit is not found" do
22
- it "raises NoUnitError" do
23
- expect { view.unit(:non_existent_unit) }.to raise_error(described_class::NoUnitError)
24
- end
25
- end
26
20
  end
27
21
 
28
22
  context "when given no unit name" do
data/spec/spec_helper.rb CHANGED
@@ -4,10 +4,10 @@ SimpleCov.start do
4
4
  add_filter "/spec\/dummy/"
5
5
  end
6
6
 
7
+ ENV["RAILS_ENV"] ||= "test"
7
8
  require "nyanko"
8
9
  Nyanko::Config.units_directory_path = File.expand_path("../fixtures/units", __FILE__)
9
10
 
10
- ENV["RAILS_ENV"] ||= "test"
11
11
  require File.expand_path("../dummy/config/environment", __FILE__)
12
12
  require "rspec/rails"
13
13
  require "rspec/autorun"
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: