arturo 2.8.0 → 3.0.0.pre.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e10b34b3f169fc7642d26b9e2fca3873256b27636293bfe35676e71d9149bdbf
4
- data.tar.gz: 6a7849fc61643a2f2c876710aa9a155f0acd04877ee6c708e8dfd64a4fc7c86a
3
+ metadata.gz: 30446d1fe69cd50b3dc0fd9c74c6c7ee58d7b9f260bde78318b8a0f5b4caff54
4
+ data.tar.gz: bcd88c75f01ead72f559acefb0ed0ffb2c0efba71cf52c3787a7893299f43edf
5
5
  SHA512:
6
- metadata.gz: d3783d7e7b12b26205262254ec63a9ea65911f6d290420fb642daa5cffa5181b81a0d550ac1fd211f7fa4768c54571fe07164db2aa4669f606cb837f9819cc05
7
- data.tar.gz: d7d7f696e99869f400fadc6e8bb461e6769ab778e46b4b108c092b2a9cba82cb911e413c7e889c240ca82d8e71f3c958249bd53e34418c038d405706e9966d00
6
+ metadata.gz: b74df3cbf4fa5ab8be57c9dd318e0d565298b2ab48afd149586878911c6693ede1f2021a8c1ae55a56dbbe591262d1baff510812ee84c6bfaebca05e71a28b49
7
+ data.tar.gz: 9cd77e352e3eadcf7079de6d2c63abf17b17db2b41743f4498938e45f78f7d62fbddfe2a3b19f5ad3354fc10f57b3de5acc457f2031142bea5aeb576b5e0c9ea
data/README.md CHANGED
@@ -86,6 +86,7 @@ rails g arturo:migration
86
86
  rails g arturo:initializer
87
87
  rails g arturo:routes
88
88
  rails g arturo:assets
