motion_require 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # MotionRequire
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'motion_require'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install motion_require
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,75 @@
1
+ require 'pathname'
2
+
3
+ module MotionRequire
4
+ class DependencyBuilder
5
+ def self.build(app, load_paths = ['app', 'vendor'])
6
+ builder = new(app, load_paths)
7
+ app.files_dependencies(builder.dependencies)
8
+ app.files = [File.join(File.dirname(__FILE__), 'require.rb')] + builder.file_list
9
+ end
10
+
11
+ def initialize(app, load_paths)
12
+ @app = app
13
+ @load_paths = load_paths
14
+ @dependencies = {}
15
+ @file_list = []
16
+ @resolved = false
17
+ end
18
+
19
+ def dependencies
20
+ resolve
21
+ @dependencies
22
+ end
23
+
24
+ def file_list
25
+ resolve
26
+ @file_list
27
+ end
28
+
29
+ private
30
+
31
+ def resolve
32
+ return if @resolved
33
+ add_dependencies_for_file(find_file('app_delegate'))
34
+ @resolved = true
35
+ end
36
+
37
+ def add_dependencies_for_file(file_name)
38
+ return if @file_list.member?(file_name)
39
+
40
+ deps = dependencies_for_file(file_name)
41
+
42
+ @dependencies[file_name] = deps unless deps.empty?
43
+
44
+ @file_list.unshift(file_name)
45
+
46
+ deps.each do |file|
47
+ add_dependencies_for_file(file)
48
+ end
49
+ end
50
+
51
+ def find_file(file)
52
+ @load_paths.each do |path|
53
+ file_name = File.join(@app.project_dir, path, file + '.rb')
54
+ return file_name if File.exist?(file_name)
55
+ end
56
+ raise LoadError.new("cannot load such file -- #{file}")
57
+ end
58
+
59
+ def dependencies_for_file(file_name)
60
+ deps = []
61
+
62
+ file = File.new(file_name, 'r')
63
+
64
+ file.each_line do |line|
65
+ if match = line.match(/^\s*require '([^']+)'\s*$/)
66
+ deps << match[1]
67
+ end
68
+ end
69
+
70
+ deps.map! {|file| find_file(file)}
71
+
72
+ deps
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,4 @@
1
+ class Kernel
2
+ def require(file)
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module MotionRequire
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require "motion_require/version"
2
+ require "motion_require/dependency_builder"
3
+
4
+ Motion::Project::App.singleton_class.class_eval do
5
+
6
+ alias_method :setup_without_require, :setup
7
+
8
+ def setup(&block)
9
+ configs.each_value { |x| MotionRequire::DependencyBuilder.build(x) }
10
+ setup_without_require(&block)
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion_require
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mick Staugaard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Implementation of Kernel#require for RubyMotion
15
+ email:
16
+ - mick@staugaard.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/motion_require/dependency_builder.rb
22
+ - lib/motion_require/require.rb
23
+ - lib/motion_require/version.rb
24
+ - lib/motion_require.rb
25
+ - README.md
26
+ homepage: ''
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.16
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Automatic file dependency resolution for RubyMotion
50
+ test_files: []
51
+ has_rdoc: