quir 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b63daed23a7fc7c91f69935f25c9eefe1d2bf34
4
- data.tar.gz: fd6d33efd28ed99f71ac1e1441e76496f6f115c0
3
+ metadata.gz: 03d1af642be46bf1ec5ef4c044f69a4ca8c44fd9
4
+ data.tar.gz: 7afe9fc14a8522877c95c808ec6e8df55d0e11fa
5
5
  SHA512:
6
- metadata.gz: 5c230c8bec00c0f4f50a2e21f88ce422e8017519b61b3f24531d30173abccc6e970ba91eddea245866561b71ad21d2f510c266cc8f637356f89f860d9b24c722
7
- data.tar.gz: caaa7fc63223d98054170f933129817643e63d5ee064c1ef4db732b876b00a1449860ecf48f3928fb3b2e121bbd6adcd1e23d56559e148d415759a07539f5356
6
+ metadata.gz: c828cc56b042bb34449454f74044979eff1d8298257cddedc56c276b5db726fa55929645714bce33993f490001fd67eb939622d597300b4066bcfbb039d2d0b1
7
+ data.tar.gz: ebf72fe1d99c44aef6c3019bac38fab829b4a5c378d662a95a7ad92a5062805fe54b9048b6c9807f593c8a57b435c02a6b5f89b8c2c477689fa7ba19ecb5f659
data/lib/quir.rb CHANGED
@@ -4,11 +4,8 @@ module Quir
4
4
  autoload :Loader, 'quir/loader'
5
5
  autoload :Inflection, 'quir/inflection'
6
6
 
7
- def self.later(&block)
7
+ def self.autoload!(&block)
8
8
  raise "No block given." unless block
9
- mod = block.binding.eval('self')
10
- dir = block.binding.eval('__FILE__').sub(/\.rb$/, '')
11
- loader = Loader.new(mod, dir)
12
- loader.run
9
+ Loader.from_binding(block.binding).autoload!
13
10
  end
14
11
  end
@@ -0,0 +1,5 @@
1
+ class Binding
2
+ def quir
3
+ ::Quir::Loader.from_binding(self)
4
+ end
5
+ end
data/lib/quir/loader.rb CHANGED
@@ -2,26 +2,30 @@ using Quir::Inflection
2
2
 
3
3
  module Quir
4
4
  class Loader
5
- attr_reader :binding
6
-
7
5
  def initialize(mod, dir)
8
6
  @module = mod
9
7
  @dir = dir
10
8
  end
11
9
 
10
+ def self.from_binding(binding)
11
+ mod = binding.eval('self')
12
+ dir = binding.eval('__FILE__').sub(/\.rb$/, '')
13
+ Loader.new(mod, dir)
14
+ end
15
+
12
16
  attr_reader :module, :dir
13
17
 
14
- def run
18
+ def autoload!
15
19
  ::Dir.glob("#{dir}/*") do |f|
16
20
  if ::File.directory?(f)
17
- append_directory f
21
+ autoload_directory f
18
22
  elsif /\.rb$/ =~ f
19
- append_ruby_file f
23
+ autoload_ruby_file f
20
24
  end
21
25
  end
22
26
  end
23
27
 
24
- def append_directory(d)
28
+ def autoload_directory(d)
25
29
  return if ::File.exist?("#{dir}/#{d}.rb")
26
30
  name = d.split(/\//)[-1].pascalize
27
31
  return if self.module.const_defined?(name, false)
@@ -29,10 +33,10 @@ module Quir
29
33
  self.module.const_set name, m
30
34
  m.name # fix module's name
31
35
  loader = ::Quir::Loader.new(m, d)
32
- loader.run
36
+ loader.autoload!
33
37
  end
34
38
 
35
- def append_ruby_file(f)
39
+ def autoload_ruby_file(f)
36
40
  name = f.split(/\//)[-1].sub(/\.rb$/, '').pascalize
37
41
  self.module.autoload name, f unless self.module.autoload?(name)
38
42
  end
data/lib/quir/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Quir
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mosop
@@ -68,6 +68,7 @@ files:
68
68
  - bin/console
69
69
  - bin/setup
70
70
  - lib/quir.rb
71
+ - lib/quir/binding.rb
71
72
  - lib/quir/inflection.rb
72
73
  - lib/quir/inflection/string.rb
73
74
  - lib/quir/inflection/string/pascalize.rb