89
+ rails g arturo:feature_model
89
90
  ```
90
91
 
91
92
  #### Run the migration:
@@ -98,6 +99,10 @@ rake db:migrate
98
99
 
99
100
  #### Edit the configuration
100
101
 
102
+ #### Edit the Feature model
103
+
104
+ By default, the generated model `Arturo::Feature` inherits from `ActiveRecord::Base`. However, if you’re using multiple databases your models should inherit from an abstract class that specifies a database connection, not directly from `ActiveRecord::Base`. Update the generated model in `app/models/arturo/feature.rb` to make it use a correct database.
105
+
101
106
  ##### Initializer
102
107
 
103
108
  Open up the newly-generated `config/initializers/arturo_initializer.rb`.
@@ -1,41 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
  require 'active_record'
3
+ require 'active_support'
3
4
 
4
- # a stub
5
- # possible TODO: remove and and refactor into an acts_as_feature mixin
6
5
  module Arturo
7
- class Feature < ::ActiveRecord::Base
8
-
6
+ module FeatureMethods
7
+ extend ActiveSupport::Concern
9
8
  include Arturo::SpecialHandling
10
9
 
11
- Arturo::Feature::SYMBOL_REGEX = /^[a-zA-z][a-zA-Z0-9_]*$/
10
+ SYMBOL_REGEX = /^[a-zA-z][a-zA-Z0-9_]*$/
12
11
  DEFAULT_ATTRIBUTES = { :deployment_percentage => 0 }.with_indifferent_access
13
12
 
14
- attr_readonly :symbol
15
-
16
- validates_presence_of :symbol, :deployment_percentage
17
- validates_uniqueness_of :symbol, :allow_blank => true, :case_sensitive => false
18
- validates_numericality_of :deployment_percentage,
19
- :only_integer => true,
20
- :allow_blank => true,
21
- :greater_than_or_equal_to => 0,
22
- :less_than_or_equal_to => 100
23
-
24
- # Looks up a feature by symbol. Also accepts a Feature as input.
25
- # @param [Symbol, Arturo::Feature] feature_or_name a Feature or the Symbol of a Feature
26
- # @return [Arturo::Feature, nil] the Feature if found, else Arturo::NoSuchFeature
27
- def self.to_feature(feature_or_symbol)
28
- return feature_or_symbol if feature_or_symbol.kind_of?(self)
29
- symbol = feature_or_symbol.to_sym.to_s
30
- self.where(:symbol => symbol).first || Arturo::NoSuchFeature.new(symbol)
13
+ included do
14
+ attr_readonly :symbol
15
+
16
+ validates_presence_of :symbol, :deployment_percentage
17
+ validates_uniqueness_of :symbol, :allow_blank => true, :case_sensitive => false
18
+ validates_numericality_of :deployment_percentage,
19
+ :only_integer => true,
20
+ :allow_blank => true,
21
+ :greater_than_or_equal_to => 0,
22
+ :less_than_or_equal_to => 100
31
23
  end
32
24
 
33
- # Looks up a feature by symbol. Also accepts a Feature as input.
34
- # @param [Symbol, Arturo::Feature] feature_or_name a Feature or the Symbol of a Feature
35
- # @return [Arturo::Feature, nil] the Feature if found, else nil
36
- def self.find_feature(feature_or_symbol)
37
- feature = to_feature(feature_or_symbol)
38
- feature.is_a?(Arturo::NoSuchFeature) ? nil : feature
25
+ class_methods do
26
+ # Looks up a feature by symbol. Also accepts a Feature as input.
27
+ # @param [Symbol, Arturo::Feature] feature_or_symbol a Feature or the Symbol of a Feature
28
+ # @return [Arturo::Feature, Arturo::NoSuchFeature] the Feature if found, else Arturo::NoSuchFeature
29
+ def to_feature(feature_or_symbol)
30
+ return feature_or_symbol if feature_or_symbol.kind_of?(self)
31
+
32
+ symbol = feature_or_symbol.to_sym.to_s
33
+ self.where(:symbol => symbol).first || Arturo::NoSuchFeature.new(symbol)
34
+ end
35
+
36
+ # Looks up a feature by symbol. Also accepts a Feature as input.
37
+ # @param [Symbol, Arturo::Feature] feature_or_symbol a Feature or the Symbol of a Feature
38
+ # @return [Arturo::Feature, nil] the Feature if found, else nil
39
+ def find_feature(feature_or_symbol)
40
+ feature = to_feature(feature_or_symbol)
41
+ feature.is_a?(Arturo::NoSuchFeature) ? nil : feature
42
+ end
43
+
44
+ def last_updated_at
45
+ maximum(:updated_at)
46
+ end
39
47
  end
40
48
 
41
49
  # Create a new Feature
@@ -59,6 +67,7 @@ module Arturo
59
67
 
60
68
  def name
61
69
  return I18n.translate("arturo.feature.nameless") if symbol.blank?
70
+
62
71
  I18n.translate("arturo.feature.#{symbol}", :default => symbol.to_s.titleize)
63
72
  end
64
73
 
@@ -74,10 +83,6 @@ module Arturo
74
83
  "<Arturo::Feature #{name}, deployed to #{deployment_percentage}%>"
75
84
  end
76
85
 
77
- def self.last_updated_at
78
- maximum(:updated_at)
79
- end
80
-
81
86
  # made public so as to allow for thresholds stored outside of the model
82
87
  def passes_threshold?(feature_recipient, threshold)
83
88
  return true if threshold == 100
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
2
5
  module Arturo
3
6
 
4
7
  # Adds whitelist and blacklist support to individual features by name
@@ -25,13 +28,9 @@ module Arturo
25
28
  # This is particularly important if your application runs in several
26
29
  # different processes or on several servers.
27
30
  module SpecialHandling
31
+ extend ActiveSupport::Concern
28
32
 
29
- def self.included(base)
30
- base.extend Arturo::SpecialHandling::ClassMethods
31
- end
32
-
33
- module ClassMethods
34
-
33
+ class_methods do
35
34
  def whitelists
36
35
  @whitelists ||= []
37
36
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Arturo
3
- VERSION = '2.8.0'
3
+ VERSION = '3.0.0.pre.1'
4
4
  end
data/lib/arturo.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  module Arturo
3
3
  require 'arturo/null_logger'
4
4
  require 'arturo/special_handling'
5
+ require 'arturo/feature'
5
6
  require 'arturo/feature_availability'
6
7
  require 'arturo/feature_management'
7
8
  require 'arturo/feature_caching'
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'rails/generators'
3
+
4
+ module Arturo
5
+ class FeatureModelGenerator < Rails::Generators::Base
6
+ def self.source_root
7
+ File.join(File.dirname(__FILE__), 'templates')
8
+ end
9
+
10
+ def copy_feature_model_file
11
+ copy_file "feature.rb", "app/models/arturo/feature.rb"
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rails/generators'
3
4
  require 'rails/generators/migration'
5
+ require 'rails/generators/active_record'
4
6
 
5
7
  module Arturo
6
8
  class MigrationGenerator < Rails::Generators::Base
@@ -10,19 +12,16 @@ module Arturo
10
12
  File.join(File.dirname(__FILE__), 'templates')
11
13
  end
12
14
 
13
- # Implement the required interface for Rails::Generators::Migration.
14
- # taken from
15
- # http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
16
- def self.next_migration_number(dirname) #:nodoc:
17
- if ActiveRecord::Base.timestamped_migrations
18
- Time.now.utc.strftime("%Y%m%d%H%M%S")
19
- else
20
- "%.3d" % (current_migration_number(dirname) + 1)
21
- end
15
+ def self.next_migration_number(dirname)
16
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
22
17
  end
23
18
 
24
19
  def create_migration_file
25
- migration_template 'migration.rb', 'db/migrate/create_features.rb'
20
+ migration_template 'migration.erb', 'db/migrate/create_features.rb', { migration_version: migration_version }
21
+ end
22
+
23
+ def migration_version
24
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
26
25
  end
27
26
  end
28
27
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+
5
+ module Arturo
6
+ class Feature < ::ActiveRecord::Base
7
+ include Arturo::FeatureMethods
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateFeatures < ActiveRecord::Migration<%= migration_version %>
4
+ def self.up
5
+ create_table :features do |t|
6
+ t.string :symbol, null: false
7
+ t.integer :deployment_percentage, null: false
8
+ # Any additional fields here
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+
14
+ def self.down
15
+ drop_table :features
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arturo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 3.0.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James A. Rosen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-14 00:00:00.000000000 Z
11
+ date: 2023-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -159,12 +159,14 @@ files:
159
159
  - lib/arturo/test_support.rb
160
160
  - lib/arturo/version.rb
161
161
  - lib/generators/arturo/assets_generator.rb
162
+ - lib/generators/arturo/feature_model_generator.rb
162
163
  - lib/generators/arturo/initializer_generator.rb
163
164
  - lib/generators/arturo/migration_generator.rb
164
165
  - lib/generators/arturo/routes_generator.rb
165
166
  - lib/generators/arturo/templates/arturo_customizations.css
167
+ - lib/generators/arturo/templates/feature.rb
166
168
  - lib/generators/arturo/templates/initializer.rb
167
- - lib/generators/arturo/templates/migration.rb
169
+ - lib/generators/arturo/templates/migration.erb
168
170
  homepage: http://github.com/zendesk/arturo
169
171
  licenses:
170
172
  - APLv2
@@ -180,9 +182,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
182
  version: '2.7'
181
183
  required_rubygems_version: !ruby/object:Gem::Requirement
182
184
  requirements:
183
- - - ">="
185
+ - - ">"
184
186
  - !ruby/object:Gem::Version
185
- version: '0'
187
+ version: 1.3.1
186
188
  requirements: []
187
189
  rubygems_version: 3.0.3.1
188
190
  signing_key:
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'active_support/core_ext'
3
-
4
- class CreateFeatures < ActiveRecord::Migration
5
- def self.up
6
- create_table :features do |t|
7
- t.string :symbol, :null => false
8
- t.integer :deployment_percentage, :null => false
9
- #Any additional fields here
10
-
11
- t.timestamps
12
- end
13
- end
14
-
15
- def self.down
16
- drop_table :features
17
- end
18
- end