Skip to content

Commit

Permalink
Merge pull request #94 from SonicGarden/dev
Browse files Browse the repository at this point in the history
[review] Use cloudfront host
  • Loading branch information
aki77 authored Sep 11, 2024
2 parents db6c901 + 2d987c4 commit 0e6008a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 58 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,9 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.0", 3.1, 3.2, 3,3]
gemfile: ["6.1", "7.0", "7.1", "main"]
exclude:
- ruby: "3.0"
gemfile: "main"
- ruby: "3.1"
gemfile: "6.1"
- ruby: "3.2"
gemfile: "6.1"
- ruby: "3.3"
gemfile: "6.1"
ruby: [3.1, 3.2, 3,3]
gemfile: ["7.0", "7.1", "7.2", "main"]
exclude: []
steps:
- name: Install packages
run: |
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ bundle exec rake copy_tuner:export

これで、`config/locales/copy_tuner.yml` に翻訳ファイルが作成されます。

## IE等のレガシーブラウザ対応が必要な場合

以下のスクリプトタグを追加する。(必要なpolyfillを個別に読み込んでも可)

```
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
```

[Polyfill service](https://cdn.polyfill.io/v2/docs/)

Development
=================

Expand Down
13 changes: 6 additions & 7 deletions copy_tuner_client.gemspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# -*- encoding: utf-8 -*-
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'copy_tuner_client/version'

Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0.0'
s.required_ruby_version = '>= 3.1.0'
s.add_dependency 'i18n', '>= 0.5.0'
s.add_dependency 'json'
s.add_dependency 'nokogiri'
s.add_development_dependency 'rails', '~> 6.1'
s.add_development_dependency 'rails', '~> 7.0'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
s.add_development_dependency 'sham_rack'
Expand All @@ -17,14 +16,14 @@ Gem::Specification.new do |s|
s.add_development_dependency 'webmock'
s.add_development_dependency 'yard'
s.authors = ['SonicGarden']
s.email = '[email protected]'
s.email = '[email protected]'
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.files = `git ls-files`.split("\n")
s.homepage = 'https://github.com/SonicGarden/copy-tuner-ruby-client'
s.name = 'copy_tuner_client'
s.name = 'copy_tuner_client'
s.platform = Gem::Platform::RUBY
s.require_paths = ['lib']
s.summary = 'Client for the CopyTuner copy management service'
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.version = CopyTunerClient::VERSION
s.metadata['rubygems_mfa_required'] = 'true'
end
File renamed without changes.
55 changes: 26 additions & 29 deletions lib/copy_tuner_client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
module CopyTunerClient
# Used to set up and modify settings for the client.
class Configuration

# These options will be present in the Hash returned by {#to_hash}.
OPTIONS = [:api_key, :development_environments, :environment_name, :host,
:http_open_timeout, :http_read_timeout, :client_name, :client_url,
:client_version, :port, :protocol, :proxy_host, :proxy_pass,
:proxy_port, :proxy_user, :secure, :polling_delay, :sync_interval,
:sync_interval_staging, :sync_ignore_path_regex, :logger,
:framework, :middleware, :disable_middleware, :disable_test_translation,
:ca_file, :exclude_key_regexp, :s3_host, :locales, :ignored_keys, :ignored_key_handler].freeze
OPTIONS = %i[api_key development_environments environment_name host
http_open_timeout http_read_timeout client_name client_url
client_version port protocol proxy_host proxy_pass
proxy_port proxy_user secure polling_delay sync_interval
sync_interval_staging sync_ignore_path_regex logger
framework middleware disable_middleware disable_test_translation
ca_file exclude_key_regexp s3_host locales ignored_keys ignored_key_handler].freeze

# @return [String] The API key for your project, found on the project edit form.
attr_accessor :api_key
Expand Down Expand Up @@ -137,14 +136,14 @@ class Configuration
# @return [Proc]
attr_accessor :ignored_key_handler

alias_method :secure?, :secure
alias secure? secure

# Instantiated from {CopyTunerClient.configure}. Sets defaults.
def initialize
self.client_name = 'CopyTuner Client'
self.client_url = 'https://rubygems.org/gems/copy_tuner_client'
self.client_version = VERSION
self.development_environments = %w(development staging)
self.development_environments = %w[development staging]
self.host = 'copy-tuner.com'
self.http_open_timeout = 5
self.http_read_timeout = 5
Expand All @@ -153,14 +152,14 @@ def initialize
self.sync_interval = 60
self.sync_interval_staging = 0
self.secure = true
self.test_environments = %w(test cucumber)
self.test_environments = %w[test cucumber]
self.upload_disabled_environments = %w[production staging]
self.s3_host = 'copy-tuner-data-prod.s3.amazonaws.com'
self.s3_host = 'copy-tuner.sg-apps.com' # NOTE: cloudfront host
self.disable_copyray_comment_injection = false
# TODO: 0.18.0以降のバージョンで初期値をtrueにしたい
self.html_escape = nil
self.ignored_keys = []
self.ignored_key_handler = -> (e) { raise e }
self.ignored_key_handler = ->(e) { raise e }

@applied = false
end
Expand Down Expand Up @@ -238,13 +237,11 @@ def applied?
#
# When {#test?} returns +false+, the poller will be started.
def apply
self.locales ||= begin
if defined?(::Rails)
self.locales = ::Rails.application.config.i18n.available_locales.presence || Array(::Rails.application.config.i18n.default_locale)
else
self.locales = [:en]
end
end
self.locales ||= self.locales = if defined?(::Rails)
::Rails.application.config.i18n.available_locales.presence || Array(::Rails.application.config.i18n.default_locale)
else
[:en]
end

self.client ||= Client.new(to_hash)
self.cache ||= Cache.new(client, to_hash)
Expand All @@ -253,8 +250,8 @@ def apply
I18n.backend = I18nBackend.new(cache)

if enable_middleware?
logger.info "Using copytuner sync middleware"
request_sync_options = {:poller => @poller, :cache => cache, :interval => sync_interval, :ignore_regex => sync_ignore_path_regex}
logger.info 'Using copytuner sync middleware'
request_sync_options = { poller: @poller, cache:, interval: sync_interval, ignore_regex: sync_ignore_path_regex }
if middleware_position.is_a?(Hash) && middleware_position[:before]
middleware.insert_before middleware_position[:before], RequestSync, request_sync_options
middleware.insert_before middleware_position[:before], CopyTunerClient::CopyrayMiddleware
Expand All @@ -266,7 +263,7 @@ def apply
middleware.use CopyTunerClient::CopyrayMiddleware
end
else
logger.info "[[[Warn]]] Not using copytuner sync middleware" unless middleware
logger.info '[[[Warn]]] Not using copytuner sync middleware' unless middleware
end

@applied = true
Expand All @@ -278,8 +275,8 @@ def apply
process_guard.start
end

if !(test? && disable_test_translation)
logger.info "Download translation now"
unless test? && disable_test_translation
logger.info 'Download translation now'
cache.download
end
end
Expand All @@ -302,19 +299,19 @@ def protocol
# @return [String] a description of the environment in which this configuration was built.
def environment_info
parts = ["Ruby: #{RUBY_VERSION}", framework, "Env: #{environment_name}"]
parts.compact.map { |part| "[#{part}]" }.join(" ")
parts.compact.map { |part| "[#{part}]" }.join(' ')
end

# Wraps the given logger in a PrefixedLogger. This way, CopyTunerClient
# log messages are recognizable.
# @param original_logger [Logger] the upstream logger to use, which must respond to the standard +Logger+ severity methods.
def logger=(original_logger)
@logger = PrefixedLogger.new("** [CopyTuner]", original_logger)
@logger = PrefixedLogger.new('** [CopyTuner]', original_logger)
end

# Sync interval for Rack Middleware
def sync_interval
if environment_name == "staging"
if environment_name == 'staging'
@sync_interval_staging
else
@sync_interval
Expand All @@ -323,7 +320,7 @@ def sync_interval

# @return [String] current project url by api_key
def project_url
URI::Generic.build(:scheme => self.protocol, :host => self.host, :port => self.port.to_i, :path => "/projects/#{self.api_key}").to_s
URI::Generic.build(scheme: self.protocol, host: self.host, port: self.port.to_i, path: "/projects/#{self.api_key}").to_s
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/copy_tuner_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CopyTunerClient
# Client version
VERSION = '0.18.0'.freeze
VERSION = '0.19.0'.freeze

# API version being used to communicate with the server
API_VERSION = '2.0'.freeze
Expand Down

0 comments on commit 0e6008a

Please sign in to comment.