motion-require 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -1
- data/lib/motion-require/ext.rb +35 -0
- data/lib/motion-require/version.rb +1 -1
- data/lib/motion-require.rb +16 -41
- data/motion/ext.rb +1 -0
- data/motion-require.gemspec +2 -0
- data/spec/TestApp/app/app_delegate.rb +5 -0
- data/spec/motion_require_spec.rb +7 -0
- data/spec/spec_helper.rb +7 -0
- metadata +26 -3
data/Rakefile
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Hack until HipByte accepts https://github.com/HipByte/RubyMotion/pull/82
|
2
|
+
# Stolen from BubbleWrap
|
3
|
+
module Motion
|
4
|
+
module Require
|
5
|
+
module Ext
|
6
|
+
module ConfigTask
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
alias_method :files_dependencies_without_require, :files_dependencies
|
11
|
+
alias_method :files_dependencies, :files_dependencies_with_require
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def files_dependencies_with_require(deps_hash)
|
16
|
+
res_path = lambda do |x|
|
17
|
+
path = /^\.?\//.match(x) ? x : File.join('.', x)
|
18
|
+
unless @files.flatten.include?(path)
|
19
|
+
Motion::Project::App.send(:fail, "Can't resolve dependency `#{x}'")
|
20
|
+
end
|
21
|
+
path
|
22
|
+
end
|
23
|
+
deps_hash.each do |path, deps|
|
24
|
+
deps = [deps] unless deps.is_a?(Array)
|
25
|
+
@dependencies[res_path.call(path)] = deps.map(&res_path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if Motion.const_defined?("Project")
|
34
|
+
Motion::Project::Config.send(:include, Motion::Require::Ext::ConfigTask)
|
35
|
+
end
|
data/lib/motion-require.rb
CHANGED
@@ -1,41 +1,11 @@
|
|
1
1
|
require 'ripper'
|
2
|
-
|
3
|
-
|
4
|
-
# Stolen from BubbleWrap
|
5
|
-
module Motion::Require
|
6
|
-
module Ext
|
7
|
-
module ConfigTask
|
8
|
-
|
9
|
-
def self.included(base)
|
10
|
-
base.class_eval do
|
11
|
-
alias_method :files_dependencies_without_require, :files_dependencies
|
12
|
-
alias_method :files_dependencies, :files_dependencies_with_require
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def files_dependencies_with_require(deps_hash)
|
17
|
-
res_path = lambda do |x|
|
18
|
-
path = /^\.?\//.match(x) ? x : File.join('.', x)
|
19
|
-
unless @files.flatten.include?(path)
|
20
|
-
Motion::Project::App.send(:fail, "Can't resolve dependency `#{x}'")
|
21
|
-
end
|
22
|
-
path
|
23
|
-
end
|
24
|
-
deps_hash.each do |path, deps|
|
25
|
-
deps = [deps] unless deps.is_a?(Array)
|
26
|
-
@dependencies[res_path.call(path)] = deps.map(&res_path)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
Motion::Project::Config.send(:include, Motion::Require::Ext::ConfigTask)
|
2
|
+
require 'pathname'
|
3
|
+
require_relative 'motion-require/ext'
|
34
4
|
|
35
5
|
module Motion
|
36
6
|
module Require
|
37
7
|
class RequireBuilder < Ripper::SexpBuilder
|
38
|
-
|
8
|
+
REQUIREMENT_TOKENS = %w[motion_require require_relative]
|
39
9
|
|
40
10
|
attr_accessor :requires
|
41
11
|
|
@@ -45,7 +15,7 @@ module Motion
|
|
45
15
|
|
46
16
|
def on_command(command, args) # scanner event
|
47
17
|
type, name, position = command
|
48
|
-
if name
|
18
|
+
if REQUIREMENT_TOKENS.include?(name)
|
49
19
|
file = parse_args(args)
|
50
20
|
requires << file
|
51
21
|
end
|
@@ -77,7 +47,7 @@ module Motion
|
|
77
47
|
if required[-3..-1] != ".rb"
|
78
48
|
required += ".rb"
|
79
49
|
end
|
80
|
-
|
50
|
+
resolve_path(file_path, required)
|
81
51
|
}
|
82
52
|
dependencies[file_path].unshift ext_file
|
83
53
|
end
|
@@ -91,22 +61,27 @@ module Motion
|
|
91
61
|
parser.requires
|
92
62
|
end
|
93
63
|
|
94
|
-
|
95
|
-
|
64
|
+
# Join `required` to directory containing `source`.
|
65
|
+
# Preserves relative/absolute nature of source
|
66
|
+
def resolve_path(source, required)
|
67
|
+
Pathname.new(source).dirname.join(required.to_str).cleanpath.to_path
|
96
68
|
end
|
97
69
|
|
98
70
|
def all(files)
|
99
71
|
Motion::Project::App.setup do |app|
|
100
72
|
app.files << ext_file
|
101
|
-
files.
|
102
|
-
app.files << file
|
103
|
-
end
|
104
|
-
|
73
|
+
app.files |= files.map { |f| explicit_relative(f) }
|
105
74
|
dependencies = dependencies_for(files)
|
106
75
|
app.files_dependencies dependencies
|
107
76
|
end
|
108
77
|
end
|
109
78
|
|
79
|
+
# RubyMotion prefers relative paths to be explicitly prefixed with ./
|
80
|
+
def explicit_relative(path)
|
81
|
+
# Paths that do not start with "/", "./", or "../" will be prefixed with ./
|
82
|
+
path.sub(%r(^(?!\.{0,2}/)), './')
|
83
|
+
end
|
84
|
+
|
110
85
|
def ext_file
|
111
86
|
File.expand_path(File.join(File.dirname(__FILE__), "../motion/ext.rb"))
|
112
87
|
end
|
data/motion/ext.rb
CHANGED
data/motion-require.gemspec
CHANGED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-require
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,23 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-04-05 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.5'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.5'
|
14
30
|
description: Dependency management for RubyMotion, using a pseudo `require`
|
15
31
|
email:
|
16
32
|
- clay@usepropeller.com
|
@@ -24,9 +40,13 @@ files:
|
|
24
40
|
- README.md
|
25
41
|
- Rakefile
|
26
42
|
- lib/motion-require.rb
|
43
|
+
- lib/motion-require/ext.rb
|
27
44
|
- lib/motion-require/version.rb
|
28
45
|
- motion-require.gemspec
|
29
46
|
- motion/ext.rb
|
47
|
+
- spec/motion_require_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/TestApp/app/app_delegate.rb
|
30
50
|
homepage: https://github.com/clayallsopp/motion-require
|
31
51
|
licenses: []
|
32
52
|
post_install_message:
|
@@ -51,4 +71,7 @@ rubygems_version: 1.8.23
|
|
51
71
|
signing_key:
|
52
72
|
specification_version: 3
|
53
73
|
summary: Dependency management for RubyMotion, using a pseudo `require`
|
54
|
-
test_files:
|
74
|
+
test_files:
|
75
|
+
- spec/motion_require_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/TestApp/app/app_delegate.rb
|