metova 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzkwM2Y4ZGZmZWVmZmJhM2U2N2E0NjM5YWQyZGIyMWJlNWM3YWYzMw==
5
+ data.tar.gz: !binary |-
6
+ MWNiZGU1MjQ2NjA5YjQxYmZkNjI0MThiZGM5ZDBhY2M5OWQwMDVkOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTExMjAzOTcyM2NlNDE2Mzc2YzA0Y2I5MzAyOGU5ZmE4Mzg2ZWQxNmRlODBj
10
+ NjlkYzhiNTJjNjUxMmFjMjEzOGVkZWU1YTY1MDY0ZTMxMTQwMjBhZWM2NGVh
11
+ ZjlkODQ0YjFjNTdhOGI3YjcwNGFjNzEzYzA1YzIwZmVkNmM0NGY=
12
+ data.tar.gz: !binary |-
13
+ YzZlYWUwY2ViMTgzYTgyNGYyMjY3ZWFlYTVmYzNiOTkwNGM2ZDVkNGU0ZGYy
14
+ MzBjM2MxMDE5ODJiMGVjZjQzNjIwMTgxN2U2MWU1YjM4NzEyYTNkMjZlZWQz
15
+ NGU4NWI0ZGNiZWFjMDVhYTMzYzU5MWJlMzllNTVhZTE4ZGZjYmQ=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Logan Serman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Metova'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rspec/core/rake_task'
25
+ task :default => :spec
26
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Metova
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Metova
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Metova</title>
5
+ <%= stylesheet_link_tag "metova/application", media: "all" %>
6
+ <%= javascript_include_tag "metova/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Metova::Engine.routes.draw do
2
+ end
@@ -0,0 +1,38 @@
1
+ require 'carrierwave'
2
+
3
+ module Metova
4
+ module Carrierwave
5
+ class Railtie < ::Rails::Railtie
6
+ initializer "metova.carrierwave" do |_|
7
+
8
+ if ENV['AWS_S3_BUCKET_NAME'] && ENV['AWS_S3_ACCESS_KEY_ID'] && ENV['AWS_S3_SECRET_ACCESS_KEY']
9
+ CarrierWave.configure do |config|
10
+ config.storage = :fog
11
+ config.fog_directory = ENV['AWS_S3_BUCKET_NAME']
12
+ config.fog_public = true
13
+ config.fog_attributes = { 'Cache-Control' => 'max-age=315576000' }
14
+ config.fog_credentials = {
15
+ provider: 'AWS',
16
+ aws_access_key_id: ENV['AWS_S3_ACCESS_KEY_ID'],
17
+ aws_secret_access_key: ENV['AWS_S3_SECRET_ACCESS_KEY']
18
+ }
19
+ end
20
+ end
21
+
22
+ if ENV['CLOUDFRONT_URL']
23
+ CarrierWave.configure do |config|
24
+ config.asset_host = ENV['CLOUDFRONT_URL']
25
+ end
26
+ end
27
+
28
+ if Rails.env.test?
29
+ CarrierWave.configure do |config|
30
+ config.storage = :file
31
+ config.enable_processing = false
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,2 @@
1
+ require 'metova'
2
+ require 'metova/carrierwave/railtie'
@@ -0,0 +1,9 @@
1
+ module Metova
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Metova
4
+
5
+ require 'kaminari'
6
+ require 'responders'
7
+
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module Metova
2
+ module Mandrill
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ initializer "metova.mandrill" do |app|
6
+ if ENV['MANDRILL_DOMAIN']
7
+ app.config.action_mailer.default_url_options = { host: (ENV['MANDRILL_DEFAULT_HOST'] || ENV['MANDRILL_DOMAIN']) }
8
+ app.config.action_mailer.delivery_method = :smtp
9
+ app.config.action_mailer.smtp_settings = {
10
+ address: 'smtp.mandrillapp.com',
11
+ port: 587,
12
+ enable_starttls_auto: true,
13
+ authentication: 'login',
14
+ user_name: ENV['MANDRILL_USERNAME'],
15
+ password: ENV['MANDRILL_PASSWORD'],
16
+ domain: ENV['MANDRILL_DOMAIN']
17
+ }
18
+
19
+ app.routes.default_url_options = app.config.action_mailer.default_url_options
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ require 'metova'
2
+ require 'metova/mandrill/railtie'
@@ -0,0 +1,29 @@
1
+ module Metova
2
+ class Responder < ActionController::Responder
3
+
4
+ prepend Metova::Responders::PaginationResponder
5
+ prepend Metova::Responders::IdsFilterResponder
6
+ prepend Metova::Responders::SortResponder
7
+ include ::Responders::HttpCacheResponder
8
+ include ::Responders::FlashResponder
9
+
10
+ def to_format
11
+ validate!
12
+ if errors.any?
13
+ display({ errors: errors })
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def validate!
20
+ end
21
+
22
+ private
23
+
24
+ def errors
25
+ @_errors ||= []
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module Metova
2
+ module Responders
3
+ module IdsFilterResponder
4
+
5
+ def initialize(*)
6
+ super
7
+ @resource = filter_ids(@resource) if response_should_be_filtered?
8
+ end
9
+
10
+ private
11
+
12
+ def filter_ids(resource)
13
+ resource.where(id: ids)
14
+ end
15
+
16
+ def response_should_be_filtered?
17
+ controller.params.include?(:ids)
18
+ end
19
+
20
+ def ids
21
+ controller.params[:ids].split(',')
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,60 @@
1
+ module Metova
2
+ module Responders
3
+ module PaginationResponder
4
+
5
+ def initialize(*)
6
+ super
7
+ if response_should_be_paginated?
8
+ @resource = paginate(@resource)
9
+ @links = []
10
+ add_next_to_link_header
11
+ add_last_to_link_header
12
+ end
13
+ end
14
+
15
+ def validate!
16
+ if controller.params.include?(:page) && !controller.params.include?(:limit)
17
+ errors << "The 'page' param was sent without 'limit'"
18
+ elsif controller.params.include?(:limit) && !controller.params.include?(:page)
19
+ errors << "The 'limit' param was sent without 'page'"
20
+ end
21
+ super
22
+ end
23
+
24
+ private
25
+
26
+ def paginate(resource)
27
+ resource.page(current_page).per(controller.params[:limit])
28
+ end
29
+
30
+ def response_should_be_paginated?
31
+ controller.params.include?(:page) &&
32
+ controller.params.include?(:limit)
33
+ end
34
+
35
+ def add_next_to_link_header
36
+ page = current_page + 1
37
+ add_to_link_header 'next', page if page <= last_page.to_i
38
+ end
39
+
40
+ def add_last_to_link_header
41
+ add_to_link_header 'last', last_page if last_page
42
+ end
43
+
44
+ def add_to_link_header(rel, page)
45
+ url = controller.url_for(request.params.merge(page: page))
46
+ @links << %Q[<#{url}>; rel="#{rel}"]
47
+ controller.response.headers['Link'] = @links.join(', ')
48
+ end
49
+
50
+ def current_page
51
+ @_current_page ||= controller.params[:page].to_i
52
+ end
53
+
54
+ def last_page
55
+ @_last_page ||= @resource.total_pages
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ module Metova
2
+ module Responders
3
+ module SortResponder
4
+
5
+ def initialize(*)
6
+ super
7
+ @resource = sort(@resource) if response_should_be_sorted?
8
+ end
9
+
10
+ private
11
+
12
+ def sort(resource)
13
+ resource.order(field_to_order_by => direction)
14
+ end
15
+
16
+ def response_should_be_sorted?
17
+ controller.params.include?(:sort)
18
+ end
19
+
20
+ def field_to_order_by
21
+ controller.params[:sort]
22
+ end
23
+
24
+ def direction
25
+ controller.params.fetch(:direction, :asc)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Metova
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ module Metova
2
+ module Versioning
3
+ class Constraints
4
+
5
+ def initialize(version)
6
+ @version = version
7
+ end
8
+
9
+ def matches?(request)
10
+ (@version == 1 && no_version_was_sent?(request)) || current_version_matches_the_version_sent?(request)
11
+ end
12
+
13
+ private
14
+
15
+ def no_version_was_sent?(request)
16
+ !request.headers['Accept'].include?('version=')
17
+ end
18
+
19
+ def current_version_matches_the_version_sent?(request)
20
+ request.headers['Accept'] =~ /version=#{@version}\z/i
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module Metova
2
+ module Versioning
3
+ class Railtie < Rails::Railtie
4
+
5
+ initializer 'metova.versioning.configure' do |app|
6
+ ActionDispatch::Routing::Mapper.send :include, Metova::Versioning::RouterDSL
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Metova
2
+ module Versioning
3
+ module RouterDSL
4
+
5
+ def version(version, &block)
6
+ scope constraints: Metova::Versioning::Constraints.new(version), &block
7
+ match '(*catchall)', to: UnsupportedVersionApp.new, via: [:get, :post, :put, :delete]
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Metova
2
+ module Versioning
3
+ class UnsupportedVersionApp
4
+
5
+ def call(env)
6
+ [
7
+ 412,
8
+ { 'Content-Type' => 'application/json' },
9
+ JSON[{ errors: ['API version was not provided or is not current. Provide the API version in the Accept header (Accept: application/json; version=X)'] }]
10
+ ]
11
+ end
12
+
13
+ end
14
+ end
15
+ end
data/lib/metova.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'metova/engine'
2
+
3
+ require 'metova/responders/pagination_responder'
4
+ require 'metova/responders/ids_filter_responder'
5
+ require 'metova/responders/sort_responder'
6
+ require 'metova/responder'
7
+
8
+ require 'metova/versioning/unsupported_version_app'
9
+ require 'metova/versioning/router_dsl'
10
+ require 'metova/versioning/constraints'
11
+ require 'metova/versioning/railtie'
12
+
13
+ module Metova
14
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :metova do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metova
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Logan Serman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0.rc3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0.rc3
27
+ - !ruby/object:Gem::Dependency
28
+ name: kaminari
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.16.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.16.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: devise
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: responders
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-rails
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
+ - !ruby/object:Gem::Dependency
98
+ name: carrierwave
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Metova libraries for Ruby on Rails
112
+ email:
113
+ - loganserman@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - MIT-LICENSE
119
+ - Rakefile
120
+ - app/assets/javascripts/metova/application.js
121
+ - app/assets/stylesheets/metova/application.css
122
+ - app/controllers/metova/application_controller.rb
123
+ - app/helpers/metova/application_helper.rb
124
+ - app/views/layouts/metova/application.html.erb
125
+ - config/routes.rb
126
+ - lib/metova.rb
127
+ - lib/metova/carrierwave.rb
128
+ - lib/metova/carrierwave/railtie.rb
129
+ - lib/metova/engine.rb
130
+ - lib/metova/mandrill.rb
131
+ - lib/metova/mandrill/railtie.rb
132
+ - lib/metova/responder.rb
133
+ - lib/metova/responders/ids_filter_responder.rb
134
+ - lib/metova/responders/pagination_responder.rb
135
+ - lib/metova/responders/sort_responder.rb
136
+ - lib/metova/version.rb
137
+ - lib/metova/versioning/constraints.rb
138
+ - lib/metova/versioning/railtie.rb
139
+ - lib/metova/versioning/router_dsl.rb
140
+ - lib/metova/versioning/unsupported_version_app.rb
141
+ - lib/tasks/metova_tasks.rake
142
+ homepage: http://github.com/metova/metova
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: 2.0.0
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.4.5
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Metova libraries for Ruby on Rails
166
+ test_files: []