55
66module Bundler
77 class Dependency < Gem ::Dependency
8- attr_reader :autorequire
9- attr_reader :groups , :platforms , :gemfile , :path , :git , :github , :branch , :ref , :glob
10-
118 def initialize ( name , version , options = { } , &blk )
129 type = options [ "type" ] || :runtime
1310 super ( name , version , type )
1411
15- @groups = Array ( options [ "group" ] || :default ) . map ( &:to_sym )
16- @source = options [ "source" ]
17- @path = options [ "path" ]
18- @git = options [ "git" ]
19- @github = options [ "github" ]
20- @branch = options [ "branch" ]
21- @ref = options [ "ref" ]
22- @glob = options [ "glob" ]
23- @platforms = Array ( options [ "platforms" ] )
24- @env = options [ "env" ]
25- @should_include = options . fetch ( "should_include" , true )
26- @gemfile = options [ "gemfile" ]
27- @force_ruby_platform = options [ "force_ruby_platform" ] if options . key? ( "force_ruby_platform" )
12+ @options = options
13+ end
14+
15+ def groups
16+ @groups ||= Array ( @options [ "group" ] || :default ) . map ( &:to_sym )
17+ end
18+
19+ def source
20+ return @source if defined? ( @source )
21+
22+ @source = @options [ "source" ]
23+ end
24+
25+ def path
26+ return @path if defined? ( @path )
27+
28+ @path = @options [ "path" ]
29+ end
30+
31+ def git
32+ return @git if defined? ( @git )
33+
34+ @git = @options [ "git" ]
35+ end
36+
37+ def github
38+ return @github if defined? ( @github )
39+
40+ @github = @options [ "github" ]
41+ end
42+
43+ def branch
44+ return @branch if defined? ( @branch )
45+
46+ @branch = @options [ "branch" ]
47+ end
48+
49+ def ref
50+ return @ref if defined? ( @ref )
51+
52+ @ref = @options [ "ref" ]
53+ end
54+
55+ def glob
56+ return @glob if defined? ( @glob )
57+
58+ @glob = @options [ "glob" ]
59+ end
60+
61+ def platforms
62+ @platforms ||= Array ( @options [ "platforms" ] )
63+ end
64+
65+ def env
66+ return @env if defined? ( @env )
67+
68+ @env = @options [ "env" ]
69+ end
70+
71+ def should_include
72+ @should_include ||= @options . fetch ( "should_include" , true )
73+ end
74+
75+ def gemfile
76+ return @gemfile if defined? ( @gemfile )
77+
78+ @gemfile = @options [ "gemfile" ]
79+ end
80+
81+ def force_ruby_platform
82+ return @force_ruby_platform if defined? ( @force_ruby_platform )
83+
84+ @force_ruby_platform = @options [ "force_ruby_platform" ]
85+ end
86+
87+ def autorequire
88+ return @autorequire if defined? ( @autorequire )
2889
29- @autorequire = Array ( options [ "require" ] || [ ] ) if options . key? ( "require" )
90+ @autorequire = Array ( @ options[ "require" ] || [ ] ) if @ options. key? ( "require" )
3091 end
3192
3293 RUBY_PLATFORM_ARRAY = [ Gem ::Platform ::RUBY ] . freeze
@@ -36,37 +97,37 @@ def initialize(name, version, options = {}, &blk)
3697 # passed in the `valid_platforms` parameter
3798 def gem_platforms ( valid_platforms )
3899 return RUBY_PLATFORM_ARRAY if force_ruby_platform
39- return valid_platforms if @ platforms. empty?
100+ return valid_platforms if platforms . empty?
40101
41102 valid_platforms . select { |p | expanded_platforms . include? ( GemHelpers . generic ( p ) ) }
42103 end
43104
44105 def expanded_platforms
45- @expanded_platforms ||= @ platforms. filter_map { |pl | CurrentRuby ::PLATFORM_MAP [ pl ] } . flatten . uniq
106+ @expanded_platforms ||= platforms . filter_map { |pl | CurrentRuby ::PLATFORM_MAP [ pl ] } . flatten . uniq
46107 end
47108
48109 def should_include?
49- @ should_include && current_env? && current_platform?
110+ should_include && current_env? && current_platform?
50111 end
51112
52113 def gemspec_dev_dep?
53114 type == :development
54115 end
55116
56117 def current_env?
57- return true unless @ env
58- if @ env. is_a? ( Hash )
59- @ env. all? do |key , val |
118+ return true unless env
119+ if env . is_a? ( Hash )
120+ env . all? do |key , val |
60121 ENV [ key . to_s ] && ( val . is_a? ( String ) ? ENV [ key . to_s ] == val : ENV [ key . to_s ] =~ val )
61122 end
62123 else
63- ENV [ @ env. to_s ]
124+ ENV [ env . to_s ]
64125 end
65126 end
66127
67128 def current_platform?
68- return true if @ platforms. empty?
69- @ platforms. any? do |p |
129+ return true if platforms . empty?
130+ platforms . any? do |p |
70131 Bundler . current_ruby . send ( "#{ p } ?" )
71132 end
72133 end
0 commit comments