From 846131bfb6825f2a3aa432dd670f3be4ab06673e Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 22 Oct 2013 10:41:25 +0200 Subject: [PATCH 01/11] [Gemfile] Added Tailor gem --- Gemfile | 1 + Gemfile.lock | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Gemfile b/Gemfile index 132512ac2..22cbba6a8 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ group :development do gem "mocha-on-bacon" gem "rake" gem 'prettybacon', :git => 'https://github.com/irrationalfab/PrettyBacon.git', :branch => 'master' + gem 'tailor' end group :debugging do diff --git a/Gemfile.lock b/Gemfile.lock index a44c4df38..358c4a47b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,7 @@ GEM rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) rb-kqueue (>= 0.2) + log_switch (0.4.0) metaclass (0.0.1) method_source (0.8.2) mime-types (1.25) @@ -78,8 +79,13 @@ GEM simplecov-html (~> 0.7.1) simplecov-html (0.7.1) slop (3.4.6) + tailor (1.3.1) + log_switch (>= 0.3.0) + term-ansicolor (>= 1.0.5) + text-table (>= 1.2.2) term-ansicolor (1.2.2) tins (~> 0.8) + text-table (1.2.3) thor (0.18.1) tins (0.12.0) yajl-ruby (1.1.0) @@ -103,4 +109,5 @@ DEPENDENCIES rake rb-fsevent redcarpet + tailor yard From d3d80589d34bc147ed4cc8a9f0ae0cd9f243af07 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 22 Oct 2013 10:42:35 +0200 Subject: [PATCH 02/11] [Rakefile] Added default config for Tailor --- .tailor | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .tailor diff --git a/.tailor b/.tailor new file mode 100644 index 000000000..7e2926c08 --- /dev/null +++ b/.tailor @@ -0,0 +1,107 @@ +#------------------------------------------------------------------------------ +# Horizontal Whitespace +#------------------------------------------------------------------------------ +# allow_hard_tabs True to let hard tabs be considered a single space. +# Default: false +# +# allow_trailing_line_spaces +# True to skip detecting extra spaces at the ends of +# lines. +# Default: false +# +# indentation_spaces The number of spaces to consider a proper indent. +# Default: 2 +# +# max_line_length The maximum number of characters in a line before +# tailor complains. +# Default: 80 +# spaces_after_comma Number of spaces to expect after a comma. +# Default: 1 +# +# spaces_before_comma Number of spaces to expect before a comma. +# Default: 0 +# +# spaces_after_lbrace The number of spaces to expect after an lbrace ('{'). +# Default: 1 +# +# spaces_before_lbrace The number of spaces to expect before an lbrace ('{'). +# Default: 1 +# +# spaces_before_rbrace The number of spaces to expect before an rbrace ('}'). +# Default: 1 +# +# spaces_in_empty_braces The number of spaces to expect between braces when +# there's nothing in the braces (i.e. {}). +# Default: 0 +# +# spaces_after_lbracket The number of spaces to expect after an +# lbracket ('['). +# Default: 0 +# +# spaces_before_rbracket The number of spaces to expect before an +# rbracket (']'). +# Default: 0 +# +# spaces_after_lparen The number of spaces to expect after an +# lparen ('('). +# Default: 0 +# +# spaces_before_rparen The number of spaces to expect before an +# rbracket (')'). +# Default: 0 +# +#------------------------------------------------------------------------------ +# Naming +#------------------------------------------------------------------------------ +# allow_camel_case_methods +# Setting to true skips detection of camel-case method +# names (i.e. def myMethod). +# Default: false +# +# allow_screaming_snake_case_classes +# Setting to true skips detection of screaming +# snake-case class names (i.e. My_Class). +# Default: false +# +#------------------------------------------------------------------------------ +# Vertical Whitespace +#------------------------------------------------------------------------------ +# max_code_lines_in_class The number of lines of code in a class to allow before +# tailor will warn you. +# Default: 300 +# +# max_code_lines_in_method +# The number of lines of code in a method to allow +# before tailor will warn you. +# Default: 30 +# +# trailing_newlines The number of newlines that should be at the end of +# the file. +# Default: 1 +# +Tailor.config do |config| + config.formatters "text" + config.file_set 'lib/**/*.rb' do |style| + style.allow_camel_case_methods false, level: :error + style.allow_hard_tabs false, level: :error + style.allow_screaming_snake_case_classes false, level: :error + style.allow_trailing_line_spaces false, level: :error + style.allow_invalid_ruby false, level: :warn + style.indentation_spaces 2, level: :error + style.max_code_lines_in_class 300, level: :error + style.max_code_lines_in_method 30, level: :error + style.max_line_length 80, level: :error + style.spaces_after_comma 1, level: :error + style.spaces_after_conditional 1, level: :error + style.spaces_after_lbrace 1, level: :error + style.spaces_after_lbracket 0, level: :error + style.spaces_after_lparen 0, level: :error + style.spaces_before_comma 0, level: :error + style.spaces_before_lbrace 1, level: :error + style.spaces_before_rbrace 1, level: :error + style.spaces_before_rbracket 0, level: :error + style.spaces_before_rparen 0, level: :error + style.spaces_in_empty_braces 0, level: :error + style.trailing_newlines 1, level: :error + end +end From 12fa857a6cd76f0f8d30096773d848436540fa7d Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 22 Oct 2013 10:44:32 +0200 Subject: [PATCH 03/11] [Rakefile] Added Tailor tasks --- Rakefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Rakefile b/Rakefile index ec8c530e7..31a38b889 100644 --- a/Rakefile +++ b/Rakefile @@ -193,4 +193,7 @@ end desc "Run all specs" task :spec => 'spec:all' +require 'tailor/rake_task' +Tailor::RakeTask.new + task :default => :spec From c513bb266172fb4223d5301fad29f587722a1a50 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 22 Oct 2013 10:47:39 +0200 Subject: [PATCH 04/11] [Tailor] Tune configuration --- .tailor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tailor b/.tailor index 7e2926c08..848c2f54b 100644 --- a/.tailor +++ b/.tailor @@ -91,7 +91,7 @@ Tailor.config do |config| style.max_code_lines_in_class 300, level: :error style.max_code_lines_in_method 30, level: :error style.max_line_length 80, level: :error - style.spaces_after_comma 1, level: :error + style.spaces_after_comma 1, level: :off style.spaces_after_conditional 1, level: :error style.spaces_after_lbrace 1, level: :error style.spaces_after_lbracket 0, level: :error From cb8becbd35a9ec9fbf8c71824aa8756faf4206e4 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 22 Oct 2013 10:56:15 +0200 Subject: [PATCH 05/11] [Rakefile] Tailor requires Ruby > 1.9.3 --- Rakefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Rakefile b/Rakefile index 31a38b889..f9c80398a 100644 --- a/Rakefile +++ b/Rakefile @@ -193,7 +193,14 @@ end desc "Run all specs" task :spec => 'spec:all' +if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9.3') require 'tailor/rake_task' Tailor::RakeTask.new +else + desc "Check style" + task :tailor do + puts "[!] Ruby > 1.9 is required to run tailor" + end +end task :default => :spec From 11e8d1b5fb7b6cba2373db873d6755ba784f9a47 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Tue, 22 Oct 2013 14:38:46 +0200 Subject: [PATCH 06/11] Fix code style --- lib/cocoapods-core.rb | 2 - lib/cocoapods-core/core_ui.rb | 1 - lib/cocoapods-core/dependency.rb | 15 +- lib/cocoapods-core/lockfile.rb | 22 +- lib/cocoapods-core/platform.rb | 10 +- lib/cocoapods-core/podfile.rb | 15 +- lib/cocoapods-core/podfile/dsl.rb | 21 +- .../podfile/target_definition.rb | 65 ++-- lib/cocoapods-core/source.rb | 5 +- lib/cocoapods-core/source/acceptor.rb | 20 +- lib/cocoapods-core/source/aggregate.rb | 31 +- lib/cocoapods-core/source/health_reporter.rb | 4 +- lib/cocoapods-core/specification.rb | 8 +- lib/cocoapods-core/specification/consumer.rb | 10 +- lib/cocoapods-core/specification/dsl.rb | 23 +- .../specification/dsl/attribute.rb | 5 +- .../specification/dsl/deprecations.rb | 52 ++-- .../specification/dsl/platform_proxy.rb | 21 +- lib/cocoapods-core/specification/linter.rb | 136 ++++++--- .../specification/root_attribute_accessors.rb | 14 +- lib/cocoapods-core/specification/set.rb | 22 +- .../specification/set/presenter.rb | 8 +- lib/cocoapods-core/specification/yaml.rb | 8 +- lib/cocoapods-core/standard_error.rb | 4 +- lib/cocoapods-core/vendor.rb | 1 - lib/cocoapods-core/vendor/version.rb | 283 +++++++++--------- lib/cocoapods-core/version.rb | 5 +- lib/cocoapods-core/yaml_converter.rb | 3 +- 28 files changed, 496 insertions(+), 318 deletions(-) diff --git a/lib/cocoapods-core.rb b/lib/cocoapods-core.rb index 3e06ac8c8..ba9cae3d3 100644 --- a/lib/cocoapods-core.rb +++ b/lib/cocoapods-core.rb @@ -35,5 +35,3 @@ class Informative < PlainInformative; end Spec = Specification end - - diff --git a/lib/cocoapods-core/core_ui.rb b/lib/cocoapods-core/core_ui.rb index 7d940a96b..84a31676f 100644 --- a/lib/cocoapods-core/core_ui.rb +++ b/lib/cocoapods-core/core_ui.rb @@ -16,4 +16,3 @@ def self.warn(message) end end - diff --git a/lib/cocoapods-core/dependency.rb b/lib/cocoapods-core/dependency.rb index 2725103e1..af15bc9b9 100644 --- a/lib/cocoapods-core/dependency.rb +++ b/lib/cocoapods-core/dependency.rb @@ -73,14 +73,16 @@ def initialize(name = nil, *requirements) if requirements.last.is_a?(Hash) @external_source = requirements.pop unless requirements.empty? - raise Informative, "A dependency with an external source may not specify version requirements (#{name})." + raise Informative, "A dependency with an external source may not " \ + "specify version requirements (#{name})." end elsif requirements.last == :head @head = true requirements.pop unless requirements.empty? - raise Informative, "A `:head` dependency may not specify version requirements (#{name})." + raise Informative, "A `:head` dependency may not specify version " \ + "requirements (#{name})." end end @@ -103,8 +105,11 @@ def initialize(name = nil, *requirements) # be better to add something like Version#display_string. # def requirement - return Requirement.new(Version.new(specific_version.version)) if specific_version - @requirement + if specific_version + Requirement.new(Version.new(specific_version.version)) + else + @requirement + end end # @return [Bool] whether the dependency points to a subspec. @@ -329,7 +334,7 @@ def self.from_string(string) # def inspect "<#{self.class} name=#{self.name} requirements=#{requirement.to_s} " \ - "external_source=#{external_source||'nil'}>" + "external_source=#{external_source||'nil'}>" end #--------------------------------------# diff --git a/lib/cocoapods-core/lockfile.rb b/lib/cocoapods-core/lockfile.rb index d557e8984..0fe6be4b2 100644 --- a/lib/cocoapods-core/lockfile.rb +++ b/lib/cocoapods-core/lockfile.rb @@ -89,7 +89,9 @@ def pod_names def version(pod_name) version = pod_versions[pod_name] return version if version - root_name = pod_versions.keys.find { |name| Specification.root_name(name) == pod_name } + root_name = pod_versions.keys.find do |name| + Specification.root_name(name) == pod_name + end pod_versions[root_name] end @@ -140,7 +142,8 @@ def dependency_to_lock_pod_named(name) version = version(name) unless dep && version - raise StandardError, "Attempt to lock the `#{name}` Pod without an known dependency." + raise StandardError, "Attempt to lock the `#{name}` Pod without an " \ + "known dependency." end locked_dependency = dep.dup @@ -229,9 +232,11 @@ def checksum_data # def detect_changes_with_podfile(podfile) result = {} - [ :added, :changed, :removed, :unchanged ].each { |k| result[k] = [] } + [:added, :changed, :removed, :unchanged].each { |k| result[k] = [] } - installed_deps = dependencies.map { |d| dependency_to_lock_pod_named(d.name) } + installed_deps = dependencies.map do |dep| + dependency_to_lock_pod_named(dep.name) + end all_dep_names = (dependencies + podfile.dependencies).map(&:name).uniq all_dep_names.each do |name| installed_dep = installed_deps.find { |d| d.name == name } @@ -239,7 +244,7 @@ def detect_changes_with_podfile(podfile) if installed_dep.nil? then key = :added elsif podfile_dep.nil? then key = :removed - elsif podfile_dep.compatible?(installed_dep ) then key = :unchanged + elsif podfile_dep.compatible?(installed_dep) then key = :unchanged else key = :changed end result[key] << name @@ -262,7 +267,7 @@ def detect_changes_with_podfile(podfile) # def write_to_disk(path) path.dirname.mkpath unless path.dirname.exist? - File.open(path, 'w') {|f| f.write(to_yaml) } + File.open(path, 'w') { |f| f.write(to_yaml) } self.defined_in_file = path end @@ -391,7 +396,7 @@ def generate_pods_data(specs) # @return [Array] the generated data. # def generate_dependencies_data(podfile) - podfile.dependencies.map{ |d| d.to_s }.sort + podfile.dependencies.map { |d| d.to_s }.sort end # Generates the information of the external sources. @@ -409,7 +414,7 @@ def generate_dependencies_data(podfile) # def generate_external_sources_data(podfile) deps = podfile.dependencies.select(&:external?) - deps = deps.sort { |d, other| d.name <=> other.name} + deps = deps.sort { |d, other| d.name <=> other.name } sources = {} deps.each { |d| sources[d.root_name] = d.external_source } sources @@ -437,4 +442,3 @@ def generate_checksums(specs) end end end - diff --git a/lib/cocoapods-core/platform.rb b/lib/cocoapods-core/platform.rb index dd223f40f..ce3395185 100644 --- a/lib/cocoapods-core/platform.rb +++ b/lib/cocoapods-core/platform.rb @@ -100,7 +100,7 @@ def ==(other) def supports?(other) other = Platform.new(other) if other.deployment_target && deployment_target - (other.name == name) && (other.deployment_target <= deployment_target) + (other.name == name) && (other.deployment_target <= deployment_target) else other.name == name end @@ -119,7 +119,7 @@ def to_s # def inspect "#<#{self.class.name} name=#{name.inspect} " \ - "deployment_target=#{deployment_target.inspect}>" + "deployment_target=#{deployment_target.inspect}>" end # @return [Symbol] a symbol representing the name of the platform. @@ -150,7 +150,11 @@ def <=> other # iOS. # def requires_legacy_ios_archs? - (name == :ios) && deployment_target && (deployment_target < Version.new("4.3")) + if name == :ios + deployment_target && (deployment_target < Version.new("4.3")) + else + false + end end # Converts the symbolic name of a platform to a string name suitable to be diff --git a/lib/cocoapods-core/podfile.rb b/lib/cocoapods-core/podfile.rb index 6062a6b4c..d38e286e0 100644 --- a/lib/cocoapods-core/podfile.rb +++ b/lib/cocoapods-core/podfile.rb @@ -234,7 +234,7 @@ def self.from_file(path) # @return [Podfile] the new Podfile # def self.from_ruby(path) - string = File.open(path, 'r:utf-8') { |f| f.read } + string = File.open(path, 'r:utf-8') { |f| f.read } # Work around for Rubinius incomplete encoding in 1.9 mode if string.respond_to?(:encoding) && string.encoding.name != "UTF-8" string.encode!('UTF-8') @@ -243,7 +243,8 @@ def self.from_ruby(path) begin eval(string, nil, path.to_s) rescue Exception => e - raise DSLError.new("Invalid `#{path.basename}` file: #{e.message}", path, e.backtrace) + message = "Invalid `#{path.basename}` file: #{e.message}" + raise DSLError.new(message, path, e.backtrace) end end podfile @@ -261,7 +262,7 @@ def self.from_ruby(path) # @return [Podfile] the new Podfile # def self.from_yaml(path) - string = File.open(path, 'r:utf-8') { |f| f.read } + string = File.open(path, 'r:utf-8') { |f| f.read } # Work around for Rubinius incomplete encoding in 1.9 mode if string.respond_to?(:encoding) && string.encoding.name != "UTF-8" string.encode!('UTF-8') @@ -314,7 +315,9 @@ def self.from_hash(hash, path = nil) # @return [void] # def set_hash_value(key, value) - raise StandardError, "Unsupported hash key `#{key}`" unless HASH_KEYS.include?(key) + unless HASH_KEYS.include?(key) + raise StandardError, "Unsupported hash key `#{key}`" + end internal_hash[key] = value end @@ -328,7 +331,9 @@ def set_hash_value(key, value) # @return [Object] The value for the key. # def get_hash_value(key) - raise StandardError, "Unsupported hash key `#{key}`" unless HASH_KEYS.include?(key) + unless HASH_KEYS.include?(key) + raise StandardError, "Unsupported hash key `#{key}`" + end internal_hash[key] end diff --git a/lib/cocoapods-core/podfile/dsl.rb b/lib/cocoapods-core/podfile/dsl.rb index ad28b978d..328ff4f63 100644 --- a/lib/cocoapods-core/podfile/dsl.rb +++ b/lib/cocoapods-core/podfile/dsl.rb @@ -36,13 +36,13 @@ class Podfile module DSL # @!group Dependencies - # The Podfile specifies the dependencies of each user target. + # The Podfile specifies the dependencies of each user target. # # * `pod` is the way to declare a specific dependency. # * `podspec` provides an easy creation API for local podspecs. - # * `target` allows you to scope your dependencies to specific + # * `target` allows you to scope your dependencies to specific # targets in your Xcode projects. - + #-----------------------------------------------------------------------# # Specifies a dependency of the project. @@ -149,7 +149,8 @@ module DSL # def pod(name = nil, *requirements, &block) if block - raise StandardError, "Inline specifications are deprecated. Please store the specification in a `podspec` file." + raise StandardError, "Inline specifications are deprecated. " \ + "Please store the specification in a `podspec` file." end unless name @@ -232,7 +233,8 @@ def podspec(options = nil) # def target(name, options = {}) if options && !options.keys.all? { |key| [:exclusive].include?(key) } - raise Informative, "Unsupported options `#{options}` for target `#{name}`" + raise Informative, "Unsupported options `#{options}` for " \ + "target `#{name}`" end parent = current_target_definition @@ -250,9 +252,9 @@ def target(name, options = {}) # These settings are used to control the CocoaPods generated project. # # This starts out simply with stating what `platform` you are working - # on. `xcodeproj` allows you to state specifically which project to - # link with. - + # on. `xcodeproj` allows you to state specifically which project to + # link with. + #-----------------------------------------------------------------------# # Specifies the platform for which a static library should be build. @@ -366,7 +368,7 @@ def link_with(*targets) # # This attribute is inherited by child target definitions. # - # If you would like to inhibit warnings per Pod you can use the + # If you would like to inhibit warnings per Pod you can use the # following syntax: # # pod 'SSZipArchive', :inhibit_warnings => true @@ -493,4 +495,3 @@ def post_install(&block) end end end - diff --git a/lib/cocoapods-core/podfile/target_definition.rb b/lib/cocoapods-core/podfile/target_definition.rb index a75502648..83ddebff8 100644 --- a/lib/cocoapods-core/podfile/target_definition.rb +++ b/lib/cocoapods-core/podfile/target_definition.rb @@ -30,7 +30,7 @@ def initialize(name, parent, internal_hash = nil) @children = [] unless internal_hash - self.name = name + self.name = name end if parent.is_a?(TargetDefinition) parent.children << self @@ -75,7 +75,11 @@ def podfile # definition including the inherited ones. # def dependencies - non_inherited_dependencies + ((exclusive? || parent.nil?) ? [] : parent.dependencies) + if exclusive? || parent.nil? + non_inherited_dependencies + else + non_inherited_dependencies + parent.dependencies + end end # @return [Array] The list of the dependencies of the target definition, @@ -153,8 +157,10 @@ def name=(name) def exclusive? if root? true + elsif get_hash_value('exclusive') + true else - get_hash_value('exclusive') || ( platform && parent && parent.platform != platform ) + platform && parent && parent.platform != platform end end @@ -250,7 +256,11 @@ def user_project_path=(path) # represents their type (`:debug` or `:release`). # def build_configurations - get_hash_value('build_configurations') || (parent.build_configurations unless root?) + if root? + get_hash_value('build_configurations') + else + get_hash_value('build_configurations') || parent.build_configurations + end end # Sets the build configurations for this target. @@ -272,10 +282,14 @@ def build_configurations=(hash) # return true for any asked pod. # def inhibits_warnings_for_pod?(pod_name) - return true if inhibit_warnings_hash['all'] || (parent.inhibits_warnings_for_pod?(pod_name) unless root?) - - inhibit_warnings_hash['for_pods'] ||= [] - inhibit_warnings_hash['for_pods'].include? pod_name + if inhibit_warnings_hash['all'] + true + elsif !root? && parent.inhibits_warnings_for_pod?(pod_name) + true + else + inhibit_warnings_hash['for_pods'] ||= [] + inhibit_warnings_hash['for_pods'].include? pod_name + end end # Sets whether the target definition should inhibit the warnings during @@ -339,11 +353,12 @@ def platform # def set_platform(name, target = nil) unless [:ios, :osx].include?(name) - raise StandardError, "Unsupported platform `#{name}`. Platform must be `:ios` or `:osx`." + raise StandardError, "Unsupported platform `#{name}`. Platform " \ + "must be `:ios` or `:osx`." end if target - value = {name.to_s => target} + value = { name.to_s => target } else value = name.to_s end @@ -401,7 +416,8 @@ def store_pod(name, *requirements) def store_podspec(options = nil) if options unless options.keys.all? { |key| [:name, :path].include?(key) } - raise StandardError, "Unrecognized options for the podspec method `#{options}`" + raise StandardError, "Unrecognized options for the podspec " \ + "method `#{options}`" end get_hash_value('podspecs', []) << options else @@ -488,7 +504,9 @@ def self.from_hash(hash, parent) # @return [void] # def set_hash_value(key, value) - raise StandardError, "Unsupported hash key `#{key}`" unless HASH_KEYS.include?(key) + unless HASH_KEYS.include?(key) + raise StandardError, "Unsupported hash key `#{key}`" + end internal_hash[key] = value end @@ -506,14 +524,16 @@ def set_hash_value(key, value) # @return [Object] The value for the key. # def get_hash_value(key, base_value = nil) - raise StandardError, "Unsupported hash key `#{key}`" unless HASH_KEYS.include?(key) + unless HASH_KEYS.include?(key) + raise StandardError, "Unsupported hash key `#{key}`" + end internal_hash[key] ||= base_value end - # Returns the inhibit_warnings hash prepopulated with default values + # Returns the inhibit_warnings hash pre-populated with default values. # - # @return [Hash] Hash with :all key for inhibiting all warnings, - # and :for_pods key for inhibiting warnings per pod + # @return [Hash] Hash with :all key for inhibiting all + # warnings, and :for_pods key for inhibiting warnings per Pod. # def inhibit_warnings_hash get_hash_value('inhibit_warnings', {}) @@ -550,7 +570,7 @@ def podspec_dependencies file = podspec_path_from_options(options) spec = Specification.from_file(file) all_specs = [spec, *spec.recursive_subspecs] - all_deps = all_specs.map{ |s| s.dependencies(platform) }.flatten + all_deps = all_specs.map { |s| s.dependencies(platform) }.flatten all_deps.reject { |dep| dep.root_name == spec.root.name } end.flatten.uniq end @@ -565,14 +585,19 @@ def podspec_dependencies # def podspec_path_from_options(options) if path = options[:path] - path_with_ext = File.extname(path) == '.podspec' ? path : "#{path}.podspec" + if File.extname(path) == '.podspec' + path_with_ext = path + else + path_with_ext = "#{path}.podspec" + end path_without_tilde = path_with_ext.gsub('~', ENV['HOME']) file = podfile.defined_in_file.dirname + path_without_tilde elsif name = options[:name] name = File.extname(name) == '.podspec' ? name : "#{name}.podspec" file = podfile.defined_in_file.dirname + name elsif options[:autodetect] - file = Pathname.glob(podfile.defined_in_file.dirname + '*.podspec').first + glob_pattern = podfile.defined_in_file.dirname + '*.podspec' + file = Pathname.glob(glob_pattern).first end end @@ -582,7 +607,7 @@ def podspec_path_from_options(options) # @param [String] pod name # # @param [Array] requirements - # If :inhibit_warnings is the only key in the hash, the hash + # If :inhibit_warnings is the only key in the hash, the hash # should be destroyed because it confuses Gem::Dependency. # # @return [void] diff --git a/lib/cocoapods-core/source.rb b/lib/cocoapods-core/source.rb index 8a930d73b..22dc7d12f 100644 --- a/lib/cocoapods-core/source.rb +++ b/lib/cocoapods-core/source.rb @@ -173,12 +173,13 @@ def search_by_name(query, full_text_search = false) s = set.specification text = "#{s.name} #{s.authors} #{s.summary} #{s.description}" rescue - CoreUI.warn "Skipping `#{set.name}` because the podspec contains errors." + CoreUI.warn "Skipping `#{set.name}` because the podspec " \ + "contains errors." end set if text && text.downcase.include?(query.downcase) end.compact else - names = pods.select { |pod_name| pod_name.downcase.include?(query.downcase) } + names = pods.select { |name| name.downcase.include?(query.downcase) } names.map { |pod_name| set(pod_name) } end end diff --git a/lib/cocoapods-core/source/acceptor.rb b/lib/cocoapods-core/source/acceptor.rb index bb6dd4347..6ea642611 100644 --- a/lib/cocoapods-core/source/acceptor.rb +++ b/lib/cocoapods-core/source/acceptor.rb @@ -68,10 +68,11 @@ def check_spec_source_change(spec, errors) source = spec.source.values_at(*keys).compact.first old_source = reference_spec(spec).source.values_at(*keys).compact.first unless source == old_source - errors << "The source of the spec doesn't match with the recorded ones." \ - "Source: `#{source}`. Previous: `#{old_source}`.\n " \ - "Please contact the specs repo maintainers if the library changed " \ - "location." + message = "The source of the spec doesn't match with the recorded " + message << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n " + message << "Please contact the specs repo maintainers if the" + message << "library changed location." + errors << message end end @@ -85,10 +86,12 @@ def check_if_untagged_version_is_acceptable(spec, previous_spec, errors) return if !spec.source[:git] || spec.source[:tag] return unless related_specifications(spec) return if previous_spec - has_tagged_spec = related_specifications(spec).any? { |s| s.version != '0.0.1' } + has_tagged_spec = related_specifications(spec).any? do |s| + s.version != '0.0.1' + end if has_tagged_spec - errors << "There is already at least one versioned specification so " \ - "untagged versions cannot be accepted." + errors << "There is already at least one versioned specification " \ + "so untagged versions cannot be accepted." end end @@ -114,7 +117,8 @@ def check_dependencies(spec, errors) spec.dependencies.each do |dep| set = source.search(dep) unless set && set.specification - errors << "Unable to find a specification for the `#{dep}` dependency." + errors << "Unable to find a specification for the `#{dep}` " \ + "dependency." end end end diff --git a/lib/cocoapods-core/source/aggregate.rb b/lib/cocoapods-core/source/aggregate.rb index e9664c56f..2ad0c962d 100644 --- a/lib/cocoapods-core/source/aggregate.rb +++ b/lib/cocoapods-core/source/aggregate.rb @@ -43,7 +43,8 @@ def all_sets pods = pods_by_source.values.flatten.uniq pods.map do |pod| - pod_sources = sources.select{ |s| pods_by_source[s].include?(pod) }.compact + pod_sources = sources.select { |s| pods_by_source[s].include?(pod) } + pod_sources = pod_sources.compact Specification::Set.new(pod, pod_sources) end end @@ -102,7 +103,9 @@ def represenative_set(name) # def search(dependency) sources = all.select { |s| !s.search(dependency).nil? } - Specification::Set.new(dependency.root_name, sources) unless sources.empty? + unless sources.empty? + Specification::Set.new(dependency.root_name, sources) + end end # @return [Array] the sets that contain the search term. @@ -116,17 +119,22 @@ def search(dependency) def search_by_name(query, full_text_search = false) pods_by_source = {} result = [] - all.each { |s| pods_by_source[s] = s.search_by_name(query, full_text_search).map(&:name) } + all.each do |s| + source_pods = s.search_by_name(query, full_text_search) + pods_by_source[s] = source_pods.map(&:name) + end root_spec_names = pods_by_source.values.flatten.uniq root_spec_names.each do |pod| sources = [] - pods_by_source.each{ |source, pods| sources << source if pods.include?(pod) } + pods_by_source.each do |source, pods| + sources << source if pods.include?(pod) + end result << Specification::Set.new(pod, sources) end if result.empty? extra = ", author, summary, or description" if full_text_search - raise(Informative, "Unable to find a pod with name" \ - "#{extra} matching `#{query}'") + raise Informative, "Unable to find a pod with name" \ + "#{extra} matching `#{query}'" end result end @@ -170,8 +178,12 @@ def update_search_index(search_data) enumerated_names << set.name set_data = search_data[set.name] has_data = set_data && set_data['version'] - needs_update = !has_data || Version.new(set_data['version']) < set.required_version - if needs_update + if has_data + stored_version = Version.new(set_data['version']) + if stored_version < set.required_version + search_data[set.name] = search_data_from_set(set) + end + else search_data[set.name] = search_data_from_set(set) end end @@ -218,7 +230,8 @@ def search_data_from_set(set) result['authors'] = spec.authors.keys.sort * ', ' result rescue - CoreUI.warn "Skipping `#{set.name}` because the podspec contains errors." + CoreUI.warn "Skipping `#{set.name}` because the podspec contains " \ + "errors." result end diff --git a/lib/cocoapods-core/source/health_reporter.rb b/lib/cocoapods-core/source/health_reporter.rb index 9eae066e5..392f4306d 100644 --- a/lib/cocoapods-core/source/health_reporter.rb +++ b/lib/cocoapods-core/source/health_reporter.rb @@ -111,7 +111,8 @@ def lint_spec(name, version, spec_path) # def check_spec_path(name, version, spec) unless spec.name == name && spec.version.to_s == version.to_s - report.add_message(:error, "Incorrect path #{ spec.defined_in_file }", name, spec.version) + message = "Incorrect path #{ spec.defined_in_file }" + report.add_message(:error, message, name, spec.version) end end @@ -198,4 +199,3 @@ def add_message(type, message, spec_name, spec_version = nil) end end end - diff --git a/lib/cocoapods-core/specification.rb b/lib/cocoapods-core/specification.rb index 6a61a707a..06ce09589 100644 --- a/lib/cocoapods-core/specification.rb +++ b/lib/cocoapods-core/specification.rb @@ -126,7 +126,8 @@ def inspect def self.name_and_version_from_string(string_representation) match_data = string_representation.match(/(\S*) \((.*)\)/) unless match_data - raise Informative, "Invalid string representation for a Specification: `#{string_representation}`." + raise Informative, "Invalid string representation for a " \ + "Specification: `#{string_representation}`." end name = match_data[1] vers = Version.new(match_data[2]) @@ -531,7 +532,7 @@ def self.from_file(path, subspec_name = nil) raise Informative, "No podspec exists at path `#{path}`." end - string = File.open(path, 'r:utf-8') { |f| f.read } + string = File.open(path, 'r:utf-8') { |f| f.read } # Work around for Rubinius incomplete encoding in 1.9 mode if string.respond_to?(:encoding) && string.encoding.name != "UTF-8" string.encode!('UTF-8') @@ -606,7 +607,8 @@ def self._eval_podspec(string, path) begin eval(string, nil, path.to_s) rescue Exception => e - raise DSLError.new("Invalid `#{path.basename}` file: #{e.message}", path, e.backtrace) + message = "Invalid `#{path.basename}` file: #{e.message}" + raise DSLError.new(message, path, e.backtrace) end end end diff --git a/lib/cocoapods-core/specification/consumer.rb b/lib/cocoapods-core/specification/consumer.rb index ef32a91ef..f5f2adbd0 100644 --- a/lib/cocoapods-core/specification/consumer.rb +++ b/lib/cocoapods-core/specification/consumer.rb @@ -224,10 +224,12 @@ def raw_value_for_attribute(the_spec, attr) value = the_spec.attributes_hash[attr.name.to_s] value = prepare_value(attr, value) - if attr.multi_platform? && the_spec.attributes_hash[platform_name.to_s] - platform_value = the_spec.attributes_hash[platform_name.to_s][attr.name.to_s] - platform_value = prepare_value(attr, platform_value) - value = merge_values(attr, value, platform_value) + if attr.multi_platform? + if platform_hash = the_spec.attributes_hash[platform_name.to_s] + platform_value = platform_hash[attr.name.to_s] + platform_value = prepare_value(attr, platform_value) + value = merge_values(attr, value, platform_value) + end end value end diff --git a/lib/cocoapods-core/specification/dsl.rb b/lib/cocoapods-core/specification/dsl.rb index 78c9c19c5..0c19ef0d3 100644 --- a/lib/cocoapods-core/specification/dsl.rb +++ b/lib/cocoapods-core/specification/dsl.rb @@ -124,7 +124,7 @@ module DSL # the list of the authors of the library and their emails. # root_attribute :authors, { - :types => [ String, Array, Hash ], + :types => [String, Array, Hash], :container => Hash, :required => true, :singularize => true, @@ -134,7 +134,7 @@ module DSL # The keys accepted by the license attribute. # - LICENSE_KEYS = [ :type, :file, :text ].freeze + LICENSE_KEYS = [:type, :file, :text].freeze # @!method license=(license) # @@ -396,9 +396,7 @@ module DSL def platform=(args) name, deployment_target = args if name - attributes_hash["platforms"] = { - name.to_s => deployment_target - } + attributes_hash["platforms"] = { name.to_s => deployment_target } else attributes_hash["platforms"] = {} end @@ -451,7 +449,8 @@ def platform=(args) # The deployment target of the platform. # def deployment_target=(*args) - raise Informative, "The deployment target can be declared only per platform." + raise Informative, "The deployment target can be declared only per " \ + "platform." end #-----------------------------------------------------------------------# @@ -497,19 +496,25 @@ def deployment_target=(*args) # def dependency(*args) name, *version_requirements = args - raise Informative, "A specification can't require itself as a subspec" if name == self.name + if name == self.name + raise Informative, "A specification can't require itself as a " \ + "subspec" + end if @parent composed_name = "" @parent.name.split("/").each do |component| composed_name << component if name == composed_name - raise Informative, "A subspec can't require one of its parents specifications" + raise Informative, "A subspec can't require one of its " \ + "parents specifications" break end composed_name << "/" end end - raise Informative, "Unsupported version requirements" unless version_requirements.all? { |req| req.is_a?(String) } + unless version_requirements.all? { |req| req.is_a?(String) } + raise Informative, "Unsupported version requirements" + end attributes_hash["dependencies"] ||= {} attributes_hash["dependencies"][name] = version_requirements end diff --git a/lib/cocoapods-core/specification/dsl/attribute.rb b/lib/cocoapods-core/specification/dsl/attribute.rb index 18f659563..0f901e050 100644 --- a/lib/cocoapods-core/specification/dsl/attribute.rb +++ b/lib/cocoapods-core/specification/dsl/attribute.rb @@ -59,7 +59,7 @@ def to_s # def inspect "<#{self.class} name=#{self.name} types=#{types} " \ - "multi_platform=#{multi_platform?}>" + "multi_platform=#{multi_platform?}>" end #---------------------------------------------------------------------# @@ -209,7 +209,8 @@ def validate_type(value) # def validate_for_writing(spec, value) if root_only? && !spec.root? - raise StandardError, "Can't set `#{name}` attribute for subspecs (in `#{spec.name}`)." + raise StandardError, "Can't set `#{name}` attribute for " \ + "subspecs (in `#{spec.name}`)." end if keys diff --git a/lib/cocoapods-core/specification/dsl/deprecations.rb b/lib/cocoapods-core/specification/dsl/deprecations.rb index dc34468e8..037028f22 100644 --- a/lib/cocoapods-core/specification/dsl/deprecations.rb +++ b/lib/cocoapods-core/specification/dsl/deprecations.rb @@ -8,59 +8,73 @@ module Deprecations def preferred_dependency=(name) self.default_subspec = name - CoreUI.warn "[#{to_s}] `preferred_dependency` has been renamed to `default_subspec`." + CoreUI.warn "[#{to_s}] `preferred_dependency` has been renamed "\ + "to `default_subspec`." end def singleton_method_added(method) if method == :pre_install - CoreUI.warn "[#{to_s}] The use of `#{method}` by overriding the method is deprecated." + CoreUI.warn "[#{to_s}] The use of `#{method}` by overriding " \ + "the method is deprecated." @pre_install_callback = Proc.new do |pod, target_definition| self.pre_install(pod, target_definition) end elsif method == :post_install - CoreUI.warn "[#{to_s}] The use of `#{method}` by overriding the method is deprecated." + CoreUI.warn "[#{to_s}] The use of `#{method}` by overriding the " \ + "method is deprecated." @post_install_callback = Proc.new do |target_installer| self.post_install(target_installer) end elsif method == :header_mappings - raise Informative, "[#{to_s}] The use of the `header_mappings` hook has been deprecated.\n" \ - "Use the `header_dir` and the `header_mappings_dir` attributes." + raise Informative, "[#{to_s}] The use of the `header_mappings` " \ + "hook has been deprecated.\n Use the `header_dir` and the " \ + "`header_mappings_dir` attributes." elsif method == :copy_header_mapping - raise Informative, "[#{to_s}] The use of the `copy_header_mapping` hook has been deprecated.\n" \ - "Use the `header_dir` and the `header_mappings_dir` attributes." + raise Informative, "[#{to_s}] The use of the " \ + "`copy_header_mapping` hook has been deprecated.\nUse" \ + "the `header_dir` and the `header_mappings_dir` attributes." end end def documentation=(value) - CoreUI.warn "[#{to_s}] The `documentation` DSL directive of the podspec format has been deprecated." + CoreUI.warn "[#{to_s}] The `documentation` DSL directive of the " \ + "podspec format has been deprecated." end def clean_paths=(value) - raise Informative, "[#{to_s}] Clean paths are deprecated. CocoaPods now " \ - "cleans unused files by default. Use the `preserve_paths` attribute if needed." + raise Informative, "[#{to_s}] Clean paths are deprecated. " \ + "CocoaPods now cleans unused files by default. Use the " \ + "`preserve_paths` attribute if needed." end - [ :part_of_dependency=, :part_of=, :exclude_header_search_paths= ].each do |method| + DEPRECATED_METHODS = [ + :part_of_dependency=, + :part_of=, + :exclude_header_search_paths= + ] + + DEPRECATED_METHODS.each do |method| define_method method do |value| - raise Informative, "[#{to_s}] Attribute `#{method.to_s[0..-2]}` has been deprecated." + raise Informative, "[#{to_s}] Attribute "\ + "`#{method.to_s[0..-2]}` has been deprecated." end end # @!group Hooks # - # The specification class provides hooks which are called by CocoaPods - # when a Pod is installed. + # The specification class provides hooks which are called by + # CocoaPods when a Pod is installed. #-----------------------------------------------------------------------# - # This is a convenience method which gets called after all pods have been - # downloaded but before they have been installed, and the Xcode project - # and related files have been generated. Note that this hook is called - # for each Pods library and only for installations where the Pod is - # installed. + # This is a convenience method which gets called after all pods have + # been downloaded but before they have been installed, and the Xcode + # project and related files have been generated. Note that this hook is + # called for each Pods library and only for installations where the Pod + # is installed. # # This hook should be used to generate and modify the files of the Pod. # diff --git a/lib/cocoapods-core/specification/dsl/platform_proxy.rb b/lib/cocoapods-core/specification/dsl/platform_proxy.rb index 3fbc01a3f..712cda7f3 100644 --- a/lib/cocoapods-core/specification/dsl/platform_proxy.rb +++ b/lib/cocoapods-core/specification/dsl/platform_proxy.rb @@ -11,8 +11,8 @@ class PlatformProxy # attr_accessor :spec - # @return [Symbol] the platform described by this proxy. Can be either `:ios` or - # `:osx`. + # @return [Symbol] the platform described by this proxy. Can be either + # `:ios` or `:osx`. # attr_accessor :platform @@ -23,15 +23,19 @@ def initialize(spec, platform) @spec, @platform = spec, platform end - # Defines a setter method for each attribute of the specification class, - # that forwards the message to the {#specification} using the + # Defines a setter method for each attribute of the specification + # class, that forwards the message to the {#specification} using the # {Specification#on_platform} method. # # @return [void] # def method_missing(meth, *args, &block) attr = Specification::DSL.attributes.values.find do |attr| - attr.writer_name.to_sym == meth || (attr.writer_singular_form && attr.writer_singular_form.to_sym == meth) + if attr.writer_name.to_sym == meth + true + elsif attr.writer_singular_form + attr.writer_singular_form.to_sym == meth + end end if attr && attr.multi_platform? spec.store_attribute(attr.name, args.first, platform) @@ -47,9 +51,10 @@ def method_missing(meth, *args, &block) def dependency(*args) name, *version_requirements = args platform_name = platform.to_s - spec.attributes_hash[platform_name] ||= {} - spec.attributes_hash[platform_name]["dependencies"] ||= {} - spec.attributes_hash[platform_name]["dependencies"][name] = version_requirements + platform_hash = spec.attributes_hash[platform_name] || {} + platform_hash["dependencies"] ||= {} + platform_hash["dependencies"][name] = version_requirements + spec.attributes_hash[platform_name] = platform_hash end # Allows to set the deployment target for the platform. diff --git a/lib/cocoapods-core/specification/linter.rb b/lib/cocoapods-core/specification/linter.rb index f0a6b3544..5674aa881 100644 --- a/lib/cocoapods-core/specification/linter.rb +++ b/lib/cocoapods-core/specification/linter.rb @@ -90,13 +90,23 @@ def warnings def perform_textual_analysis return unless @file text = @file.read - error "`config.ios?` and `config.osx?` are deprecated." if text =~ /config\..?os.?/ - error "clean_paths are deprecated (use preserve_paths)." if text =~ /clean_paths/ + if text =~ /config\..?os.?/ + error "`config.ios?` and `config.osx?` are deprecated." + end + if text =~ /clean_paths/ + error "clean_paths are deprecated (use preserve_paths)." + end + all_lines_count = text.lines.count comments_lines_count = text.scan(/^\s*#\s+/).length comments_ratio = comments_lines_count.fdiv(all_lines_count) - warning "Comments must be deleted." if comments_lines_count > 20 && comments_ratio > 0.2 - warning "Comments placed at the top of the specification must be deleted." if text.lines.first =~ /^\s*#\s+/ + if comments_lines_count > 20 && comments_ratio > 0.2 + warning "Comments must be deleted." + end + if text.lines.first =~ /^\s*#\s+/ + warning "Comments placed at the top of the specification must be " \ + "deleted." + end end # Checks that every root only attribute which is required has a value. @@ -138,7 +148,7 @@ def run_root_validation_hooks # @return [void] # def perform_all_specs_analysis - all_specs = [ spec, *spec.recursive_subspecs ] + all_specs = [spec, *spec.recursive_subspecs] all_specs.each do |current_spec| current_spec.available_platforms.each do |platform| @consumer = Specification::Consumer.new(current_spec, platform) @@ -193,7 +203,11 @@ def run_validation_hooks(attributes) # def _validate_name(n) if spec.name && file - names_match = (file.basename.to_s == spec.root.name + '.podspec') || (file.basename.to_s == spec.root.name + '.podspec.yaml') + acceptable_names = [ + spec.root.name + '.podspec', + spec.root.name + '.podspec.yaml' + ] + names_match = acceptable_names.include?(file.basename.to_s) unless names_match error "The name of the spec should match the name of the file." end @@ -203,33 +217,50 @@ def _validate_name(n) def _validate_version(v) if v.to_s.empty? error "A version is required." - else - error "The version of the spec should be higher than 0." unless v > Version::ZERO + elsif v <= Version::ZERO + error "The version of the spec should be higher than 0." end end # Performs validations related to the `summary` attribute. # def _validate_summary(s) - warning "The summary should be a short version of `description` (max 140 characters)." if s.length > 140 - warning "The summary is not meaningful." if s =~ /A short description of/ + if s.length > 140 + warning "The summary should be a short version of `description` " \ + "(max 140 characters)." + end + if s =~ /A short description of/ + warning "The summary is not meaningful." + end end # Performs validations related to the `description` attribute. # def _validate_description(d) - warning "The description is not meaningful." if d =~ /An optional longer description of/ - warning "The description is equal to the summary." if d == spec.summary - warning "The description is shorter than the summary." if d.length < spec.summary.length + if d =~ /An optional longer description of/ + warning "The description is not meaningful." + end + if d == spec.summary + warning "The description is equal to the summary." + end + if d.length < spec.summary.length + warning "The description is shorter than the summary." + end end # Performs validations related to the `license` attribute. # def _validate_license(l) type = l[:type] - warning "Missing license type." if type.nil? - warning "Invalid license type." if type && type.gsub(' ', '').gsub("\n", '').empty? - error "Sample license type." if type && type =~ /\(example\)/ + if type.nil? + warning "Missing license type." + end + if type && type.gsub(' ', '').gsub("\n", '').empty? + warning "Invalid license type." + end + if type && type =~ /\(example\)/ + error "Sample license type." + end end # Performs validations related to the `source` attribute. @@ -237,21 +268,49 @@ def _validate_license(l) def _validate_source(s) if git = s[:git] tag, commit = s.values_at(:tag, :commit) - github = git.include?('github.com') - version = spec.version.to_s + version = spec.version.to_s - error "Example source." if git =~ /http:\/\/EXAMPLE/ - error 'The commit of a Git source cannot be `HEAD`.' if commit && commit.downcase =~ /head/ - warning 'The version should be included in the Git tag.' if tag && !tag.include?(version) - warning "Github repositories should end in `.git`." if github && !git.end_with?('.git') - warning "Github repositories should use `https` link." if github && !git.start_with?('https://github.com') && !git.start_with?('git://gist.github.com') + if git =~ /http:\/\/EXAMPLE/ + error "Example source." + end + if commit && commit.downcase =~ /head/ + error 'The commit of a Git source cannot be `HEAD`.' + end + if tag && !tag.include?(version) + warning 'The version should be included in the Git tag.' + end if version == '0.0.1' - error 'Git sources should specify either a commit or a tag.' if commit.nil? && tag.nil? + if commit.nil? && tag.nil? + error 'Git sources should specify either a commit or a tag.' + end else warning 'Git sources should specify a tag.' if tag.nil? end end + + perform_github_source_checks(s) + end + + # Performs validations related to github sources. + # + def perform_github_source_checks(s) + supported_domains = [ + 'https://github.com', + 'git://gist.github.com', + ] + + if git = s[:git] + is_github = git.include?('github.com') + if is_github + if !git.end_with?('.git') + warning "Github repositories should end in `.git`." + end + unless supported_domains.find { |domain| git.start_with?(domain) } + warning "Github repositories should use `https` link." + end + end + end end #-----------------------------------------------------------------------# @@ -281,7 +340,8 @@ def validate_file_patterns end patterns.each do |pattern| if pattern.start_with?('/') - error "File patterns must be relative and cannot start with a slash (#{attrb.name})." + error "File patterns must be relative and cannot start with a " \ + "slash (#{attrb.name})." end end end @@ -291,7 +351,8 @@ def validate_file_patterns # def check_tmp_arc_not_nil if consumer.requires_arc.nil? - warning "A value for `requires_arc` should be specified until the migration to a `true` default." + warning "A value for `requires_arc` should be specified until the " \ + "migration to a `true` default." end end @@ -302,20 +363,25 @@ def check_if_spec_is_empty empty_patterns = methods.all? { |m| consumer.send(m).empty? } empty = empty_patterns && consumer.spec.subspecs.empty? if empty - error "The #{consumer.spec} spec is empty (no source files, resources, preserve paths, dependencies or subspecs)." + error "The #{consumer.spec} spec is empty (no source files, " \ + "resources, preserve paths, dependencies or subspecs)." end end # Check the hooks # def check_install_hooks - warning "The pre install hook of the specification DSL has been " \ - "deprecated, use the `resource_bundles` or the `prepare_command` " \ - "attributes." unless consumer.spec.pre_install_callback.nil? + unless consumer.spec.pre_install_callback.nil? + warning "The pre install hook of the specification DSL has been " \ + "deprecated, use the `resource_bundles` or the " \ + "`prepare_command` attributes." + end - warning "The post install hook of the specification DSL has been " \ - "deprecated, use the `resource_bundles` or the `prepare_command` " \ - "attributes." unless consumer.spec.post_install_callback.nil? + unless consumer.spec.post_install_callback.nil? + warning "The post install hook of the specification DSL has been " \ + "deprecated, use the `resource_bundles` or the " \ + " `prepare_command` attributes." + end end #-----------------------------------------------------------------------# @@ -399,7 +465,9 @@ def initialize(type, message) def to_s r = "[#{type.to_s.upcase}] #{message}" if platforms != Specification::PLATFORMS - platforms_names = platforms.uniq.map { |p| Platform.string_name(p) } + platforms_names = platforms.uniq.map do |p| + Platform.string_name(p) + end r << " [#{platforms_names * ' - '}]" unless platforms.empty? end r diff --git a/lib/cocoapods-core/specification/root_attribute_accessors.rb b/lib/cocoapods-core/specification/root_attribute_accessors.rb index 0edc2ef0d..5bef10658 100644 --- a/lib/cocoapods-core/specification/root_attribute_accessors.rb +++ b/lib/cocoapods-core/specification/root_attribute_accessors.rb @@ -29,7 +29,11 @@ def name # robust handling of head versions (like a dedicated section). # def version - @version ||= root? ? Version.new(attributes_hash["version"]) : root.version + if root? + @version ||= Version.new(attributes_hash["version"]) + else + @version ||= root.version + end end # @return [Hash] a hash containing the authors as the keys and their @@ -108,8 +112,8 @@ def description description.strip_heredoc if description end - # @return [Array] The list of the URL for the screenshots of the - # Pod. + # @return [Array] The list of the URL for the screenshots of + # the Pod. # # @note The value is coerced to an array. # @@ -130,7 +134,7 @@ def prepare_command attributes_hash["prepare_command"] end - #-----------------------------------------------------------------------# + #---------------------------------------------------------------------# private @@ -151,6 +155,8 @@ def convert_keys_to_symbol(value) result end + #---------------------------------------------------------------------# + end end end diff --git a/lib/cocoapods-core/specification/set.rb b/lib/cocoapods-core/specification/set.rb index 0b1d117c0..e49474f84 100644 --- a/lib/cocoapods-core/specification/set.rb +++ b/lib/cocoapods-core/specification/set.rb @@ -1,5 +1,4 @@ require 'active_support/core_ext/array/conversions' - require 'cocoapods-core/specification/set/presenter' require 'cocoapods-core/specification/set/statistics' @@ -60,15 +59,18 @@ def initialize(name, sources = []) # @return [void] # def required_by(dependency, dependent_name) - unless @required_by.empty? || dependency.requirement.satisfied_by?(Version.new(required_version.to_s)) - raise Informative, "#{dependent_name} tries to activate `#{dependency}', but already activated version `#{required_version}' by #{@required_by.to_sentence}." + # TODO + unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version) + raise Informative, "#{dependent_name} tries to activate " \ + "`#{dependency}', but already activated version " \ + "`#{required_version}' by #{@required_by.to_sentence}." end @specification = nil @required_by << dependent_name @dependencies << dependency end - # @return [Dependency] a dependency that includes all the versions + # @return [Dependency] A dependency that includes all the versions # requirements of the stored dependencies. # def dependency @@ -85,9 +87,12 @@ def dependency # used to disambiguate. # def specification - @specification ||= Specification.from_file(specification_path_for_version(required_version)) + path = specification_path_for_version(required_version) + @specification ||= Specification.from_file(path) end + # TODO + # def specification_path_for_version(version) sources = [] versions_by_source.each do |source, source_versions| @@ -142,11 +147,14 @@ def versions_by_source end def ==(other) - self.class === other && @name == other.name && @sources.map(&:name) == other.sources.map(&:name) + self.class === other && + @name == other.name && + @sources.map(&:name) == other.sources.map(&:name) end def to_s - "#<#{self.class.name} for `#{name}' with required version `#{required_version}' available at `#{sources.map(&:name) * ', '}'>" + "#<#{self.class.name} for `#{name}' with required version " \ + "`#{required_version}' available at `#{sources.map(&:name) * ', '}'>" end alias_method :inspect, :to_s diff --git a/lib/cocoapods-core/specification/set/presenter.rb b/lib/cocoapods-core/specification/set/presenter.rb index e5172124f..3f8c9a40f 100644 --- a/lib/cocoapods-core/specification/set/presenter.rb +++ b/lib/cocoapods-core/specification/set/presenter.rb @@ -128,7 +128,7 @@ def description # @return [String] the URL of the source of the Pod. # def source_url - url_keys = [:git, :svn, :http, :hg, :path ] + url_keys = [:git, :svn, :http, :hg, :path] key = spec.source.keys.find { |k| url_keys.include?(k) } key ? spec.source[key] : 'No source url' end @@ -141,7 +141,10 @@ def source_url # "iOS - OS X" # def platform - spec.available_platforms.sort { |a,b| a.to_s.downcase <=> b.to_s.downcase }.join(' - ') + sorted_platforms = spec.available_platforms.sort do |a,b| + a.to_s.downcase <=> b.to_s.downcase + end + sorted_platforms.join(' - ') end # @return [String] the type of the license of the Pod. @@ -234,4 +237,3 @@ def distance_from_now_in_words(from_time) end end end - diff --git a/lib/cocoapods-core/specification/yaml.rb b/lib/cocoapods-core/specification/yaml.rb index b9c9ca797..520c6547e 100644 --- a/lib/cocoapods-core/specification/yaml.rb +++ b/lib/cocoapods-core/specification/yaml.rb @@ -13,7 +13,9 @@ def to_yaml # def to_hash hash = attributes_hash.dup - hash["subspecs"] = subspecs.map { |spec| spec.to_hash } unless subspecs.empty? + unless subspecs.empty? + hash["subspecs"] = subspecs.map { |spec| spec.to_hash } + end hash end @@ -39,7 +41,9 @@ def self.from_hash(hash, parent = nil) subspecs = attributes_hash.delete('subspecs') spec.attributes_hash = attributes_hash if subspecs - spec.subspecs = subspecs.map { |s_hash| Specification.from_hash(s_hash, spec) } + spec.subspecs = subspecs.map do |s_hash| + Specification.from_hash(s_hash, spec) + end end spec end diff --git a/lib/cocoapods-core/standard_error.rb b/lib/cocoapods-core/standard_error.rb index 0f6570f22..62c5cfeb9 100644 --- a/lib/cocoapods-core/standard_error.rb +++ b/lib/cocoapods-core/standard_error.rb @@ -67,8 +67,8 @@ def message lines = File.readlines(dsl_path.to_s) indent = " # " indicator = indent.dup.gsub("#", ">") - first_line = ( line_numer.zero? ) - last_line = ( line_numer == (lines.count - 1) ) + first_line = (line_numer.zero?) + last_line = (line_numer == (lines.count - 1)) m << "\n" m << "#{indent}from #{trace_line.gsub(/:in.*$/,'')}\n" diff --git a/lib/cocoapods-core/vendor.rb b/lib/cocoapods-core/vendor.rb index 10c2c4176..9a246ccba 100644 --- a/lib/cocoapods-core/vendor.rb +++ b/lib/cocoapods-core/vendor.rb @@ -52,4 +52,3 @@ module Gem end end end - diff --git a/lib/cocoapods-core/vendor/version.rb b/lib/cocoapods-core/vendor/version.rb index f9c846f57..6829cc7b7 100644 --- a/lib/cocoapods-core/vendor/version.rb +++ b/lib/cocoapods-core/vendor/version.rb @@ -142,192 +142,195 @@ module Pod::Vendor # "~> 3.5" 3.5 ... 4.0 # "~> 3.5.0" 3.5.0 ... 3.6 - class Gem::Version - autoload :Requirement, 'rubygems/requirement' + module Gem + class Version + autoload :Requirement, 'rubygems/requirement' - include Comparable + include Comparable - VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z]+)*' # :nodoc: - ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})*\s*\z/ # :nodoc: + VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z]+)*' # :nodoc: + ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})*\s*\z/ # :nodoc: - ## - # A string representation of this Version. + ## + # A string representation of this Version. - attr_reader :version - alias to_s version + attr_reader :version + alias to_s version - ## - # True if the +version+ string matches RubyGems' requirements. + ## + # True if the +version+ string matches RubyGems' requirements. - def self.correct? version - version.to_s =~ ANCHORED_VERSION_PATTERN - end + def self.correct? version + version.to_s =~ ANCHORED_VERSION_PATTERN + end - ## - # Factory method to create a Version object. Input may be a Version - # or a String. Intended to simplify client code. - # - # ver1 = Version.create('1.3.17') # -> (Version object) - # ver2 = Version.create(ver1) # -> (ver1) - # ver3 = Version.create(nil) # -> nil - - def self.create input - if input.respond_to? :version then - input - elsif input.nil? then - nil - else - new input + ## + # Factory method to create a Version object. Input may be a Version + # or a String. Intended to simplify client code. + # + # ver1 = Version.create('1.3.17') # -> (Version object) + # ver2 = Version.create(ver1) # -> (ver1) + # ver3 = Version.create(nil) # -> nil + + def self.create input + if input.respond_to? :version then + input + elsif input.nil? then + nil + else + new input + end end - end - ## - # Constructs a Version from the +version+ string. A version string is a - # series of digits or ASCII letters separated by dots. + ## + # Constructs a Version from the +version+ string. A version string is a + # series of digits or ASCII letters separated by dots. - def initialize version - raise ArgumentError, "Malformed version number string #{version}" unless - self.class.correct?(version) + def initialize version + unless self.class.correct?(version) + raise ArgumentError, "Malformed version number string #{version}" + end - @version = version.to_s - @version.strip! - end + @version = version.to_s + @version.strip! + end - ## - # Return a new version object where the next to the last revision - # number is one greater (e.g., 5.3.1 => 5.4). - # - # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored. + ## + # Return a new version object where the next to the last revision + # number is one greater (e.g., 5.3.1 => 5.4). + # + # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored. - def bump - segments = self.segments.dup - segments.pop while segments.any? { |s| String === s } - segments.pop if segments.size > 1 + def bump + segments = self.segments.dup + segments.pop while segments.any? { |s| String === s } + segments.pop if segments.size > 1 - segments[-1] = segments[-1].succ - self.class.new segments.join(".") - end + segments[-1] = segments[-1].succ + self.class.new segments.join(".") + end - ## - # A Version is only eql? to another version if it's specified to the - # same precision. Version "1.0" is not the same as version "1". + ## + # A Version is only eql? to another version if it's specified to the + # same precision. Version "1.0" is not the same as version "1". - def eql? other - self.class === other and @version == other.version - end + def eql? other + self.class === other and @version == other.version + end - def hash # :nodoc: - @hash ||= segments.hash - end + def hash # :nodoc: + @hash ||= segments.hash + end - def init_with coder # :nodoc: - yaml_initialize coder.tag, coder.map - end + def init_with coder # :nodoc: + yaml_initialize coder.tag, coder.map + end - def inspect # :nodoc: - "#<#{self.class} #{version.inspect}>" - end + def inspect # :nodoc: + "#<#{self.class} #{version.inspect}>" + end - ## - # Dump only the raw version string, not the complete object. It's a - # string for backwards (RubyGems 1.3.5 and earlier) compatibility. + ## + # Dump only the raw version string, not the complete object. It's a + # string for backwards (RubyGems 1.3.5 and earlier) compatibility. - def marshal_dump - [version] - end + def marshal_dump + [version] + end - ## - # Load custom marshal format. It's a string for backwards (RubyGems - # 1.3.5 and earlier) compatibility. + ## + # Load custom marshal format. It's a string for backwards (RubyGems + # 1.3.5 and earlier) compatibility. - def marshal_load array - initialize array[0] - end + def marshal_load array + initialize array[0] + end - def yaml_initialize(tag, map) - @version = map['version'] - @segments = nil - @hash = nil - end + def yaml_initialize(tag, map) + @version = map['version'] + @segments = nil + @hash = nil + end - ## - # A version is considered a prerelease if it contains a letter. + ## + # A version is considered a prerelease if it contains a letter. - def prerelease? - @prerelease ||= @version =~ /[a-zA-Z]/ - end + def prerelease? + @prerelease ||= @version =~ /[a-zA-Z]/ + end - def pretty_print q # :nodoc: - q.text "Gem::Version.new(#{version.inspect})" - end + def pretty_print q # :nodoc: + q.text "Gem::Version.new(#{version.inspect})" + end - ## - # The release for this version (e.g. 1.2.0.a -> 1.2.0). - # Non-prerelease versions return themselves. + ## + # The release for this version (e.g. 1.2.0.a -> 1.2.0). + # Non-prerelease versions return themselves. - def release - return self unless prerelease? + def release + return self unless prerelease? - segments = self.segments.dup - segments.pop while segments.any? { |s| String === s } - self.class.new segments.join('.') - end + segments = self.segments.dup + segments.pop while segments.any? { |s| String === s } + self.class.new segments.join('.') + end - def segments # :nodoc: + def segments # :nodoc: - # segments is lazy so it can pick up version values that come from - # old marshaled versions, which don't go through marshal_load. + # segments is lazy so it can pick up version values that come from + # old marshaled versions, which don't go through marshal_load. - @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s| - /^\d+$/ =~ s ? s.to_i : s - end - end + @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s| + /^\d+$/ =~ s ? s.to_i : s + end + end - ## - # A recommended version for use with a ~> Requirement. + ## + # A recommended version for use with a ~> Requirement. - def spermy_recommendation - segments = self.segments.dup + def spermy_recommendation + segments = self.segments.dup - segments.pop while segments.any? { |s| String === s } - segments.pop while segments.size > 2 - segments.push 0 while segments.size < 2 + segments.pop while segments.any? { |s| String === s } + segments.pop while segments.size > 2 + segments.push 0 while segments.size < 2 - "~> #{segments.join(".")}" - end + "~> #{segments.join(".")}" + end - ## - # Compares this version with +other+ returning -1, 0, or 1 if the - # other version is larger, the same, or smaller than this - # one. Attempts to compare to something that's not a - # Gem::Version return +nil+. + ## + # Compares this version with +other+ returning -1, 0, or 1 if the + # other version is larger, the same, or smaller than this + # one. Attempts to compare to something that's not a + # Gem::Version return +nil+. - def <=> other - return unless Gem::Version === other - return 0 if @version == other.version + def <=> other + return unless Gem::Version === other + return 0 if @version == other.version - lhsegments = segments - rhsegments = other.segments + lhsegments = segments + rhsegments = other.segments - lhsize = lhsegments.size - rhsize = rhsegments.size - limit = (lhsize > rhsize ? lhsize : rhsize) - 1 + lhsize = lhsegments.size + rhsize = rhsegments.size + limit = (lhsize > rhsize ? lhsize : rhsize) - 1 - i = 0 + i = 0 - while i <= limit - lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0 - i += 1 + while i <= limit + lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0 + i += 1 - next if lhs == rhs - return -1 if String === lhs && Numeric === rhs - return 1 if Numeric === lhs && String === rhs + next if lhs == rhs + return -1 if String === lhs && Numeric === rhs + return 1 if Numeric === lhs && String === rhs - return lhs <=> rhs - end + return lhs <=> rhs + end - return 0 + return 0 + end end - end + end end diff --git a/lib/cocoapods-core/version.rb b/lib/cocoapods-core/version.rb index e4748a864..abe79419a 100644 --- a/lib/cocoapods-core/version.rb +++ b/lib/cocoapods-core/version.rb @@ -106,8 +106,8 @@ def self.correct? version # @!group Semantic Versioning - SEMANTIC_VERSION_PATTERN = '[0-9]+(\.[0-9]+(\.[0-9]+(-[0-9A-Za-z\-\.]+)?)?)?' - ANCHORED_SEMANTIC_VERSION_PATTERN = /\A\s*(#{SEMANTIC_VERSION_PATTERN})*\s*\z/ + SEMVER_PATTERN = '[0-9]+(\.[0-9]+(\.[0-9]+(-[0-9A-Za-z\-\.]+)?)?)?' + ANCHORED_SEMANTIC_VERSION_PATTERN = /\A\s*(#{SEMVER_PATTERN})*\s*\z/ # @return [Bool] Whether the version conforms to the Semantic Versioning # specification (2.0.0-rc.1). @@ -142,4 +142,3 @@ def patch end end - diff --git a/lib/cocoapods-core/yaml_converter.rb b/lib/cocoapods-core/yaml_converter.rb index bc587334e..0f2604ba6 100644 --- a/lib/cocoapods-core/yaml_converter.rb +++ b/lib/cocoapods-core/yaml_converter.rb @@ -67,7 +67,8 @@ def process_according_to_class(value, hash_keys_hint = nil) when Array then process_array(value) when Hash then process_hash(value, hash_keys_hint) else - raise StandardError, "Unsupported class for YAML conversion #{value.class}" + raise StandardError, "Unsupported class for YAML conversion " \ + "#{value.class}" end end From 27aab70efe2053977b4e20b610a3e9a68ba7b445 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Wed, 30 Oct 2013 11:33:29 +0100 Subject: [PATCH 07/11] [Tailor] Improve settings --- .tailor | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.tailor b/.tailor index 848c2f54b..fb8c3cebe 100644 --- a/.tailor +++ b/.tailor @@ -1,3 +1,5 @@ +require 'rake/file_list' + #------------------------------------------------------------------------------ # Horizontal Whitespace #------------------------------------------------------------------------------ @@ -81,7 +83,23 @@ # Tailor.config do |config| config.formatters "text" - config.file_set 'lib/**/*.rb' do |style| + + config.file_set 'lib/cocoapods-core/specification/dsl/attribute.rb', :dsl do |style| + style.spaces_before_rbrace 1, level: :off + style.spaces_before_lbrace 1, level: :off + style.spaces_before_rbracket 1, level: :off + end + + excluded = [ + "lib/cocoapods-core/specification/dsl/attribute.rb", + "lib/cocoapods-core/vendor/*.rb", + "lib/cocoapods-core/specification/dsl/deprecations.rb", # Bug with indentation check + ] + file_list = Rake::FileList['lib/**/*.rb'] + excluded.each { |file| file_list.exclude(file) } + files = file_list.to_a + + config.file_set(files) do |style| style.allow_camel_case_methods false, level: :error style.allow_hard_tabs false, level: :error style.allow_screaming_snake_case_classes false, level: :error From 83190cb39e332c0c31fc1264574df5f90d0ea80c Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Wed, 30 Oct 2013 11:33:49 +0100 Subject: [PATCH 08/11] [Bundle] Update --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 358c4a47b..f1ab22777 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,7 +49,7 @@ GEM log_switch (0.4.0) metaclass (0.0.1) method_source (0.8.2) - mime-types (1.25) + mime-types (2.0) mocha (0.11.4) metaclass (~> 0.0.1) mocha-on-bacon (0.2.1) From 923fe4fa5b3676e0311142aca54df5c529277f2e Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Wed, 30 Oct 2013 11:34:01 +0100 Subject: [PATCH 09/11] [Rakefile] Minor fixes --- Rakefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index f9c80398a..f9f5ea931 100644 --- a/Rakefile +++ b/Rakefile @@ -118,9 +118,11 @@ namespace :spec do task :all do ENV['GENERATE_COVERAGE'] = 'true' sh "bundle exec bacon #{specs('**')}" + puts "Checking code style..." + Rake::Task["tailor"].invoke end - desc "Checks that the gem is campable of loading all the specs of the master repo." + desc "Checks that the gem is capable of loading all the specs of the master repo." task :repo do puts "Checking compatibility with master repo" require 'pathname' @@ -194,12 +196,12 @@ desc "Run all specs" task :spec => 'spec:all' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9.3') -require 'tailor/rake_task' -Tailor::RakeTask.new + require 'tailor/rake_task' + Tailor::RakeTask.new else desc "Check style" task :tailor do - puts "[!] Ruby > 1.9 is required to run tailor" + puts "[!] Ruby > 1.9 is required to run style checks" end end From e4191be93c31571c392b2c4e746e8de545a9c89a Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Wed, 30 Oct 2013 12:10:18 +0100 Subject: [PATCH 10/11] [Specification::Set] Improve required_by_logic --- lib/cocoapods-core/specification/set.rb | 52 ++++++++++++------- .../specification/set/presenter.rb | 2 +- spec/specification/set/statistics_spec.rb | 2 +- spec/specification/set_spec.rb | 32 +++++++++--- 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/lib/cocoapods-core/specification/set.rb b/lib/cocoapods-core/specification/set.rb index e49474f84..b8f6fe0b5 100644 --- a/lib/cocoapods-core/specification/set.rb +++ b/lib/cocoapods-core/specification/set.rb @@ -37,7 +37,7 @@ def initialize(name, sources = []) @name = name sources = sources.is_a?(Array) ? sources : [sources] @sources = sources.sort_by(&:name) - @required_by = [] + @dependencies_by_requirer_name = {} @dependencies = [] end @@ -59,22 +59,26 @@ def initialize(name, sources = []) # @return [void] # def required_by(dependency, dependent_name) - # TODO - unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version) - raise Informative, "#{dependent_name} tries to activate " \ - "`#{dependency}', but already activated version " \ - "`#{required_version}' by #{@required_by.to_sentence}." + dependencies_by_requirer_name[dependent_name] ||= [] + dependencies_by_requirer_name[dependent_name] << dependency + dependencies << dependency + + if acceptable_versions.empty? + message = "Unable to satisfy the following requirements:\n" + dependencies_by_requirer_name.each do |name, dependencies| + dependencies.each do |dep| + message << "- `#{dep.to_s}` required by `#{name}`" + end + end + raise Informative, message end - @specification = nil - @required_by << dependent_name - @dependencies << dependency end # @return [Dependency] A dependency that includes all the versions # requirements of the stored dependencies. # def dependency - @dependencies.inject(Dependency.new(name)) do |previous, dependency| + dependencies.inject(Dependency.new(name)) do |previous, dependency| previous.merge(dependency.to_root_dependency) end end @@ -88,7 +92,7 @@ def dependency # def specification path = specification_path_for_version(required_version) - @specification ||= Specification.from_file(path) + specification = Specification.from_file(path) end # TODO @@ -116,6 +120,13 @@ def required_version version end + # @return [Array] All the versions which are acceptable given + # the requirements. + # + def acceptable_versions + versions.select { |v| dependency.match?(name, v) } + end + # @return [Array] all the available versions for the Pod, sorted # from highest to lowest. # @@ -181,6 +192,14 @@ def to_hash } end + + #-----------------------------------------------------------------------# + + + attr_accessor :dependencies_by_requirer_name + attr_accessor :dependencies + + #-----------------------------------------------------------------------# # The Set::External class handles Pods from external sources. Pods from @@ -199,14 +218,7 @@ def initialize(spec) end def ==(other) - self.class === other && @specification == other.specification - end - - def required_by(dependency, dependent_name) - before = @specification - super(dependency, dependent_name) - ensure - @specification = before + self.class === other && specification == other.specification end def specification_path @@ -214,7 +226,7 @@ def specification_path end def versions - [@specification.version] + [specification.version] end end end diff --git a/lib/cocoapods-core/specification/set/presenter.rb b/lib/cocoapods-core/specification/set/presenter.rb index 3f8c9a40f..1505bf4cd 100644 --- a/lib/cocoapods-core/specification/set/presenter.rb +++ b/lib/cocoapods-core/specification/set/presenter.rb @@ -82,7 +82,7 @@ def sources # highest available version. # def spec - @set.specification + @spec ||= @set.specification end # @return [String] the list of the authors of the Pod in sentence diff --git a/spec/specification/set/statistics_spec.rb b/spec/specification/set/statistics_spec.rb index a87db52ea..ea48b2b8a 100644 --- a/spec/specification/set/statistics_spec.rb +++ b/spec/specification/set/statistics_spec.rb @@ -44,7 +44,7 @@ module Pod end it "returns nil for GitHub based methods if the Pod is not hosted by GitHub" do - @set.specification.source = { :git => 'example.com/repo.git' } + Specification.any_instance.stubs(:source).returns({:git => 'example.com/repo.git'}) @stats.github_watchers(@set).should == nil @stats.github_forks(@set).should == nil @stats.github_pushed_at(@set).should == nil diff --git a/spec/specification/set_spec.rb b/spec/specification/set_spec.rb index 635bf8b0b..7d7df007c 100644 --- a/spec/specification/set_spec.rb +++ b/spec/specification/set_spec.rb @@ -38,8 +38,9 @@ module Pod end it "raises if the required version doesn't exist" do - @set.required_by(Dependency.new('CocoaLumberjack', '< 1.0'), 'Spec') - lambda { @set.required_version }.should.raise Informative + should.raise Informative do + @set.required_by(Dependency.new('CocoaLumberjack', '< 1.0'), 'Spec') + end end it "can test if it is equal to another set" do @@ -72,19 +73,33 @@ module Pod @set.required_version.should == Version.new('1.2') end + it "returns the acceptable versions according to the requirements stored" do + @set.acceptable_versions.map(&:to_s).should == ['1.2', '1.1', '1.0'] + end + it "returns the specification for the required version" do @set.specification.name.should == 'CocoaLumberjack' @set.specification.version.should == Version.new('1.2') end - it "ignores dotfiles when getting the version directories" do + it "ignores dot files when getting the version directories" do `touch #{fixture('spec-repos/master/CocoaLumberjack/.DS_Store')}` - lambda { @set.versions }.should.not.raise + should.not.raise do + @set.versions + end end it "raises if a version is incompatible with the activated version" do - spec = Dependency.new('CocoaLumberjack', '1.2.1') - lambda { @set.required_by(spec, 'Spec') }.should.raise Informative + dep = Dependency.new('CocoaLumberjack', '1.2.1') + should.raise Informative do + @set.required_by(dep, 'Spec') + end + end + + it "accepts a requirement if it allows supported versions" do + dep = Dependency.new('CocoaLumberjack', '< 1.1') + @set.required_by(dep, 'Spec') + @set.acceptable_versions.map(&:to_s).should == ['1.0'] end end @@ -179,8 +194,9 @@ module Pod end it "raises if the required version doesn't match the specification" do - @set.required_by(Dependency.new('BananaLib', '< 1.0'), 'Spec') - lambda { @set.required_version }.should.raise Informative + should.raise Informative do + @set.required_by(Dependency.new('BananaLib', '< 1.0'), 'Spec') + end end end end From 554127d521231f1628fcc440a64e12d9296600ae Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Wed, 30 Oct 2013 12:27:07 +0100 Subject: [PATCH 11/11] [Bundle] Restore compatiblity with Ruby 1.8.7 --- Gemfile | 3 +++ Gemfile.lock | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 22cbba6a8..cca5b1ec2 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,9 @@ source "http://rubygems.org" gemspec +# Ruby 1.8.7 +gem "mime-types", "< 2.0" + group :development do gem 'coveralls', :require => false gem "mocha", "~> 0.11.4" diff --git a/Gemfile.lock b/Gemfile.lock index f1ab22777..d44aff176 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,7 +49,7 @@ GEM log_switch (0.4.0) metaclass (0.0.1) method_source (0.8.2) - mime-types (2.0) + mime-types (1.25) mocha (0.11.4) metaclass (~> 0.0.1) mocha-on-bacon (0.2.1) @@ -101,6 +101,7 @@ DEPENDENCIES coveralls github-markup kicker! + mime-types (< 2.0) mocha (~> 0.11.4) mocha-on-bacon prettybacon!