apitools-middleware 0.0.1

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: a448dab79ade7a009e9a651c20b3cd91092adc7e
4
+ data.tar.gz: b669baa0693438142740bf6120a87005ef9ec411
5
+ SHA512:
6
+ metadata.gz: 5d7d3d4db1c0c63da26f5d6025caa065501bcf62255d3fd88546b30de4d5872167742e6e17f5e2af2b18c3046d580c0541f292c5b6033e2f0c264e064190590b
7
+ data.tar.gz: 8becb7e16e33500c920cec7b4ebcee83bc9bd02b98a4f91821a20404f18070da51e9f09bc6a373577eca8acbbe3487f6031b7a3fa44bfc7a7fe29c66cefec3ed
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.0.0
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in apitools-middleware.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michal Cichra
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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Apitools::Middleware [![Build Status](https://travis-ci.org/APItools/apitools-middleware.svg?branch=master)](https://travis-ci.org/APItools/apitools-middleware)
2
+
3
+ Ruby Library for working with APItools Middleware. Validating, testing, ...
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'apitools-middleware'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install apitools-middleware
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ repository = Apitools::Middleware::LocalRepository.new
24
+ repository.middleware.each do |middleware|
25
+ puts "Middleware #{middleware.name} is invalid" unless middleware.valid?
26
+ end
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/APItools/apitools-middleware/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -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 'apitools/middleware/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "apitools-middleware"
8
+ spec.version = Apitools::Middleware::VERSION
9
+ spec.authors = ["Michal Cichra"]
10
+ spec.email = ["michal@3scale.net"]
11
+ spec.summary = %q{Ruby Libary for Apitools Middleware}
12
+ spec.description = %q{Apitools Middleware manifest, repository, specification and more.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
25
+
26
+ spec.add_dependency 'semantic'
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'pathname'
2
+
3
+ module Apitools
4
+ module Middleware
5
+ class LocalRepository < Repository
6
+ PATTERN = "*/#{Spec::MANIFEST_FILE}"
7
+
8
+ def initialize(path = Pathname.pwd.join('middleware'), pattern = PATTERN)
9
+ @path = Pathname(path).expand_path
10
+ @manifests = Pathname.glob(@path.join(pattern))
11
+ end
12
+
13
+ def content(file)
14
+ Pathname(file).read
15
+ end
16
+
17
+ def middleware
18
+ @middleware ||= @manifests.map{ |manifest| Apitools::Middleware::Spec.new(self, manifest) }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ require 'ostruct'
2
+ require 'json'
3
+ require 'forwardable'
4
+
5
+ module Apitools
6
+ module Middleware
7
+ class Manifest < OpenStruct
8
+
9
+ extend Forwardable
10
+ def_delegator :to_h, :empty?
11
+
12
+ def self.parse(json)
13
+ parsed = JSON.parse(json)
14
+ new(parsed)
15
+
16
+ rescue JSON::ParserError
17
+ invalid_manifest
18
+ end
19
+
20
+ def self.invalid_manifest
21
+ # TODO: create own class for invalid manifest
22
+ new()
23
+ end
24
+
25
+ def ==(other)
26
+ super or to_h == other
27
+ end
28
+
29
+ def valid?
30
+ ! empty?
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ module Apitools
2
+ module Middleware
3
+ class Repository
4
+ attr_accessor :middleware
5
+
6
+ def content(path)
7
+ raise 'needs to be reimplemented in subclasses'
8
+ end
9
+
10
+ def valid?
11
+ Array(middleware).all?(&:valid?)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,63 @@
1
+ require 'pathname'
2
+ require 'semantic'
3
+ require 'forwardable'
4
+
5
+ module Apitools
6
+ module Middleware
7
+ class Spec
8
+ MANIFEST_FILE = 'apitools.json' # should be apitools.json
9
+
10
+ attr_reader :repo, :path, :manifest_path
11
+
12
+ extend Forwardable
13
+ def_delegators :manifest, :name, :description, :author, :endpoints, :files
14
+
15
+ def initialize(repo, path)
16
+ @repo = repo
17
+ pathname = Pathname(path)
18
+ @path = pathname.dirname
19
+ @manifest_path = pathname.basename || MANIFEST_FILE
20
+ end
21
+
22
+ def manifest=(json)
23
+ @manifest = Manifest.parse(json)
24
+ end
25
+
26
+ def manifest
27
+ @manifest ||= Manifest.parse(load_manifest)
28
+ end
29
+
30
+ def code
31
+ @code ||= load_code
32
+ end
33
+
34
+ def endpoint
35
+ Array(endpoints).first
36
+ end
37
+
38
+ def version
39
+ Semantic::Version.new(manifest.version)
40
+ rescue ArgumentError
41
+ false
42
+ end
43
+
44
+ def valid?
45
+ required_attributes = [name, path, author, endpoint, version, description]
46
+ required_attributes.all?
47
+ end
48
+
49
+ protected
50
+
51
+ def load_manifest
52
+ @repo.content(@path.join(@manifest_path))
53
+ end
54
+
55
+ def load_code
56
+ file = files.first
57
+
58
+ @repo.content(@path.join(file))
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ module Apitools
2
+ module Middleware
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'apitools/middleware/version'
2
+
3
+ module Apitools
4
+ module Middleware
5
+ autoload :Repository, 'apitools/middleware/repository'
6
+ autoload :LocalRepository, 'apitools/middleware/local_repository'
7
+ autoload :Spec, 'apitools/middleware/spec'
8
+ autoload :Manifest, 'apitools/middleware/manifest'
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require 'apitools/middleware'
@@ -0,0 +1,3 @@
1
+ {
2
+ "name" : "cache middleware"
3
+ }
File without changes
File without changes
@@ -0,0 +1,36 @@
1
+ describe Apitools::Middleware::LocalRepository do
2
+
3
+ subject(:repository) { described_class.new('spec/fixtures/middleware') }
4
+ let(:middleware) { repository.middleware }
5
+
6
+ it 'has 3 middlewares' do
7
+ expect(middleware.length).to eq(3)
8
+ end
9
+
10
+ context 'all middlewares are valid' do
11
+ before do
12
+ middleware.each {|m| expect(m).to receive(:valid?).and_return(true) }
13
+ end
14
+ expect_it { to be_valid }
15
+ end
16
+
17
+ context 'some middleware is invalid' do
18
+ expect_it { to_not be_valid }
19
+ end
20
+
21
+ context 'first middleware' do
22
+ let(:first) { subject.middleware.first }
23
+
24
+ it 'reads the manifest' do
25
+ expect(first.manifest).to be_valid
26
+ end
27
+ end
28
+
29
+ context 'second middleware' do
30
+ let(:second) { subject.middleware[1] }
31
+
32
+ it 'does not crash' do
33
+ expect(second.manifest).not_to be_valid
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ describe Apitools::Middleware::Manifest do
2
+
3
+ context 'invalid manifest' do
4
+ subject(:invalid_manifest) { described_class.invalid_manifest }
5
+ expect_it { to_not be_valid }
6
+ end
7
+
8
+ context 'empty manifest' do
9
+ subject(:empty_manifest) { described_class.new }
10
+ expect_it { to_not be_valid }
11
+ end
12
+
13
+ context 'manifest with something' do
14
+ subject(:manifest) { described_class.new(value: true) }
15
+ expect_it { to be_valid }
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ describe Apitools::Middleware::Repository do
2
+
3
+ it 'has #content method' do
4
+ expect{ subject.content('path') }.to raise_error(/needs to be reimplemented/)
5
+ end
6
+
7
+ end
@@ -0,0 +1,84 @@
1
+ require 'apitools/middleware'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, make a
12
+ # separate helper file that requires this one and then use it only in the specs
13
+ # that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # These two settings work together to allow you to limit a spec run
21
+ # to individual examples or groups you care about by tagging them with
22
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
23
+ # get run.
24
+ config.filter_run :focus
25
+ config.run_all_when_everything_filtered = true
26
+
27
+ # Many RSpec users commonly either run the entire suite or an individual
28
+ # file, and it's useful to allow more verbose output when running an
29
+ # individual spec file.
30
+ if config.files_to_run.one?
31
+ # Use the documentation formatter for detailed output,
32
+ # unless a formatter has already been configured
33
+ # (e.g. via a command-line flag).
34
+ config.default_formatter = 'doc'
35
+ end
36
+
37
+ # Print the 10 slowest examples and example groups at the
38
+ # end of the spec run, to help surface which specs are running
39
+ # particularly slow.
40
+ config.profile_examples = 10
41
+
42
+ # Run specs in random order to surface order dependencies. If you find an
43
+ # order dependency and want to debug it, you can fix the order by providing
44
+ # the seed, which is printed after each run.
45
+ # --seed 1234
46
+ config.order = :random
47
+
48
+ # Seed global randomization in this process using the `--seed` CLI option.
49
+ # Setting this allows you to use `--seed` to deterministically reproduce
50
+ # test failures related to randomization by passing the same `--seed` value
51
+ # as the one that triggered the failure.
52
+ Kernel.srand config.seed
53
+
54
+ # rspec-expectations config goes here. You can use an alternate
55
+ # assertion/expectation library such as wrong or the stdlib/minitest
56
+ # assertions if you prefer.
57
+ config.expect_with :rspec do |expectations|
58
+ # Enable only the newer, non-monkey-patching expect syntax.
59
+ # For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ expectations.syntax = :expect
62
+ end
63
+
64
+ # rspec-mocks config goes here. You can use an alternate test double
65
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
66
+ config.mock_with :rspec do |mocks|
67
+ # Enable only the newer, non-monkey-patching expect syntax.
68
+ # For more details, see:
69
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
70
+ mocks.syntax = :expect
71
+
72
+ # Prevents you from mocking or stubbing a method that does not exist on
73
+ # a real object. This is generally recommended.
74
+ mocks.verify_partial_doubles = true
75
+ end
76
+
77
+ config.alias_example_to :expect_it
78
+ end
79
+
80
+ RSpec::Core::MemoizedHelpers.module_eval do
81
+ alias to should
82
+ alias to_not should_not
83
+ alias expect_it should # keep rubymine happy
84
+ end
data/spec/spec_spec.rb ADDED
@@ -0,0 +1,46 @@
1
+ describe Apitools::Middleware::Spec do
2
+ let(:repo) { double('repository') }
3
+ let(:path) { Pathname('some/path.json') }
4
+
5
+ subject(:spec) { described_class.new(repo, path.to_s) }
6
+
7
+ it 'trims path to just folder' do
8
+ expect(spec.path).to eq(path.dirname)
9
+ end
10
+
11
+ it 'remembers manifest from path' do
12
+ expect(spec.manifest_path).to eq(path.basename)
13
+ end
14
+
15
+ it 'allows setting manifest as json' do
16
+ spec.manifest = '{ "name": "manifest" }'
17
+ expect(spec.manifest).to eq(name: 'manifest')
18
+ end
19
+
20
+ context 'with valid manifest' do
21
+ let(:manifest) do
22
+ {
23
+ name: 'middleware',
24
+ author: '3scale',
25
+ description: 'some description',
26
+ version: '1.2.3-rc.2',
27
+ endpoints: ['*'],
28
+ files: ['middleware.lua']
29
+ }
30
+ end
31
+
32
+ before do
33
+ spec.manifest = manifest.to_json
34
+ end
35
+
36
+ expect_it { to be_valid }
37
+ end
38
+
39
+ context 'with empty manifest' do
40
+ before do
41
+ spec.manifest = {}.to_json
42
+ end
43
+
44
+ expect_it { to_not be_valid }
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apitools-middleware
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michal Cichra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-28 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: semantic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Apitools Middleware manifest, repository, specification and more.
70
+ email:
71
+ - michal@3scale.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - apitools-middleware.gemspec
84
+ - lib/apitools-middleware.rb
85
+ - lib/apitools/middleware.rb
86
+ - lib/apitools/middleware/local_repository.rb
87
+ - lib/apitools/middleware/manifest.rb
88
+ - lib/apitools/middleware/repository.rb
89
+ - lib/apitools/middleware/spec.rb
90
+ - lib/apitools/middleware/version.rb
91
+ - spec/fixtures/middleware/cache/apitools.json
92
+ - spec/fixtures/middleware/privacy/apitools.json
93
+ - spec/fixtures/middleware/test/apitools.json
94
+ - spec/local_repository_spec.rb
95
+ - spec/manifest_spec.rb
96
+ - spec/repository_spec.rb
97
+ - spec/spec_helper.rb
98
+ - spec/spec_spec.rb
99
+ homepage: ''
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Ruby Libary for Apitools Middleware
123
+ test_files:
124
+ - spec/fixtures/middleware/cache/apitools.json
125
+ - spec/fixtures/middleware/privacy/apitools.json
126
+ - spec/fixtures/middleware/test/apitools.json
127
+ - spec/local_repository_spec.rb
128
+ - spec/manifest_spec.rb
129
+ - spec/repository_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/spec_spec.rb
132
+ has_rdoc: