shackleton 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6954e600be3d0361b3cbf63489ba32028a2e94e0
4
+ data.tar.gz: f13ad60fbba787ae362323881070ef1680c73152
5
+ SHA512:
6
+ metadata.gz: 0c82960ddb9f2a7a17830eb424d0ad4a3cb127aba31d20ab58d4e55c694010854f57f6a878fc6922066ae50d580fc07ce0405a82df3bb8cf8338bdffdaf956ae
7
+ data.tar.gz: bc6cd5229faf14d91557a773f628733051f334410bce01c447570a0c185fcd9b8d29af52a35ef8f9d775de35afdfcf3f6622b73a2472c21c6b381ba60a7e5ca5
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in shackleton.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Shackleton
2
+
3
+ A URL builder DSL, set up your API routes, and then call to build your URL
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'shackleton'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shackleton
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ map = Shackleton.mapper do
25
+ route :line, 'line(/:id)' do
26
+ route :meta do
27
+ route :modes
28
+ route :severity
29
+ route :disruption_categories, 'disruptioncategories'
30
+ route :service_types, 'servicetypes'
31
+ end
32
+ route :mode, 'mode/:modes' do
33
+ route :route
34
+ end
35
+ end
36
+ end
37
+
38
+ map.line(id: 'northern').meta.modes.to_s #=> 'line/10/meta/modes'
39
+ map.line(id: 'northern').mode(mode: 'tube', detail: true).to_s #=> 'line/10/meta/modes/tube?detail=true'
40
+ map.line.meta.modes.to_s #=> 'line/meta/modes'
41
+ ```
42
+
43
+ The mapper defines the structure of the urls, and when you call each fragment, your aruments are captured and then replayed to create your URL, undefined query params are supported, they're attached to the end of the URI
44
+
45
+ `
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/adamcarlile/shackleton.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shackleton"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "pry"
14
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/shackleton.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'mustermann'
2
+ require 'shackleton/extensions/hash_slice'
3
+ require "shackleton/version"
4
+
5
+ require 'shackleton/route'
6
+ require 'shackleton/mapper'
7
+ require 'shackleton/fragment'
8
+ require 'shackleton/builder'
9
+
10
+ module Shackleton
11
+ module_function
12
+
13
+ def mapper(&block)
14
+ Shackleton::Mapper.new(&block)
15
+ end
16
+
17
+ end
@@ -0,0 +1,30 @@
1
+ module Shackleton
2
+ class Builder
3
+ extend Forwardable
4
+
5
+ def_delegator :build, :to_s
6
+
7
+ def stack
8
+ @stack ||= []
9
+ end
10
+
11
+ def build
12
+ [stack.map(&:call).compact.join('/').gsub(%r{/+}, '/'), query_params].reject(&:empty?).join("?")
13
+ end
14
+
15
+ def add_route(route, kwargs)
16
+ stack << Shackleton::Fragment.new(route, kwargs)
17
+ self
18
+ end
19
+
20
+ def query_params
21
+ URI.encode_www_form(Hash[*stack.map {|x| x.query_params.to_a}.flatten])
22
+ end
23
+
24
+ def method_missing(method, *args, **kwargs, &block)
25
+ return self.add_route(stack.last[method.to_sym], kwargs) if stack.last[method.to_sym]
26
+ super
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ module Shackleton
2
+ module Extensions
3
+ module HashSlice
4
+ def slice(*keys)
5
+ ::Hash[[keys, self.values_at(*keys)].transpose]
6
+ end
7
+ def except(*keys)
8
+ desired_keys = self.keys - keys
9
+ ::Hash[[desired_keys, self.values_at(*desired_keys)].transpose]
10
+ end
11
+ end
12
+ end
13
+ end
14
+ Hash.include Shackleton::Extensions::HashSlice
@@ -0,0 +1,25 @@
1
+ module Shackleton
2
+ class Fragment
3
+ extend Forwardable
4
+
5
+ def_delegator :@route, :[]
6
+
7
+ def initialize(route, arguments)
8
+ @route = route
9
+ @arguments = arguments
10
+ end
11
+
12
+ def call
13
+ @route.expand(arguments)
14
+ end
15
+
16
+ def arguments
17
+ @arguments.slice(*@route.named_fragments)
18
+ end
19
+
20
+ def query_params
21
+ @arguments.except(*@route.named_fragments)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ module Shackleton
2
+ class Mapper
3
+
4
+ def initialize &block
5
+ @root = Shackleton::Route.new(&block)
6
+ end
7
+
8
+ def method_missing(method, *args, **kwargs, &block)
9
+ return Shackleton::Builder.new.add_route(@root[method.to_sym], kwargs) if @root[method.to_sym]
10
+ super
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module Shackleton
2
+ class Route
3
+ extend Forwardable
4
+
5
+ def_delegator :routes, :[]
6
+ def_delegator :pattern, :expand
7
+
8
+ def initialize(name: nil, path: nil, parent: nil, **options, &block)
9
+ @name = name
10
+ @path = path || name.to_s
11
+ @options = options
12
+ @parent = parent
13
+ instance_exec self, &block if block_given?
14
+ end
15
+
16
+ def route(name, path=nil, **options, &block)
17
+ routes[name.to_sym] = self.class.new(name: name, path: path, **options, &block)
18
+ end
19
+
20
+ def routes
21
+ @routes ||= {}
22
+ end
23
+
24
+ def named_fragments
25
+ @named_fragments ||= pattern.names.map(&:to_sym)
26
+ end
27
+
28
+ private
29
+
30
+ def pattern
31
+ @pattern ||= Mustermann.new(@path, type: :rails)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Shackleton
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "shackleton/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shackleton"
8
+ spec.version = Shackleton::VERSION
9
+ spec.authors = ["Adam Carlile"]
10
+ spec.email = ["github@adamcarlile.com"]
11
+
12
+ spec.summary = %q{Map your way across that cold tudra of API consuming}
13
+ spec.homepage = "https://github.com/adamcarlile/shackelton"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "mustermann"
24
+ spec.add_dependency "mustermann-contrib"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry"
30
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shackleton
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Carlile
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mustermann
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: mustermann-contrib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - github@adamcarlile.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/shackleton.rb
114
+ - lib/shackleton/builder.rb
115
+ - lib/shackleton/extensions/hash_slice.rb
116
+ - lib/shackleton/fragment.rb
117
+ - lib/shackleton/mapper.rb
118
+ - lib/shackleton/route.rb
119
+ - lib/shackleton/version.rb
120
+ - shackleton.gemspec
121
+ homepage: https://github.com/adamcarlile/shackelton
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.11
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Map your way across that cold tudra of API consuming
145
+ test_files: []