motion_require2 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in motion_require.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mick Staugaard
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # motion_require
2
+
3
+ Allows you to use `require` in your RubyMotion apps just like you are used to. This allows you to use gems like you normally do and manage your
4
+ dependencies with Bundler.
5
+
6
+ ## Installation
7
+
8
+ Use bundler like you normally do when writing your Ruby apps, and add this line to your application's Gemfile:
9
+
10
+ gem 'motion_require'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Then require it in your Rakefile by adding this line somewhere at the top:
17
+
18
+ require 'motion_require'
19
+
20
+ So your Rakefile will look something like this:
21
+
22
+ ```ruby
23
+ require "bundler/setup"
24
+
25
+ $:.unshift('/Library/RubyMotion/lib')
26
+ require 'motion/project'
27
+ require 'motion_require'
28
+
29
+ Motion::Project::App.setup do |app|
30
+ app.name = 'KillerApp'
31
+ end
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Now you can use require in your application to specify the dependencies without having to maintain the compliation order in you Rakefile.
37
+ You can even require files from gems that are in you Gemfile.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ $:.unshift("/Library/RubyMotion/lib")
2
+ require 'motion/project'
@@ -0,0 +1,12 @@
1
+ require "motion_require/version"
2
+ require "motion_require/dependency_graph"
3
+
4
+ module MotionRequire
5
+ module ConfigTask
6
+ def auto_require
7
+ MotionRequire::DependencyGraph.build(self)
8
+ end
9
+ end
10
+ end
11
+
12
+ Motion::Project::Config.send(:include, MotionRequire::ConfigTask)
@@ -0,0 +1,96 @@
1
+ require 'pathname'
2
+ require 'tsort'
3
+
4
+ module MotionRequire
5
+
6
+ class DependencyHash < Hash
7
+ include TSort
8
+
9
+ alias tsort_each_node each_key
10
+
11
+ def tsort_each_child(k)
12
+ self[k].each { |p| yield p } if has_key?(k)
13
+ end
14
+
15
+ end
16
+
17
+ class DependencyGraph
18
+
19
+ def self.build(app)
20
+ builder = new(app, app.files + app.spec_files, ['app', 'lib', 'vendor'])
21
+ app.files = [kernel_require_path] + builder.files - app.spec_files
22
+ #app.files_dependencies(builder.dependencies)
23
+ end
24
+
25
+ def initialize(app, start_files, load_paths)
26
+ @app = app
27
+ @start_files = start_files
28
+ @load_paths = load_paths.map { |path| File.join(@app.project_dir, path) }
29
+
30
+ @dependencies = DependencyHash.new []
31
+ @files = []
32
+
33
+ @resolved = false
34
+ end
35
+
36
+ def files
37
+ rebuild
38
+ @files
39
+ end
40
+
41
+ def dependencies
42
+ rebuild
43
+ @dependencies
44
+ end
45
+
46
+ private
47
+
48
+ def self.kernel_require_path
49
+ File.join(File.dirname(__FILE__), 'kernel_require.rb')
50
+ end
51
+
52
+ def rebuild
53
+ return if @resolved
54
+
55
+ unprocessed = Array.new @start_files
56
+
57
+ while unprocessed.count > 0
58
+ cur_file = unprocessed.pop
59
+ @dependencies[cur_file] += dependencies_for_file(cur_file) unless @dependencies.include?(cur_file)
60
+
61
+ @dependencies[cur_file].each do |dependency|
62
+ @dependencies[dependency] = [] unless @dependencies.include?(dependency)
63
+ end
64
+ end
65
+
66
+ @files = @dependencies.tsort
67
+ @dependencies.delete_if { |_, v| v.empty? }
68
+
69
+ @resolved = true
70
+ end
71
+
72
+ def dependencies_for_file(file_name)
73
+ deps = []
74
+
75
+ File.open(file_name, 'r') do |f|
76
+ f.each_line do |line|
77
+ if match = line.match(/^\s*require ([\"'])([^']+)\1\s*$/)
78
+ deps << match[2]
79
+ end
80
+ end
81
+ end
82
+
83
+ deps.map { |file| find_file(file) }
84
+ end
85
+
86
+ def find_file(file)
87
+ (@load_paths + $:).each do |path|
88
+ file_name = File.join(path, file + '.rb')
89
+ return file_name if File.exist?(file_name)
90
+ end
91
+
92
+ raise "Can't locate file #{file}"
93
+ end
94
+
95
+ end
96
+ 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.4.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/motion_require/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mick Staugaard", "Venkat Dinavahi"]
6
+ gem.email = ["mick@staugaard.com"]
7
+ gem.description = "Implementation of Kernel#require for RubyMotion"
8
+ gem.summary = "Automatic file dependency resolution for RubyMotion"
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "motion_require2"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MotionRequire::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion_require2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mick Staugaard
9
+ - Venkat Dinavahi
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-14 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: Implementation of Kernel#require for RubyMotion
16
+ email:
17
+ - mick@staugaard.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - lib/motion_require.rb
28
+ - lib/motion_require/dependency_graph.rb
29
+ - lib/motion_require/kernel_require.rb
30
+ - lib/motion_require/version.rb
31
+ - motion_require.gemspec
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Automatic file dependency resolution for RubyMotion
56
+ test_files: []