Skip to content

Commit

Permalink
[Specification] Switch to JSON (sorry YAML)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Dec 19, 2013
1 parent 88f665e commit 7ba170c
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 194 deletions.
2 changes: 1 addition & 1 deletion lib/cocoapods-core/source.rb
Expand Up @@ -113,7 +113,7 @@ def specification(name, version)
#
def specification_path(name, version)
path = specs_dir + name + version.to_s
specification_path = path + "#{name}.podspec.yaml"
specification_path = path + "#{name}.podspec.json"
unless specification_path.exist?
specification_path = path + "#{name}.podspec"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-core/source/health_reporter.rb
Expand Up @@ -124,7 +124,7 @@ def check_spec_path(name, version, spec)
# @return [void]
#
def check_stray_specs
all_paths = Pathname.glob(source.repo + '**/*.podspec{,.yaml}')
all_paths = Pathname.glob(source.repo + '**/*.podspec{,.json}')
stray_specs = all_paths - report.analyzed_paths
stray_specs.each do |path|
report.add_message(:error, "Stray spec", path)
Expand Down
8 changes: 4 additions & 4 deletions lib/cocoapods-core/specification.rb
Expand Up @@ -3,7 +3,7 @@
require 'cocoapods-core/specification/linter'
require 'cocoapods-core/specification/root_attribute_accessors'
require 'cocoapods-core/specification/set'
require 'cocoapods-core/specification/yaml'
require 'cocoapods-core/specification/json'

module Pod

Expand All @@ -18,7 +18,7 @@ class Specification
include Pod::Specification::DSL
include Pod::Specification::DSL::Deprecations
include Pod::Specification::RootAttributesAccessors
include Pod::Specification::YAMLSupport
include Pod::Specification::JSONSupport

# @return [Specification] the parent of the specification unless the
# specification is a root.
Expand Down Expand Up @@ -561,8 +561,8 @@ def self.from_string(spec_contents, path, subspec_name = nil)
unless spec.is_a?(Specification)
raise Informative, "Invalid podspec file at path `#{path}`."
end
when '.yaml'
spec = Specification.from_yaml(spec_contents)
when '.json'
spec = Specification.from_json(spec_contents)
else
raise Informative, "Unsupported specification format `#{path.extname}`."
end
Expand Down
@@ -1,14 +1,16 @@
module Pod
class Specification
module YAMLSupport
module JSONSupport

# @return [String] the yaml representation of the specification.
# @return [String] the json representation of the specification.
#
def to_yaml
require 'yaml'
to_hash.to_yaml
def to_json
require 'json'
JSON.pretty_generate(to_hash)
end

#-----------------------------------------------------------------------#

# @return [Hash] the hash representation of the specification including
# subspecs.
#
Expand All @@ -26,7 +28,20 @@ def to_hash
def safe_to_hash?
pre_install_callback.nil? && post_install_callback.nil?
end
end

# Configures a new specification from the given JSON representation.
#
# @param [String] the JSON encoded hash which contains the information of
# the specification.
#
#
# @return [Specification] the specification
#
def self.from_json(json)
require 'json'
hash = JSON.parse(json)
from_hash(hash)
end

# Configures a new specification from the given hash.
Expand All @@ -49,18 +64,7 @@ def self.from_hash(hash, parent = nil)
spec
end

# Configures a new specification from the given YAML representation.
#
# @param [String] the YAML encoded hash which contains the information of
# the specification.
#
#
# @return [Specification] the specification
#
def self.from_yaml(yaml)
require 'yaml'
hash = YAML.load(yaml)
from_hash(hash)
end
#-----------------------------------------------------------------------#

end
end
2 changes: 1 addition & 1 deletion lib/cocoapods-core/specification/linter.rb
Expand Up @@ -205,7 +205,7 @@ def _validate_name(n)
if spec.name && file
acceptable_names = [
spec.root.name + '.podspec',
spec.root.name + '.podspec.yaml'
spec.root.name + '.podspec.json'
]
names_match = acceptable_names.include?(file.basename.to_s)
unless names_match
Expand Down
50 changes: 50 additions & 0 deletions spec/fixtures/BananaLib.podspec.json
@@ -0,0 +1,50 @@
{
"name": "BananaLib",
"version": "1.0",
"authors": [
"Banana Corp",
{
"Monkey Boy": "monkey@banana-corp.local"
}
],
"homepage": "http://banana-corp.local/banana-lib.html",
"summary": "Chunky bananas!",
"description": "Full of chunky bananas.",
"source": {
"git": "http://banana-corp.local/banana-lib.git",
"tag": "v1.0"
},
"license": {
"type": "MIT",
"file": "LICENSE",
"text": "Permission is hereby granted ..."
},
"platforms": {
"ios": "4.3"
},
"source_files": [
"Classes/*.{h,m}",
"Vendor"
],
"ios": {
"source_files": "Classes_ios/*.{h,m}"
},
"resources": "Resources/*.png",
"xcconfig": {
"OTHER_LDFLAGS": "-framework SystemConfiguration"
},
"prefix_header_file": "Classes/BananaLib.pch",
"requires_arc": true,
"dependencies": {
"monkey": [
"~> 1.0.1",
"< 1.0.9"
]
},
"subspecs": [
{
"name": "GreenBanana",
"source_files": "GreenBanana"
}
]
}
47 changes: 0 additions & 47 deletions spec/fixtures/BananaLib.podspec.yaml

