shoppingcart 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4c8ededbaeb7e6e38b001b39401005e0f6d77d4
4
+ data.tar.gz: dcb53def1eadeb7a2fc510bb26d40cde90139326
5
+ SHA512:
6
+ metadata.gz: 5ac602d0354a90a97f09ba0eb8da7eb7c9baaf7d2b1a49f8640e8e0870b5b552a262b0636ad3d29a67640a45ed18d3c40a0ea195f171d4a661c46f2afb0bef9e
7
+ data.tar.gz: 712ca2a93dfd2bb5fd77f2005142cf9d84a4c8658263ec1deb8d96a261931f98b8dd01474ba6630542cefbfba4f365d92638dcb139194d640f39ff8fb4128dfc
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm: 2.0.0-p598
3
+ cache: bundler
4
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shopping.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'cocoapods', '>= 0.36.0'
8
+ gem 'bacon'
9
+ gem 'mocha-on-bacon'
10
+ gem 'mocha', '~> 0.11.4'
11
+ gem 'prettybacon', :git => 'https://github.com/irrationalfab/PrettyBacon.git', :branch => 'master'
12
+ gem 'coveralls', :require => false
13
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Boris Bügling
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Shopping
2
+
3
+ [![Build Status](http://img.shields.io/travis/neonichu/shopping/master.svg?style=flat)](https://travis-ci.org/neonichu/shopping)
4
+ [![Coverage Status](https://coveralls.io/repos/neonichu/shopping/badge.svg)](https://coveralls.io/r/neonichu/shopping)
5
+ [![Gem Version](http://img.shields.io/gem/v/shoppingcart.svg?style=flat)](http://badge.fury.io/rb/shoppingcart)
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/neonichu/shopping.svg?style=flat)](https://codeclimate.com/github/neonichu/shopping)
7
+
8
+ Parse Cartfiles in Ruby, be happy.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'shopping'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```bash
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```bash
27
+ $ gem install shopping
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/neonichu/shopping/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ def specs(dir)
4
+ FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
5
+ end
6
+
7
+ desc 'Runs all the specs'
8
+ task :spec do
9
+ sh "bundle exec bacon #{specs('**')}"
10
+ end
11
+
12
+ task :default => :specs
@@ -0,0 +1,2 @@
1
+ require "shopping/version"
2
+ require "shopping/parser"
@@ -0,0 +1,37 @@
1
+ grammar Cartfile
2
+ rule Cartfile
3
+ ((dependency | comment)? "\n")+
4
+ end
5
+
6
+ rule dependency
7
+ repo " " quoted_string (" " (version_spec | quoted_string))? (" " comment)?
8
+ end
9
+
10
+ rule repo
11
+ "github" | "git"
12
+ end
13
+
14
+ rule quoted_string
15
+ '"' ASCII '"'
16
+ end
17
+
18
+ rule ASCII
19
+ ([\x20\x23-\x5B\x5D-\x7E])*
20
+ end
21
+
22
+ rule comment
23
+ "#" ASCII
24
+ end
25
+
26
+ rule version
27
+ [0-9] "." [0-9] ("." [0-9])?
28
+ end
29
+
30
+ rule operator
31
+ ">=" | "~>" | "=="
32
+ end
33
+
34
+ rule version_spec
35
+ operator " " version
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ grammar Resolved
2
+ rule Resolved
3
+ (resolved_dependency "\n")+
4
+ end
5
+
6
+ rule resolved_dependency
7
+ repo " " quoted_string " " (commit | tag)
8
+ end
9
+
10
+ rule repo
11
+ "github" | "git"
12
+ end
13
+
14
+ rule tag
15
+ quoted_string
16
+ end
17
+
18
+ rule commit
19
+ '"' [0-9a-z]+ '"'
20
+ end
21
+
22
+ rule quoted_string
23
+ '"' ASCII '"'
24
+ end
25
+
26
+ rule ASCII
27
+ ([\x20\x23-\x5B\x5D-\x7E])*
28
+ end
29
+ end
@@ -0,0 +1,96 @@
1
+ require 'citrus'
2
+
3
+ grammars = ::File.expand_path(::File.join('..', 'grammars'), __FILE__)
4
+ $LOAD_PATH.unshift(grammars) unless $LOAD_PATH.include?(grammars)
5
+
6
+ Citrus.require 'Cartfile'
7
+ Citrus.require 'Resolved'
8
+
9
+ module Shopping
10
+ class Dependency
11
+ attr_reader :branch
12
+ attr_reader :repo
13
+ attr_reader :version
14
+
15
+ def initialize(dependency_match)
16
+ quoted_string = dependency_match['quoted_string']
17
+ version_spec = dependency_match['version_spec']
18
+
19
+ @repo = dependency_match['repo'].first.to_s
20
+ @path = unquote(quoted_string)
21
+ @version = version_spec.first.to_s
22
+ @version = nil if @version.length == 0
23
+
24
+ if quoted_string.count == 2
25
+ @branch = unquote([quoted_string[1]])
26
+ end
27
+ end
28
+
29
+ def name
30
+ (Pathname.new(@path).basename '.*').to_s
31
+ end
32
+
33
+ def url
34
+ @repo == "git" ? @path : "https://github.com/#{@path}.git"
35
+ end
36
+
37
+ def to_s
38
+ "#{name} #{version}"
39
+ end
40
+
41
+ private
42
+
43
+ def unquote(string)
44
+ string.first.to_s.split('"')[1]
45
+ end
46
+ end
47
+
48
+ class ResolvedDependency < Dependency
49
+ attr_reader :commit
50
+ attr_reader :tag
51
+
52
+ def initialize(dependency_match)
53
+ super(dependency_match)
54
+
55
+ @branch = nil
56
+ @commit = unquote(dependency_match['commit'])
57
+ @tag = unquote(dependency_match['tag'])
58
+ @version = nil
59
+ end
60
+ end
61
+
62
+ class Parser
63
+ def self.parse(path)
64
+ Cartfile.parse(Pathname.new(path).read).matches.map do |match|
65
+ dependency = match.captures[:dependency]
66
+ unless dependency.nil? || dependency.first.nil?
67
+ Dependency.new(dependency.first.captures)
68
+ end
69
+ end.compact
70
+ end
71
+
72
+ def self.parse_resolved(path)
73
+ Resolved.parse(Pathname.new(path).read).matches.map do |match|
74
+ resolved = match.captures[:resolved_dependency]
75
+ ResolvedDependency.new(resolved.first.captures)
76
+ end
77
+ end
78
+ end
79
+
80
+ class Podfile
81
+ def self.serialize(dependencies)
82
+ dependencies.map do |dependency|
83
+ pod = "pod '#{dependency.name}'"
84
+
85
+ if (!dependency.branch && !dependency.version) || dependency.repo == 'git'
86
+ pod += ", :git => '#{dependency.url}'"
87
+ end
88
+
89
+ pod += ", :branch => '#{dependency.branch}'" if dependency.branch
90
+ pod += ", '#{dependency.version.sub('==', '=')}'" if dependency.version
91
+
92
+ pod
93
+ end.join("\n")
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module Shopping
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shopping/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shoppingcart"
8
+ spec.version = Shopping::VERSION
9
+ spec.authors = ["Boris Bügling"]
10
+ spec.email = ["boris@icculus.org"]
11
+ spec.summary = %q{Parse Cartfiles in Ruby, be happy.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "citrus"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Shopping
4
+ describe Parser do
5
+ it 'can parse the repository kind of a dependency' do
6
+ match = Cartfile.parse('github', :root => :repo)
7
+ match.should.not == nil
8
+ end
9
+
10
+ it 'can parse quoted strings' do
11
+ match = Cartfile.parse('"foo/bar"', :root => :quoted_string)
12
+ match.should.not == nil
13
+ end
14
+
15
+ it 'can parse versions' do
16
+ versions = [ '>= 1.0', '== 2.0', '~> 3.1.0' ]
17
+
18
+ versions.each do |version|
19
+ match = Cartfile.parse(version.split(' ')[0], :root => :operator)
20
+ match.should.not == nil
21
+
22
+ match = Cartfile.parse(version.split(' ')[1], :root => :version)
23
+ match.should.not == nil
24
+
25
+ match = Cartfile.parse(version, :root => :version_spec)
26
+ match.should.not == nil
27
+ end
28
+ end
29
+
30
+ it 'can parse a dependency' do
31
+ dep = "github \"ReactiveCocoa/ReactiveCocoa\" >= 2.3.1"
32
+ match = Cartfile.parse(dep, :root => :dependency)
33
+
34
+ match.should.not == nil
35
+ end
36
+
37
+ it 'can parse a dependency with branch' do
38
+ dep = 'git "https://enterprise.local/desktop/git-error-translations.git" "development"'
39
+ match = Dependency.new(Cartfile.parse(dep, :root => :dependency))
40
+
41
+ match.name.should == 'git-error-translations'
42
+ match.url.should == 'https://enterprise.local/desktop/git-error-translations.git'
43
+ match.version.should == nil
44
+ match.branch.should == 'development'
45
+ end
46
+
47
+ it 'can parse a simple Cartfile' do
48
+ match = Parser.parse('spec/fixtures/TestCartfile')
49
+
50
+ match.first.name.should == 'ReactiveCocoa'
51
+ match.first.url.should == 'https://github.com/ReactiveCocoa/ReactiveCocoa.git'
52
+ match.first.version.should == '>= 2.3.1'
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ github "ReactiveCocoa/ReactiveCocoa" >= 2.3.1
2
+ github "Mantle/Mantle" ~> 1.0
3
+
4
+ # here is a comment
5
+ github "jspahrsummers/libextobjc" == 0.4.1
6
+ github "jspahrsummers/xcconfigs" # here is an intra-line comment
7
+
8
+ git "https://enterprise.local/desktop/git-error-translations.git" "development"
@@ -0,0 +1,2 @@
1
+ github "ReactiveCocoa/ReactiveCocoa" "v2.3.1"
2
+ git "https://github.com/Mantle/Mantle.git" "40abed6e58b4864afac235c3bb2552e23bc9da47"
@@ -0,0 +1,5 @@
1
+ pod 'ReactiveCocoa', '>= 2.3.1'
2
+ pod 'Mantle', '~> 1.0'
3
+ pod 'libextobjc', '= 0.4.1'
4
+ pod 'xcconfigs', :git => 'https://github.com/jspahrsummers/xcconfigs.git'
5
+ pod 'git-error-translations', :git => 'https://enterprise.local/desktop/git-error-translations.git', :branch => 'development'
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Shopping
4
+ describe Podfile do
5
+ it 'can convert a Cartfile to a Podfile' do
6
+ result = Parser.parse('spec/fixtures/TestCartfile')
7
+ podfile = Podfile.serialize(result)
8
+
9
+ podfile.should == Pathname.new('spec/fixtures/TestPodfile').read
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Shopping
4
+ describe Parser do
5
+ it 'can parse a commit' do
6
+ commit = '"40abed6e58b4864afac235c3bb2552e23bc9da47"'
7
+ match = Resolved.parse(commit, :root => :commit)
8
+ match.should.not == nil
9
+ end
10
+
11
+ it 'can parse a simple Cartfile.resolved' do
12
+ match = Parser.parse_resolved('spec/fixtures/TestCartfile.resolved')
13
+
14
+ match.first.commit.should == nil
15
+ match.first.name.should == 'ReactiveCocoa'
16
+ match.first.repo.should == 'github'
17
+ match.first.tag.should == 'v2.3.1'
18
+ match.first.url.should == 'https://github.com/ReactiveCocoa/ReactiveCocoa.git'
19
+
20
+ match.last.commit.should == '40abed6e58b4864afac235c3bb2552e23bc9da47'
21
+ match.last.name.should == 'Mantle'
22
+ match.last.repo.should == 'git'
23
+ match.last.tag.should == nil
24
+ match.last.url.should == 'https://github.com/Mantle/Mantle.git'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'pathname'
5
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
6
+ $:.unshift((ROOT + 'lib').to_s)
7
+ $:.unshift((ROOT + 'spec').to_s)
8
+
9
+ require 'bundler/setup'
10
+ require 'bacon'
11
+ require 'mocha-on-bacon'
12
+ require 'pretty_bacon'
13
+
14
+ require 'shopping'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoppingcart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Boris Bügling
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: citrus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - boris@icculus.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/shopping.rb
70
+ - lib/shopping/grammars/Cartfile.citrus
71
+ - lib/shopping/grammars/Resolved.citrus
72
+ - lib/shopping/parser.rb
73
+ - lib/shopping/version.rb
74
+ - shopping.gemspec
75
+ - spec/basic_spec.rb
76
+ - spec/fixtures/TestCartfile
77
+ - spec/fixtures/TestCartfile.resolved
78
+ - spec/fixtures/TestPodfile
79
+ - spec/podfile_spec.rb
80
+ - spec/resolved_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.0.14
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Parse Cartfiles in Ruby, be happy.
106
+ test_files:
107
+ - spec/basic_spec.rb
108
+ - spec/fixtures/TestCartfile
109
+ - spec/fixtures/TestCartfile.resolved
110
+ - spec/fixtures/TestPodfile
111
+ - spec/podfile_spec.rb
112
+ - spec/resolved_spec.rb
113
+ - spec/spec_helper.rb
114
+ has_rdoc: