alephbet 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5810939a6190541eae1871206aa006520f035e73db99691bbdb55774621ba46a
4
- data.tar.gz: 5ccd87046ef852d8bab6916cc93ba6505f2a2a6ca0d97a5ebef14bcc505f8291
3
+ metadata.gz: c971b8cb75c095dbde099fb3f59dd83e420cc48e9b6a1172e61587b2ea8a9dc1
4
+ data.tar.gz: 472e4e0b7cbd85a235f99fb6388a45ff714246e82633929d1d4d8d012e09e448
5
5
  SHA512:
6
- metadata.gz: 22a3cdff22bb2e8879d3c405beb441dcd561a291f9abc01a7d08cd7949e25aacbaaa99e5b1a979345d7435194ed43b281bd0ed747e1c776c4c85aee5f485f266
7
- data.tar.gz: c5d782af07facd9fb8505329d3f7f4a695f33149fb6f8701e05cda517a275d8937b248ba81dab39d26c920d93b92464e04fc6e1de64730b0aee34bd89699cb9e
6
+ metadata.gz: 587b7c4291025cc0414480c7cdc3b7a4f1ee16bf56733cdffe8ff8f9de998b6def238d30894532fc1e5682ea8e80810b098b839affb6bab345d82b6cd7522fe8
7
+ data.tar.gz: e56b686c9cc246b72493cf2ebda60ad3b5122c4c328169f6f96949de8980b2f702e6eacf9ff5889656026f80c49039d816c8b6ffb9a0a976a996ace13f3aa6ec
@@ -1,5 +1,15 @@
1
1
  module Alephbet
2
2
  class ApplicationController < ActionController::Base
3
- protect_from_forgery with: :exception
3
+ protect_from_forgery :with => :exception
4
+ before_action :cors_headers, :if => -> { Alephbet.enable_cors }
5
+
6
+ private
7
+
8
+ def cors_headers
9
+ response.headers["Access-Control-Allow-Origin"] = Alephbet.cors_allow_origin
10
+ response.headers["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
11
+ response.headers["Access-Control-Allow-Headers"] = Alephbet.cors_allow_headers
12
+ response.headers["Access-Control-Max-Age"] = "1728000"
13
+ end
4
14
  end
5
15
  end
@@ -4,7 +4,6 @@ module Alephbet
4
4
 
5
5
  # acts a browser-friendly API endpoint
6
6
  skip_before_action :verify_authenticity_token
7
- before_action :cors_headers
8
7
  before_action :check_api_key, :except => :cors_preflight_check
9
8
 
10
9
  def experiments
@@ -82,12 +81,5 @@ module Alephbet
82
81
  def permitted_params
83
82
  params.permit(PARAMS)
84
83
  end
85
-
86
- def cors_headers
87
- response.headers["Access-Control-Allow-Origin"] = Alephbet.cors_allow_origin
88
- response.headers["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
89
- response.headers["Access-Control-Allow-Headers"] = Alephbet.cors_allow_headers
90
- response.headers["Access-Control-Max-Age"] = "1728000"
91
- end
92
84
  end
93
85
  end
data/lib/alephbet.rb CHANGED
@@ -2,11 +2,12 @@ require "alephbet/engine"
2
2
 
3
3
  module Alephbet
4
4
  class << self
5
- attr_accessor :api_key, :cors_allow_origin, :cors_allow_headers
5
+ attr_accessor :api_key, :enable_cors, :cors_allow_origin, :cors_allow_headers
6
6
 
7
7
  def setup
8
8
  # fallback api_key if none specified
9
9
  self.api_key = SecureRandom.uuid
10
+ self.enable_cors = true
10
11
  self.cors_allow_origin = "*"
11
12
  self.cors_allow_headers = "*"
12
13
  yield(self) if block_given?
@@ -1,3 +1,3 @@
1
1
  module Alephbet
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  Alephbet.setup do |config|
2
2
  config.api_key = ENV["ALEPHBET_API_KEY"] || SecureRandom.uuid
3
+ config.enable_cors = true
3
4
  config.cors_allow_origin = "*"
4
5
  config.cors_allow_headers = "*"
5
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoav Aner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-03 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails