featurer_web 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5424277e81d034b0ec142d92fc00db64a67fd258
4
+ data.tar.gz: 192a7a6439ab9b4c0fb629cfefb4ebbbd4ab725c
5
+ SHA512:
6
+ metadata.gz: 0af4559e8e8f95d257cb7824519e5bffed367da904f99d9c73207b721541f6b6d0491406a8debba6ad74001ee931de87d81fdfe07894788498e802fb7c04b017
7
+ data.tar.gz: 74d01941ac14ca3be9482e597f7a980dbf77cef0908f45b5de9f9828f3950cd5fb48ddbaa075368d2d36249824be9cc1e7d7ad16fde6986fe1bf54c2e91231db
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Juan González
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'FeaturerWeb'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ load 'rails/tasks/statistics.rake'
17
+
18
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,20 @@
1
+ $(document).ready(function() {
2
+ $("a[data-method=delete]").on('click', function(e) {
3
+ e.preventDefault();
4
+
5
+ if (confirm("Are you sure?") == true) {
6
+ theElement = $(this);
7
+
8
+ $.ajax({
9
+ url: $(this).attr("href"),
10
+ type: "DELETE",
11
+ success: function() {
12
+ row = theElement.closest("tr");
13
+ row.fadeOut(400, function() {
14
+ row.remove();
15
+ });
16
+ }
17
+ });
18
+ }
19
+ });
20
+ });
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+
14
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,16 @@
1
+ module FeaturerWeb
2
+ class ApplicationController < ActionController::Base
3
+ attr_reader :current_user
4
+ helper_method :current_user
5
+
6
+ before_action :authenticate
7
+
8
+ private
9
+
10
+ def authenticate
11
+ return if (@current_user = session[:current_user])
12
+
13
+ redirect_to login_path
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ module FeaturerWeb
2
+ class FeaturesController < ApplicationController
3
+ def index
4
+ render locals: { collection: Feature.all }
5
+ end
6
+
7
+ def new
8
+ render locals: { feature: Feature.new }
9
+ end
10
+
11
+ def edit
12
+ render locals: { feature: Feature.by_name(params[:id]) }
13
+ end
14
+
15
+ def update
16
+ update_and_redirect
17
+ end
18
+
19
+ def create
20
+ update_and_redirect
21
+ end
22
+
23
+ def destroy
24
+ Featurer.delete(params[:id])
25
+
26
+ head 200
27
+ end
28
+
29
+ private
30
+
31
+ def update_and_redirect
32
+ Feature.update(params[:name], params[:matching_values])
33
+
34
+ redirect_to root_path
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ module FeaturerWeb
2
+ class SessionsController < ApplicationController
3
+ skip_before_action :authenticate
4
+
5
+ def login
6
+ FeaturerWeb.admin_users.each do |user_hash|
7
+ next unless credentials_match?(user_hash)
8
+
9
+ session[:current_user] = username
10
+ flash[:info] = 'Welcome home!'
11
+
12
+ redirect_to root_path
13
+
14
+ break
15
+ end
16
+
17
+ return if session[:current_user]
18
+
19
+ flash[:error] = 'Invalid credentials'
20
+
21
+ render :show_login
22
+ end
23
+
24
+ def logout
25
+ session[:current_user] = nil
26
+
27
+ redirect_to root_path
28
+ end
29
+
30
+ private
31
+
32
+ def credentials_match?(user_hash)
33
+ user_hash[:username] == username && user_hash[:password_sha256] == password_sha256
34
+ end
35
+
36
+ def username
37
+ params[:username].to_s
38
+ end
39
+
40
+ def password_sha256
41
+ @password_sha256 ||= Digest::SHA256.digest(params[:password].to_s)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,4 @@
1
+ module FeaturerWeb
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module FeaturerWeb
2
+ module FeaturerHelper
3
+ def formattted_matching_values(matching_values)
4
+ return [] unless matching_values
5
+
6
+ matching_values.map do |matching_value|
7
+ match = Regexp.new(/^\(\?-mix:(.*)\)$/).match(matching_value)
8
+
9
+ if match # Looks like a regular expression
10
+ "/#{match[1]}/"
11
+ else
12
+ matching_value
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ Feature = Struct.new(:name, :matching_values) do
2
+ class << self
3
+ def all
4
+ Featurer.feature_list.map do |feature_details|
5
+ Feature.new(feature_details[:name], feature_details[:matching_values])
6
+ end
7
+ end
8
+
9
+ def by_name(name)
10
+ found_feature_hash = Featurer.feature_list.find do |feature_hash|
11
+ !name.empty? && feature_hash[:name] == name.to_sym
12
+ end
13
+
14
+ raise "Unknown feature: '#{name}'" unless found_feature_hash
15
+
16
+ Feature.new(found_feature_hash[:name], found_feature_hash[:matching_values])
17
+ end
18
+
19
+ def update(name, matching_values_string)
20
+ massaged_values = matching_values_string.split("\r\n").map do |matching_value|
21
+ regexp_match = Regexp.new(%r{^\/(.*)\/$}).match(matching_value)
22
+
23
+ if regexp_match
24
+ Regexp.new(regexp_match[1])
25
+ else
26
+ matching_value
27
+ end
28
+ end
29
+
30
+ Featurer.register(name, massaged_values)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ <tr>
2
+ <td><%= feature.name %></td>
3
+ <td>
4
+ <% formattted_matching_values(feature.matching_values).each do |matching_value| %>
5
+ <div> <%= matching_value %> </div>
6
+ <% end %>
7
+ </td>
8
+ <td>
9
+ <%= link_to "Edit", edit_feature_path(feature.name), class: "btn btn-default" %>
10
+ <%= link_to "Destroy", feature_path(feature.name), class: "btn btn-warning", method: :delete %>
11
+ </tr>
@@ -0,0 +1,28 @@
1
+ <div class="form-group">
2
+ <label for="name">Name for your new feature</label>
3
+ <input class="form-control" name="name" placeholder="Feature name" value="<%= feature.name %>">
4
+ <div class="alert alert-info">Any string can be used as a feature name, even with spaces.</div>
5
+ </div>
6
+
7
+ <div class="form-group">
8
+ <label for="matching_values">Matching values for your feature</label>
9
+ <textarea class="form-control" name="matching_values" placeholder="One matching value per line" rows=10><%= formattted_matching_values(feature.matching_values).join("\r\n") %></textarea>
10
+ <div class="alert alert-info">
11
+ The matching values can be one of the following:
12
+ <li>
13
+ <strong>Regular expressions</strong> Any line that starts and ends with a forward slash (/) is considered a
14
+ regular expression that will be matched to the value passed to Featurer#on?.
15
+ </li>
16
+ <li>
17
+ <strong>Boolean</strong> If a feature has a matching_value equal to 'true' it is enabled globally regardless of
18
+ the value passed to Featurer#on?.
19
+ </li>
20
+ <li>
21
+ <strong>Another string</strong> Any other type of string is matched literally against the value passed to
22
+ Featurer#on?
23
+ </li>
24
+ </div>
25
+
26
+ </div>
27
+
28
+ <input type="submit" class="btn btn-success"></input>
@@ -0,0 +1,3 @@
1
+ <%= form_tag feature_path(feature.name), method: :put do %>
2
+ <%= render partial: 'form', locals: { feature: feature } %>
3
+ <% end %>
@@ -0,0 +1,13 @@
1
+
2
+ <table class="table table-bordered table-striped">
3
+ <thead>
4
+ <th>Feature name</th>
5
+ <th>Matching values</th>
6
+ <th width="150px"/>
7
+ </thead>
8
+ <tbody>
9
+ <%= render partial: 'feature', collection: collection %>
10
+ </tbody>
11
+ </table>
12
+
13
+ <%= link_to "Create new feature", new_feature_path, class: "pull-right btn btn-primary" %>
@@ -0,0 +1,3 @@
1
+ <%= form_tag features_path(feature.name), method: :post do %>
2
+ <%= render partial: 'form', locals: { feature: feature } %>
3
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%= form_tag login_path, method: :POST do %>
2
+ <div class="form-group">
3
+ <label for="username">Username</label>
4
+ <input class="form-control" name="username" placeholder="Username"/>
5
+ </div>
6
+
7
+ <div class="form-group">
8
+ <label for="password">Password</label>
9
+ <input class="form-control" name="password" type="password" placeholder="Password"/>
10
+ </div>
11
+
12
+ <input type="submit" class="pull-right btn btn-success" value="Login"/>
13
+ <% end %>
@@ -0,0 +1,48 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>FeaturerWeb</title>
5
+
6
+ <meta charset="utf-8">
7
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1">
9
+
10
+ <%= stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", media: "all" %>
11
+ <%= stylesheet_link_tag "featurer_web/application", media: "all" %>
12
+
13
+ <%= javascript_include_tag "https://code.jquery.com/jquery-3.1.1.min.js" %>
14
+ <%= javascript_include_tag "featurer_web/application" %>
15
+ </head>
16
+ <body>
17
+
18
+ <nav class="navbar navbar-default">
19
+ <div class="container-fluid">
20
+ <div class="navbar-header">
21
+ <a class="navbar-brand" href="<%= root_path %>">Featurer</a>
22
+ </div>
23
+
24
+ <% if current_user %>
25
+ <!-- Collect the nav links, forms, and other content for toggling -->
26
+ <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
27
+ <ul class="nav navbar-nav navbar-right">
28
+ <li><%= link_to "Logout", logout_path %></li>
29
+ </ul>
30
+ </div><!-- /.navbar-collapse -->
31
+ <% end %>
32
+ </div><!-- /.container-fluid -->
33
+ </nav>
34
+
35
+ <div class="container">
36
+ <% if flash[:error] %>
37
+ <div class="alert alert-warning"><%= flash[:error] %></div>
38
+ <% end %>
39
+ <% if flash[:info] %>
40
+ <div class="alert alert-success"><%= flash[:info] %></div>
41
+ <% end %>
42
+
43
+
44
+ <%= yield %>
45
+ </div>
46
+
47
+ </body>
48
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ FeaturerWeb::Engine.routes.draw do
2
+ root to: 'features#index'
3
+
4
+ get '/login', to: 'sessions#show_login'
5
+ post '/login', to: 'sessions#login'
6
+ get '/logout', to: 'sessions#logout'
7
+
8
+ resources :features
9
+ end
@@ -0,0 +1,27 @@
1
+ require 'featurer_web/engine'
2
+
3
+ module FeaturerWeb
4
+ INVALD_ADMIN_USERS_MSG = <<-MESSAGE.strip_heredoc
5
+ admin_users must be an empty array or an array of hashes with the following format:
6
+ [
7
+ {
8
+ username: "the_login_username",
9
+ password_sha256: Digest::SHA256.digest("password")
10
+ }
11
+ ]
12
+ MESSAGE
13
+
14
+ def self.admin_users=(admin_users)
15
+ all_is_good = admin_users.is_a?(Array) && admin_users.all? do |admin_user|
16
+ admin_user.is_a?(Hash) && admin_user[:username] && admin_user[:password_sha256]
17
+ end
18
+
19
+ raise INVALD_ADMIN_USERS_MSG unless all_is_good
20
+
21
+ @admin_users = admin_users
22
+ end
23
+
24
+ def self.admin_users
25
+ @admin_users || []
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module FeaturerWeb
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace FeaturerWeb
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module FeaturerWeb
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :featurer_web do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: featurer_web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan González
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: featurer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Description of FeaturerWeb.
42
+ email:
43
+ - juan.gonzalez@xing.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - Rakefile
50
+ - app/assets/javascripts/featurer_web/anchors_to_delete.js
51
+ - app/assets/javascripts/featurer_web/application.js
52
+ - app/assets/stylesheets/featurer_web/application.css
53
+ - app/controllers/featurer_web/application_controller.rb
54
+ - app/controllers/featurer_web/features_controller.rb
55
+ - app/controllers/featurer_web/sessions_controller.rb
56
+ - app/helpers/featurer_web/application_helper.rb
57
+ - app/helpers/featurer_web/featurer_helper.rb
58
+ - app/models/feature.rb
59
+ - app/views/featurer_web/features/_feature.html.erb
60
+ - app/views/featurer_web/features/_form.html.erb
61
+ - app/views/featurer_web/features/edit.html.erb
62
+ - app/views/featurer_web/features/index.html.erb
63
+ - app/views/featurer_web/features/new.html.erb
64
+ - app/views/featurer_web/sessions/show_login.html.erb
65
+ - app/views/layouts/featurer_web/application.html.erb
66
+ - config/routes.rb
67
+ - lib/featurer_web.rb
68
+ - lib/featurer_web/engine.rb
69
+ - lib/featurer_web/version.rb
70
+ - lib/tasks/featurer_web_tasks.rake
71
+ homepage: https://github.com/opsidao/featurer_web
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.5.1
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Summary of FeaturerWeb.
95
+ test_files: []