sail 3.2.4 → 3.3.0
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.
- checksums.yaml +4 -4
- data/README.md +47 -6
- data/Rakefile +1 -1
- data/app/models/sail/setting.rb +2 -6
- data/app/views/sail/settings/index.html.erb +14 -4
- data/lib/sail.rb +1 -0
- data/lib/sail/constant_collection.rb +1 -0
- data/lib/sail/engine.rb +6 -0
- data/lib/sail/graphql.rb +43 -0
- data/lib/sail/mutations.rb +49 -0
- data/lib/sail/version.rb +1 -1
- metadata +5 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05fca866e54ba0e38f8d78010f0cbe328b694b7f09619b36a2d533d3c5ed8f92
|
4
|
+
data.tar.gz: 9f95a6750ae40d4086d46fa56ff75323532ffd72cf109ee6a6425589d2220f4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfb372c20ab721d43af3f0d692ba0b1f5ff7d1c9185a4fe7a997c4e966589b1892b8027fecfed329328dce602f17516b3280030c39a67cf5a4de1c21135d3f0b
|
7
|
+
data.tar.gz: 0f238303cd0b2797649996dcf26b1df9a3299f34cc9fb987edf7fa71336ce2bee21bca2c7d416598b208bb87da8c0d45e1784a355e9612d0e1d1cd0960d19bfc
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
[](https://github.com/vinistock/sail/actions) [](https://codecov.io/gh/vinistock/sail) [](https://badge.fury.io/rb/sail)  [](https://github.com/markets/awesome-ruby)
|
4
4
|
|
5
5
|
# Sail
|
6
6
|
|
@@ -139,10 +139,10 @@ All possible cast types as well as detailed examples of usage can be found in th
|
|
139
139
|
# Get setting value with appropriate cast type
|
140
140
|
#
|
141
141
|
# Returns setting value with cast or yields it if passed a block
|
142
|
-
Sail.get(
|
142
|
+
Sail.get(:name)
|
143
143
|
|
144
144
|
# This usage will return the result of the block
|
145
|
-
Sail.get(
|
145
|
+
Sail.get(:name) do |setting_value|
|
146
146
|
my_code(setting_value)
|
147
147
|
end
|
148
148
|
|
@@ -153,15 +153,15 @@ end
|
|
153
153
|
|
154
154
|
# For example, this will ignore ExampleError, but any other error raised will increase
|
155
155
|
# the count until the setting "name" is reset.
|
156
|
-
Sail.get(
|
156
|
+
Sail.get(:name, expected_errors: [ExampleError]) do |value|
|
157
157
|
code_that_can_raise_example_error(value)
|
158
158
|
end
|
159
159
|
|
160
160
|
# Set setting value
|
161
|
-
Sail.set(
|
161
|
+
Sail.set(:name, "value")
|
162
162
|
|
163
163
|
# Reset setting value (requires the sail.yml file!)
|
164
|
-
Sail.reset(
|
164
|
+
Sail.reset(:name)
|
165
165
|
|
166
166
|
# Switcher
|
167
167
|
# This method will take three setting names as parameters
|
@@ -209,6 +209,47 @@ Response
|
|
209
209
|
200 OK
|
210
210
|
```
|
211
211
|
|
212
|
+
### GraphQL
|
213
|
+
|
214
|
+
For GraphQL APIs, types and mutations are defined for convenience. Include Sail's Graphql modules to get the appropriate fields.
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
# app/graphql/types/query_type.rb
|
218
|
+
|
219
|
+
module Types
|
220
|
+
class QueryType < Types::BaseObject
|
221
|
+
include Sail::Graphql::Types
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
# app/graphql/types/mutation_type.rb
|
226
|
+
|
227
|
+
module Types
|
228
|
+
class MutationType < Types::BaseObject
|
229
|
+
include Sail::Graphql::Mutations
|
230
|
+
end
|
231
|
+
end
|
232
|
+
```
|
233
|
+
|
234
|
+
To query settings via GraphQL, use the following pattern.
|
235
|
+
|
236
|
+
```graphql
|
237
|
+
query {
|
238
|
+
sailGet(name: "my_setting")
|
239
|
+
sailSwitcher(positive: "positive_case_setting", negative: "negative_case_setting", throttledBy: "throttle_setting")
|
240
|
+
}
|
241
|
+
|
242
|
+
mutation {
|
243
|
+
sailSet(name: "my_setting", value: "value") {
|
244
|
+
success
|
245
|
+
}
|
246
|
+
|
247
|
+
sailProfileSwitch(name: "my_profile") {
|
248
|
+
success
|
249
|
+
}
|
250
|
+
}
|
251
|
+
```
|
252
|
+
|
212
253
|
## Localization
|
213
254
|
|
214
255
|
Sail's few strings are all localized for English in [en.yml], making it easy to create translations for the desired languages.
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ require "rspec/core/rake_task"
|
|
20
20
|
RSpec::Core::RakeTask.new(spec: "app:db:test:prepare")
|
21
21
|
task default: :spec
|
22
22
|
|
23
|
-
task :
|
23
|
+
task all: :environment do
|
24
24
|
system("brakeman --no-pager && rake && rubocop --auto-correct && rails_best_practices")
|
25
25
|
end
|
26
26
|
|
data/app/models/sail/setting.rb
CHANGED
@@ -11,7 +11,7 @@ module Sail
|
|
11
11
|
class UnexpectedCastType < StandardError; end
|
12
12
|
|
13
13
|
FULL_RANGE = (0...100).freeze
|
14
|
-
AVAILABLE_MODELS = Dir[Rails.root.join("app
|
14
|
+
AVAILABLE_MODELS = Dir[Rails.root.join("app/models/*.rb")]
|
15
15
|
.map { |dir| dir.split("/").last.camelize.gsub(".rb", "") }.freeze
|
16
16
|
|
17
17
|
has_many :entries, dependent: :destroy
|
@@ -32,11 +32,7 @@ module Sail
|
|
32
32
|
|
33
33
|
after_initialize :instantiate_caster
|
34
34
|
|
35
|
-
scope :paginated,
|
36
|
-
select(:name, :description, :group, :value, :cast_type, :updated_at)
|
37
|
-
.offset(page.to_i * per_page)
|
38
|
-
.limit(per_page)
|
39
|
-
}
|
35
|
+
scope :paginated, ->(page, per_page) { offset(page.to_i * per_page).limit(per_page) }
|
40
36
|
|
41
37
|
scope :by_query, lambda { |query|
|
42
38
|
if cast_types.key?(query) || query == Sail::ConstantCollection::STALE
|
@@ -22,13 +22,23 @@
|
|
22
22
|
<div class="clearfix"></div>
|
23
23
|
|
24
24
|
<div class="page-links">
|
25
|
-
<%= link_to("", settings_path(page: [params[:page].to_i - 1, 0].max, monitor_mode: params[:monitor_mode]), method: :get, id: "angle-left-link", title: I18n.t("sail.previous_page")) %>
|
25
|
+
<%= link_to("", settings_path(page: [params[:page].to_i - 1, 0].max, monitor_mode: params[:monitor_mode], query: params[:query]), method: :get, id: "angle-left-link", title: I18n.t("sail.previous_page")) %>
|
26
|
+
<%= link_to(1, settings_path(page: 0, monitor_mode: params[:monitor_mode], query: params[:query]), method: :get, class: params[:page].to_i.zero? || params[:page].blank? ? "active" : "") %>
|
26
27
|
|
27
|
-
<%
|
28
|
-
|
28
|
+
<% if params[:page].to_i - Sail::ConstantCollection::MAX_PAGES > 1 %>
|
29
|
+
●●●
|
29
30
|
<% end %>
|
30
31
|
|
31
|
-
|
32
|
+
<% ([params[:page].to_i - Sail::ConstantCollection::MAX_PAGES, 1].max...[@number_of_pages - 1, params[:page].to_i + Sail::ConstantCollection::MAX_PAGES].min).each do |page| %>
|
33
|
+
<%= link_to(page + 1, settings_path(page: page, monitor_mode: params[:monitor_mode], query: params[:query]), method: :get, class: params[:page].to_i == page || params[:page].blank? && page.zero? ? "active" : "") %>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<% if params[:page].to_i + Sail::ConstantCollection::MAX_PAGES < @number_of_pages - 1 %>
|
37
|
+
●●●
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
<%= link_to(@number_of_pages, settings_path(page: @number_of_pages - 1, monitor_mode: params[:monitor_mode], query: params[:query]), method: :get, class: params[:page].to_i == @number_of_pages - 1 ? "active" : "") %>
|
41
|
+
<%= link_to("", settings_path(page: [params[:page].to_i + 1, @number_of_pages - 1].min, monitor_mode: params[:monitor_mode], query: params[:query]), method: :get, id: "angle-right-link", title: I18n.t("sail.next_page")) %>
|
32
42
|
</div>
|
33
43
|
</div>
|
34
44
|
<% end %>
|
data/lib/sail.rb
CHANGED
data/lib/sail/engine.rb
CHANGED
@@ -37,6 +37,12 @@ module Sail
|
|
37
37
|
end
|
38
38
|
|
39
39
|
config.after_initialize do
|
40
|
+
if Rails::VERSION::MAJOR < 5
|
41
|
+
warn(
|
42
|
+
"DEPRECATION WARNING: Sail will no longer support Rails versions < 5"
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
40
46
|
errors = [ActiveRecord::NoDatabaseError]
|
41
47
|
errors << PG::ConnectionBad if defined?(PG)
|
42
48
|
|
data/lib/sail/graphql.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
module Sail
|
5
|
+
# Graphql
|
6
|
+
#
|
7
|
+
# Module to include type definitions
|
8
|
+
# for GraphQL APIs.
|
9
|
+
module Graphql
|
10
|
+
autoload :Mutations, "sail/mutations"
|
11
|
+
|
12
|
+
module Types # :nodoc:
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
field :sail_get, ::GraphQL::Types::JSON, null: true do
|
17
|
+
description "Returns the value for a given setting."
|
18
|
+
argument :name, String, required: true, description: "The setting's name."
|
19
|
+
end
|
20
|
+
|
21
|
+
field :sail_switcher, ::GraphQL::Types::JSON, null: true do
|
22
|
+
description "Switches between the positive or negative setting based on the throttle."
|
23
|
+
argument :positive, String, required: true, description: "The setting's name if the throttle is bigger than the desired amount."
|
24
|
+
argument :negative, String, required: true, description: "The setting's name if the throttle is smaller than the desired amount."
|
25
|
+
argument :throttled_by, String, required: true, description: "The throttle setting's name."
|
26
|
+
end
|
27
|
+
|
28
|
+
def sail_get(name:)
|
29
|
+
Sail.get(name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sail_switcher(positive:, negative:, throttled_by:)
|
33
|
+
Sail.switcher(
|
34
|
+
positive: positive,
|
35
|
+
negative: negative,
|
36
|
+
throttled_by: throttled_by
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# :nocov:
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
module Sail
|
5
|
+
module Graphql
|
6
|
+
module Mutations # :nodoc:
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
field :sail_set, mutation: SailSet do
|
11
|
+
description "Set the value for a setting."
|
12
|
+
argument :name, String, required: true
|
13
|
+
argument :value, String, required: true
|
14
|
+
end
|
15
|
+
|
16
|
+
field :sail_profile_switch, mutation: SailProfileSwitch do
|
17
|
+
description "Switches to the chosen profile."
|
18
|
+
argument :name, String, required: true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class SailSet < ::GraphQL::Schema::Mutation # :nodoc:
|
23
|
+
argument :name, String, required: true
|
24
|
+
argument :value, String, required: true
|
25
|
+
|
26
|
+
field :success, Boolean, null: false
|
27
|
+
|
28
|
+
def resolve(name:, value:)
|
29
|
+
_, success = Sail.set(name, value)
|
30
|
+
{ success: success }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class SailProfileSwitch < ::GraphQL::Schema::Mutation # :nodoc:
|
35
|
+
argument :name, String, required: true
|
36
|
+
|
37
|
+
field :success, Boolean, null: false
|
38
|
+
|
39
|
+
def resolve(name:)
|
40
|
+
success = Profile.exists?(name: name)
|
41
|
+
Profile.switch(name)
|
42
|
+
|
43
|
+
{ success: success }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# :nocov:
|
data/lib/sail/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinicius Stock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sassc-rails
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: byebug
|
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
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: capybara
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,20 +122,6 @@ dependencies:
|
|
136
122
|
- - ">="
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: codeclimate-test-reporter
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '1.0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '1.0'
|
153
125
|
- !ruby/object:Gem::Dependency
|
154
126
|
name: database_cleaner
|
155
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -375,7 +347,9 @@ files:
|
|
375
347
|
- lib/sail/configuration.rb
|
376
348
|
- lib/sail/constant_collection.rb
|
377
349
|
- lib/sail/engine.rb
|
350
|
+
- lib/sail/graphql.rb
|
378
351
|
- lib/sail/instrumenter.rb
|
352
|
+
- lib/sail/mutations.rb
|
379
353
|
- lib/sail/railtie.rb
|
380
354
|
- lib/sail/types.rb
|
381
355
|
- lib/sail/types/ab_test.rb
|
@@ -402,7 +376,7 @@ licenses:
|
|
402
376
|
metadata: {}
|
403
377
|
post_install_message: |
|
404
378
|
**************************************************************************
|
405
|
-
Sail 3.
|
379
|
+
Sail 3.3.0!
|
406
380
|
|
407
381
|
For major version upgrades, check the CHANGELOG and run the updater to
|
408
382
|
create necessary migrations.
|