apicasso 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +1,44 @@
1
- # frozen_string_literal: true
2
-
3
- # This concern is used to provide abstract ordering based on `params[:sort]`
4
- module Orderable
5
- extend ActiveSupport::Concern
6
- SORT_ORDER = { '+' => :asc, '-' => :desc }.freeze
7
-
8
- # A list of the param names that can be used for ordering the model list
9
- def ordering_params(params)
10
- # For example it retrieves a list of orders in descending order of total_value.
11
- # Within a specific total_value, older orders are ordered first
12
- #
13
- # GET /orders?sort=-total_value,created_at
14
- # ordering_params(params) # => { total_value: :desc, created_at: :asc }
15
- #
16
- # Usage:
17
- # Order.order(ordering_params(params))
18
- ordering = {}
19
- params[:sort].try(:split, ',').try(:each) do |attr|
20
- parsed_attr = parse_attr attr
21
- if model.attribute_names.include?(parsed_attr)
22
- ordering[parsed_attr] = SORT_ORDER[parse_sign attr]
23
- end
24
- end
25
- ordering
26
- end
27
-
28
- private
29
-
30
- # Parsing of attributes to avoid empty starts in case browser passes "+" as " "
31
- def parse_attr(attr)
32
- return attr.gsub(/^\ (.*)/, '\1') if attr.starts_with?(' ')
33
- attr[1..-1]
34
- end
35
-
36
- # Ordering sign parse, which separates
37
- def parse_sign(attr)
38
- attr =~ /\A[+-]/ ? attr.slice!(0) : '+'
39
- end
40
-
41
- def model
42
- (params[:resource] || params[:nested] || controller_name).classify.constantize
43
- end
44
- end
1
+ # frozen_string_literal: true
2
+
3
+ # This concern is used to provide abstract ordering based on `params[:sort]`
4
+ module Orderable
5
+ extend ActiveSupport::Concern
6
+ SORT_ORDER = { '+' => :asc, '-' => :desc }.freeze
7
+
8
+ # A list of the param names that can be used for ordering the model list
9
+ def ordering_params(params)
10
+ # For example it retrieves a list of orders in descending order of total_value.
11
+ # Within a specific total_value, older orders are ordered first
12
+ #
13
+ # GET /orders?sort=-total_value,created_at
14
+ # ordering_params(params) # => { total_value: :desc, created_at: :asc }
15
+ #
16
+ # Usage:
17
+ # Order.order(ordering_params(params))
18
+ ordering = {}
19
+ params[:sort].try(:split, ',').try(:each) do |attr|
20
+ parsed_attr = parse_attr attr
21
+ if model.attribute_names.include?(parsed_attr)
22
+ ordering[parsed_attr] = SORT_ORDER[parse_sign attr]
23
+ end
24
+ end
25
+ ordering
26
+ end
27
+
28
+ private
29
+
30
+ # Parsing of attributes to avoid empty starts in case browser passes "+" as " "
31
+ def parse_attr(attr)
32
+ return attr.gsub(/^\ (.*)/, '\1') if attr.starts_with?(' ')
33
+ attr[1..-1]
34
+ end
35
+
36
+ # Ordering sign parse, which separates
37
+ def parse_sign(attr)
38
+ attr =~ /\A[+-]/ ? attr.slice!(0) : '+'
39
+ end
40
+
41
+ def model
42
+ (params[:resource] || params[:nested] || controller_name).classify.constantize
43
+ end
44
+ end
@@ -1,40 +1,40 @@
1
- # frozen_string_literal: true
2
-
3
- module Apicasso
4
- # Ability to parse a scope object from Apicasso::Key
5
- class Ability
6
- include CanCan::Ability
7
-
8
- def initialize(key)
9
- key ||= Apicasso::Key.new
10
- cannot :manage, :all
11
- cannot :read, :all
12
- key.scope.each do |permission, klasses_clearances|
13
- klasses_clearances.each do |klasses|
14
- klasses.each do |klass, clearance|
15
- if clearance == true
16
- # Usage:
17
- # To have a key reading all channels and all accouts
18
- # you would have a scope:
19
- # => `{read: [{channel: true}, {accout: true}]}`
20
- can permission.to_sym, klass.underscore.to_sym
21
- can permission.to_sym, klass.classify.constantize
22
- elsif clearance.class == Hash
23
- # Usage:
24
- # To have a key reading all banners from a channel with id 999
25
- # you would have a scope:
26
- # => `{read: [{banner: {owner_id: [999]}}]}`
27
- can permission.to_sym,
28
- klass.underscore.to_sym
29
- clearance.each do |by_field, values|
30
- can permission.to_sym,
31
- klass.classify.constantize,
32
- by_field => values
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Apicasso
4
+ # Ability to parse a scope object from Apicasso::Key
5
+ class Ability
6
+ include CanCan::Ability
7
+
8
+ def initialize(key)
9
+ key ||= Apicasso::Key.new
10
+ cannot :manage, :all
11
+ cannot :read, :all
12
+ key.scope.each do |permission, klasses_clearances|
13
+ klasses_clearances.each do |klasses|
14
+ klasses.each do |klass, clearance|
15
+ if clearance == true
16
+ # Usage:
17
+ # To have a key reading all channels and all accouts
18
+ # you would have a scope:
19
+ # => `{read: [{channel: true}, {accout: true}]}`
20
+ can permission.to_sym, klass.underscore.to_sym
21
+ can permission.to_sym, klass.classify.constantize
22
+ elsif clearance.class == Hash
23
+ # Usage:
24
+ # To have a key reading all banners from a channel with id 999
25
+ # you would have a scope:
26
+ # => `{read: [{banner: {owner_id: [999]}}]}`
27
+ can permission.to_sym,
28
+ klass.underscore.to_sym
29
+ clearance.each do |by_field, values|
30
+ can permission.to_sym,
31
+ klass.classify.constantize,
32
+ by_field => values
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
- module Apicasso
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- self.table_name_prefix = 'apicasso_'
5
- end
6
- end
1
+ module Apicasso
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ self.table_name_prefix = 'apicasso_'
5
+ end
6
+ end
@@ -1,25 +1,25 @@
1
- # frozen_string_literal: true
2
-
3
- require 'securerandom'
4
- module Apicasso
5
- # A model to abstract API access, with scope options, token generation, request limiting
6
- class Key < ApplicationRecord
7
- before_create :set_auth_token
8
-
9
- private
10
-
11
- # Method that generates `SecureRandom.uuid` as token until
12
- # an unique one has been acquired
13
- def set_auth_token
14
- loop do
15
- self.token = generate_auth_token
16
- break unless self.class.exists?(token: token)
17
- end
18
- end
19
-
20
- # RFC4122 style token
21
- def generate_auth_token
22
- SecureRandom.uuid.delete('-')
23
- end
24
- end
25
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ module Apicasso
5
+ # A model to abstract API access, with scope options, token generation, request limiting
6
+ class Key < ApplicationRecord
7
+ before_create :set_auth_token
8
+
9
+ private
10
+
11
+ # Method that generates `SecureRandom.uuid` as token until
12
+ # an unique one has been acquired
13
+ def set_auth_token
14
+ loop do
15
+ self.token = generate_auth_token
16
+ break unless self.class.exists?(token: token)
17
+ end
18
+ end
19
+
20
+ # RFC4122 style token
21
+ def generate_auth_token
22
+ SecureRandom.uuid.delete('-')
23
+ end
24
+ end
25
+ end
@@ -1,8 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
- module Apicasso
4
- # A model to abstract API access, with scope options, token generation, request limiting
5
- class Request < ApplicationRecord
6
- belongs_to :api_key, class_name: 'Apicasso::Key'
7
- end
8
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Apicasso
4
+ # A model to abstract API access, with scope options, token generation, request limiting
5
+ class Request < ApplicationRecord
6
+ belongs_to :api_key, class_name: 'Apicasso::Key'
7
+ end
8
+ end
data/config/routes.rb CHANGED
@@ -1,14 +1,14 @@
1
- Apicasso::Engine.routes.draw do
2
- scope module: :apicasso do
3
- resources :apidocs, only: [:index]
4
- get '/:resource/', to: 'crud#index', via: :get
5
- match '/:resource/', to: 'crud#create', via: :post
6
- get '/:resource/:id', to: 'crud#show', via: :get
7
- match '/:resource/:id', to: 'crud#update', via: :patch
8
- match '/:resource/:id', to: 'crud#destroy', via: :delete
9
- match '/:resource/:id/:nested/', to: 'crud#nested_index', via: :get
10
- match '/:resource/', to: 'crud#schema', via: :options
11
- match '/:resource/:id', to: 'crud#schema', via: :options
12
- match '/:resource/:id/:nested/', to: 'crud#schema', via: :options
13
- end
14
- end
1
+ Apicasso::Engine.routes.draw do
2
+ scope module: :apicasso do
3
+ resources :apidocs, only: [:index]
4
+ get '/:resource/', to: 'crud#index', via: :get
5
+ match '/:resource/', to: 'crud#create', via: :post
6
+ get '/:resource/:id', to: 'crud#show', via: :get
7
+ match '/:resource/:id', to: 'crud#update', via: :patch
8
+ match '/:resource/:id', to: 'crud#destroy', via: :delete
9
+ match '/:resource/:id/:nested/', to: 'crud#nested_index', via: :get
10
+ match '/:resource/', to: 'crud#schema', via: :options
11
+ match '/:resource/:id', to: 'crud#schema', via: :options
12
+ match '/:resource/:id/:nested/', to: 'crud#schema', via: :options
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ class CreateApicassoTables < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :apicasso_keys, id: :uuid do |t|
4
+ t.json :scope
5
+ t.integer :scope_type
6
+ t.json :request_limiting
7
+ t.text :token
8
+ t.datetime :deleted_at
9
+ t.timestamps null: false
10
+ end
11
+ create_table :apicasso_requests, id: :uuid do |t|
12
+ t.text :api_key_id
13
+ t.json :object
14
+ t.timestamps null: false
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
- module Apicasso
4
- class Engine < ::Rails::Engine
5
- end
6
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Apicasso
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
- module Apicasso
2
- VERSION = '0.2.14'
3
- end
1
+ module Apicasso
2
+ VERSION = '0.2.15'
3
+ end
data/lib/apicasso.rb CHANGED
@@ -1,9 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- require 'apicasso/version'
4
- require 'apicasso/engine'
5
- require 'apicasso/active_record_extension'
6
-
7
- module Apicasso
8
- # Your code goes here...
9
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'apicasso/version'
4
+ require 'apicasso/engine'
5
+ require 'apicasso/active_record_extension'
6
+
7
+ module Apicasso
8
+ # Your code goes here...
9
+ end
@@ -1,25 +1,25 @@
1
- require 'rails/generators/migration'
2
-
3
- module Apicasso
4
- module Generators
5
- class InstallGenerator < ::Rails::Generators::Base
6
- include Rails::Generators::Migration
7
- source_root File.expand_path('../templates', __FILE__)
8
- desc 'Add the required migrations to run APIcasso'
9
-
10
- def self.next_migration_number(path)
11
- if @prev_migration_nr
12
- @prev_migration_nr += 1
13
- else
14
- @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
15
- end
16
- @prev_migration_nr.to_s
17
- end
18
-
19
- def copy_migrations
20
- migration_template 'create_apicasso_tables.rb',
21
- 'db/migrate/create_apicasso_tables.rb'
22
- end
23
- end
24
- end
25
- end
1
+ require 'rails/generators/migration'
2
+
3
+ module Apicasso
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ desc 'Add the required migrations to run APIcasso'
9
+
10
+ def self.next_migration_number(path)
11
+ if @prev_migration_nr
12
+ @prev_migration_nr += 1
13
+ else
14
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
15
+ end
16
+ @prev_migration_nr.to_s
17
+ end
18
+
19
+ def copy_migrations
20
+ migration_template 'create_apicasso_tables.rb',
21
+ 'db/migrate/create_apicasso_tables.rb'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,17 +1,17 @@
1
- class CreateApicassoTables < ActiveRecord::Migration[5.0]
2
- def change
3
- create_table :apicasso_keys, id: :uuid do |t|
4
- t.json :scope
5
- t.integer :scope_type
6
- t.json :request_limiting
7
- t.text :token
8
- t.datetime :deleted_at
9
- t.timestamps null: false
10
- end
11
- create_table :apicasso_requests, id: :uuid do |t|
12
- t.text :api_key_id
13
- t.json :object
14
- t.timestamps null: false
15
- end
16
- end
17
- end
1
+ class CreateApicassoTables < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :apicasso_keys, id: :uuid do |t|
4
+ t.json :scope
5
+ t.integer :scope_type
6
+ t.json :request_limiting
7
+ t.text :token
8
+ t.datetime :deleted_at
9
+ t.timestamps null: false
10
+ end
11
+ create_table :apicasso_requests, id: :uuid do |t|
12
+ t.text :api_key_id
13
+ t.json :object
14
+ t.timestamps null: false
15
+ end
16
+ end
17
+ end
@@ -1,4 +1,4 @@
1
- # desc "Explaining what the task does"
2
- # task :apicasso do
3
- # # Task goes here
4
- # end
1
+ # desc "Explaining what the task does"
2
+ # task :apicasso do
3
+ # # Task goes here
4
+ # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apicasso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Bellincanta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-04 00:00:00.000000000 Z
11
+ date: 2018-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan
@@ -106,6 +106,7 @@ files:
106
106
  - app/models/apicasso/key.rb
107
107
  - app/models/apicasso/request.rb
108
108
  - config/routes.rb
109
+ - db/migrate/20180826141433_create_apicasso_tables.rb
109
110
  - lib/apicasso.rb
110
111
  - lib/apicasso/active_record_extension.rb
111
112
  - lib/apicasso/engine.rb
@@ -133,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  requirements: []
135
136
  rubyforge_project:
136
- rubygems_version: 2.6.14
137
+ rubygems_version: 2.7.6
137
138
  signing_key:
138
139
  specification_version: 4
139
140
  summary: An abstract API design as a mountable engine