magnetite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/magnetite.rb +10 -0
- data/lib/magnetite/base.rb +2 -0
- data/lib/magnetite/plugs/accept_plug.rb +7 -0
- data/lib/magnetite/plugs/base.rb +7 -0
- data/lib/magnetite/plugs/flash_plug.rb +7 -0
- data/lib/magnetite/routing/base.rb +49 -0
- data/lib/magnetite/routing/errors.rb +48 -0
- data/lib/magnetite/routing/pipeline.rb +32 -0
- data/lib/magnetite/routing/scope.rb +21 -0
- data/lib/magnetite/version.rb +3 -0
- data/magnetite.gemspec +27 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af5b10b83c869fe1449b279a1c2eb89808e7fe18
|
4
|
+
data.tar.gz: acef0862dff87367bc68f6ff027777659ccaabd0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16ac6d65756f3725b9935c1652286adacb3c67e5198d70b882c4705d42c93c269df64ed601a086f02028eb6ae2a8569b2b1aa70b1358d612ac79e82d7b02bbde
|
7
|
+
data.tar.gz: 923e1289a761600c81fdf1d8e890e53299075233fb1a1bb1022c6e686382675c915af5c7ba9bfab4436d9c65d0a42655e4f90cceb70f538414adbe738c240d95
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Magnetite
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/magnetite`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'magnetite'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install magnetite
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/magnetite.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "magnetite"
|
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 "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/magnetite.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative './magnetite/version'
|
2
|
+
require_relative './magnetite/base'
|
3
|
+
|
4
|
+
require_relative './magnetite/routing/base'
|
5
|
+
require_relative './magnetite/routing/pipeline'
|
6
|
+
require_relative './magnetite/routing/scope'
|
7
|
+
|
8
|
+
require_relative './magnetite/plugs/base'
|
9
|
+
require_relative './magnetite/plugs/accept_plug'
|
10
|
+
require_relative './magnetite/plugs/flash_plug'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative './errors'
|
2
|
+
|
3
|
+
module Magnetite
|
4
|
+
module Routing
|
5
|
+
|
6
|
+
class Base < BasicObject
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@pipelines = {}
|
10
|
+
@scopes = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# @param [Symbol] name A name representing the pipeline this name will
|
15
|
+
# be used to get the pipeline in the scopes.
|
16
|
+
def pipeline(name, &block)
|
17
|
+
::Kernel.raise NameRequired if name.nil?
|
18
|
+
|
19
|
+
@pipelines[name] = Pipeline.new(name)
|
20
|
+
@pipelines[name].instance_eval(&block) if ::Kernel.block_given?
|
21
|
+
@pipelines[name]
|
22
|
+
end
|
23
|
+
|
24
|
+
def scope(path, &block)
|
25
|
+
::Kernel.raise PathRequired if path.nil?
|
26
|
+
::Kernel.raise BlockRequired unless ::Kernel.block_given?
|
27
|
+
|
28
|
+
@scopes[path] = Scope.new(path, self)
|
29
|
+
@scopes[path].instance_eval(&block)
|
30
|
+
@scopes[path]
|
31
|
+
end
|
32
|
+
|
33
|
+
def resolve(path)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_pipeline(name)
|
38
|
+
@pipelines[name.to_sym]
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def resolve_scope(path)
|
44
|
+
# TODO given the path obtain the scope that first matches with it.
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Magnetite
|
2
|
+
module Routing
|
3
|
+
|
4
|
+
class NameRequired < ::StandardError
|
5
|
+
|
6
|
+
def to_s
|
7
|
+
'Pipeline requires a name'
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class PathRequired < ::StandardError
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
'Scope requires a path'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class BlockRequired < ::StandardError
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
'Scope requires a block to define the routing'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
class PipelineNotFound < ::StandardError
|
29
|
+
|
30
|
+
def initialize(pipeline_name)
|
31
|
+
@pipeline_name = pipeline_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
"Pipeline #{@pipeline_name} not found in the router"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class PlugNotFound < ::StandardError
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Magnetite
|
2
|
+
module Routing
|
3
|
+
class Pipeline < BasicObject
|
4
|
+
|
5
|
+
attr_reader :name, :plugs
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
@plugs = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def plug(name, *arguments)
|
13
|
+
@plugs << [plug_class(name), *arguments]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def plug_class(name)
|
19
|
+
plug_name = name.dup
|
20
|
+
plug_name = "::Magnetite::Plugs::#{plug_name}" unless ::Object.const_defined?(plug_name)
|
21
|
+
|
22
|
+
::Object.const_get(plug_name)
|
23
|
+
rescue ::NameError
|
24
|
+
::Kernel.raise <<-RUBY
|
25
|
+
Could not find a plug with the name #{name} in neither ::Magnetite::Plugs nor root.
|
26
|
+
Available: #{::Magnetite::Plugs.constants.select {|plag| plag != :Base }.map {|plug| "::Magnetite::Plugs:#{plug.to_s}" }.join(', ')}
|
27
|
+
RUBY
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Magnetite
|
2
|
+
module Routing
|
3
|
+
class Scope < BasicObject
|
4
|
+
|
5
|
+
def initialize(path, router)
|
6
|
+
@path = path
|
7
|
+
@router = router
|
8
|
+
@pipeline = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def pipe_through(name)
|
12
|
+
@pipeline = @router.get_pipeline(name)
|
13
|
+
|
14
|
+
::Kernel.raise PipelineNotFound.new(name) if @pipeline.nil?
|
15
|
+
|
16
|
+
@pipeline
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/magnetite.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "magnetite/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "magnetite"
|
8
|
+
spec.version = Magnetite::VERSION
|
9
|
+
spec.authors = ["Pablo Ifran"]
|
10
|
+
spec.email = ["pabloifran@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Some Summary}
|
13
|
+
spec.description = %q{Some description}
|
14
|
+
spec.homepage = "http://github.com"
|
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_development_dependency 'bundler', '~> 1.15'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'rspec-benchmark'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magnetite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pablo Ifran
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-benchmark
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Some description
|
70
|
+
email:
|
71
|
+
- pabloifran@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/magnetite.rb
|
84
|
+
- lib/magnetite/base.rb
|
85
|
+
- lib/magnetite/plugs/accept_plug.rb
|
86
|
+
- lib/magnetite/plugs/base.rb
|
87
|
+
- lib/magnetite/plugs/flash_plug.rb
|
88
|
+
- lib/magnetite/routing/base.rb
|
89
|
+
- lib/magnetite/routing/errors.rb
|
90
|
+
- lib/magnetite/routing/pipeline.rb
|
91
|
+
- lib/magnetite/routing/scope.rb
|
92
|
+
- lib/magnetite/version.rb
|
93
|
+
- magnetite.gemspec
|
94
|
+
homepage: http://github.com
|
95
|
+
licenses: []
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.6.11
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Some Summary
|
117
|
+
test_files: []
|