This file was deleted.

@@ -1,4 +1,4 @@
Pod::Spec.new do |s|
s.name = 'YAMLSpec'
s.name = 'IncorrectPath'
s.version = '0.9'
end
@@ -0,0 +1,4 @@
{
"name": "JSONSpec",
"version": "0.9"
}
@@ -0,0 +1,4 @@
{
"name": "JSONSpec",
"version": "1.0"
}
4 changes: 4 additions & 0 deletions spec/fixtures/spec-repos/test_repo/Specs/StraySpec.podspec
@@ -0,0 +1,4 @@
Pod::Spec.new do |s|
s.name = 'IncorrectPath'
s.version = '0.9'
end

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions spec/source/aggregate_spec.rb
Expand Up @@ -118,17 +118,17 @@ module Pod

it "generates the search index from scratch" do
index = @sut.generate_search_index
index.keys.sort.should == ["BananaLib", "Faulty_spec", "JSONKit", "YAMLSpec"]
index.keys.sort.should == ["BananaLib", "Faulty_spec", "IncorrectPath", "JSONKit", "JSONSpec"]
index["BananaLib"]["version"].should == '1.0'
index["BananaLib"]["summary"].should == 'Chunky bananas!'
index["BananaLib"]["description"].should == 'Full of chunky bananas.'
index["BananaLib"]["authors"].should == 'Banana Corp, Monkey Boy'
end

it "updates a given index" do
old_index = {"Faulty_spec" => {}, "JSONKit" => {}, "YAMLSpec" => {}}
old_index = {"Faulty_spec" => {}, "JSONKit" => {}, "JSONSpec" => {}}
index = @sut.update_search_index(old_index)
index.keys.sort.should == ["BananaLib", "Faulty_spec", "JSONKit", "YAMLSpec"]
index.keys.sort.should == ["BananaLib", "Faulty_spec", "IncorrectPath", "JSONKit", "JSONSpec"]
index["BananaLib"]["version"].should == '1.0'
end

Expand Down
3 changes: 2 additions & 1 deletion spec/source/health_reporter_spec.rb
Expand Up @@ -23,7 +23,7 @@ module Pod

it "analyzes all the specifications of a repo" do
@sut.analyze
@sut.report.analyzed_paths.count.should == 8
@sut.report.analyzed_paths.count.should == 9
end

it "is robust against malformed specifications" do
Expand All @@ -35,6 +35,7 @@ module Pod
it "lints the specifications" do
@sut.analyze
errors = @sut.report.pods_by_error.keys.join(' - ')
p errors
errors.should.match /Missing required attribute/
end

Expand Down
20 changes: 10 additions & 10 deletions spec/source_spec.rb
Expand Up @@ -49,29 +49,29 @@ module Pod
path.should == @sut.repo + 'Reachability/3.0.0/Reachability.podspec'
end

it "returns the path of YAML specification with a given name and version" do
it "returns the path of JSON specification with a given name and version" do
source = Source.new(fixture('spec-repos/test_repo'))
path = source.specification_path('YAMLSpec', Version.new('1.0'))
path.should == source.repo + 'Specs/YAMLSpec/1.0/YAMLSpec.podspec.yaml'
path = source.specification_path('JSONSpec', Version.new('1.0'))
path.should == source.repo + 'Specs/JSONSpec/1.0/JSONSpec.podspec.json'
end

it "favors the YAML version of a specification if both are available" do
it "favors the JSON version of a specification if both are available" do
source = Source.new(fixture('spec-repos/test_repo'))
ruby_path = source.repo + 'Specs/YAMLSpec/0.9/YAMLSpec.podspec.yaml'
path = source.specification_path('YAMLSpec', Version.new('0.9'))
ruby_path = source.repo + 'Specs/JSONSpec/0.9/JSONSpec.podspec.json'
path = source.specification_path('JSONSpec', Version.new('0.9'))
ruby_path.should.exist
path.should == source.repo + 'Specs/YAMLSpec/0.9/YAMLSpec.podspec.yaml'
path.should == source.repo + 'Specs/JSONSpec/0.9/JSONSpec.podspec.json'
end

it "raises if it can't find a specification for the given version and name" do
should.raise StandardError do
@sut.specification_path('YAMLSpec', Version.new('999'))
end.message.should.match(/Unable to find the specification YAMLSpec/)
@sut.specification_path('JSONSpec', Version.new('999'))
end.message.should.match(/Unable to find the specification JSONSpec/)
end

it "returns all the specifications" do
source = Source.new(fixture('spec-repos/test_repo'))
source.all_specs.map(&:name).sort.uniq.should == ["BananaLib", "JSONKit", "YAMLSpec"]
source.all_specs.map(&:name).sort.uniq.should == ["BananaLib", "IncorrectPath", "JSONKit", "JSONSpec"]
end

end
Expand Down

0 comments on commit 7ba170c

Please sign in to comment.