greyscale_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21e71af3947b0cc815cb95463fb059f8f6c0c2c7
4
+ data.tar.gz: f0300f7d0d2a42f81a330457aed57c8b132afd0d
5
+ SHA512:
6
+ metadata.gz: eb71e778325000ea30ef6ba12a0c03d85db5c4f9598efc02052987fc55ed80c04371046ffed39f2c3ed6ca07fa8e9c2a618faa16186f714bba372028c7bb3214
7
+ data.tar.gz: a1abe9d7eddeb54d09d0e7d3788806bd451bc604d851cff03ce8820c27f8cf2ac107ecd7013fb002f548ddf8e2d91585693febcde3fda37c765d7a049c9ac251
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Greg Orlov
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/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # GreyscaleRails
2
+ This is a collection of handy tools to make your life developing against the [Greyscale.io](http://www.greyscale.io) platform easy and delightful.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'greyscale_rails'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ $ gem install greyscale_rails
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ There are a few things this gem provides
24
+
25
+ ### Config
26
+
27
+ [GreyscaleRecord](http://github.com/greyscale-io/greyscale_record) is the default ORM for the Greyscale.io platform and there's some configuration that needs to happen, but it's somewhat verbose. To spare you the pain of reading all those docs, you can configure everything in a single yaml file: `greyscale.yml`
28
+
29
+ Here's what it looks like
30
+
31
+ ```yml
32
+ development:
33
+ driver: yaml
34
+ data_root: db/fixtures
35
+ live_reload: true
36
+
37
+ test:
38
+ driver: yaml
39
+ data_root: test/db/fixtures
40
+
41
+ production:
42
+ driver: greyscale
43
+ data_root: http://api.greyscale.io
44
+ revision_root: http://revisions.greyscale.io
45
+ app_id: <APP_ID>
46
+ app_key: <APP_KEY>
47
+ ```
48
+
49
+ Here's what all the fields are:
50
+
51
+ * `driver`: tells the application to load the proper data fetcher. The options are
52
+ * `yaml`: will load yaml files from your local file system folder, specified by `data_root`
53
+ * `greyscale`: will load data from a remote server that complies to the Greyscale.io API standard
54
+ * `data_root`: the root path of the source from which you want to load your data
55
+ * `revision_root`: the root path of the source from which you load data [previews](#patchable)
56
+ * `app_id`: Your app's Greyscale.io API id
57
+ * `app_key`: Your app's Greyscale.io API key
58
+
59
+ ### Patchable
60
+
61
+ This is a module that's loaded into Application Controller that detects a revision key in `params[:revision]`, and automatically applies the patch for the duration of the call.
62
+
63
+ __NOTE__: it applies it to `GreycaleRecord::Base`'s data store, so if you have more than one store that you are using, this may not work as well as you hope.
64
+
65
+ ## Contributing
66
+ Contribution directions go here.
67
+
68
+ ## License
69
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
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 = 'GreyscaleRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
File without changes
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ module GreyscaleRails
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,39 @@
1
+ module GreyscaleRails
2
+ module Patchable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :apply_patch
7
+ after_action :remove_patch
8
+
9
+ def apply_patch
10
+ revision = params[:revision]
11
+
12
+ if revision.present?
13
+
14
+ definition = patch_driver.load! revision
15
+
16
+ patch = Hana::Patch.new( definition[:patch] )
17
+
18
+ GreyscaleRecord::Base.data_store.apply_patch patch
19
+
20
+ Rails.logger.debug "Aplying patch: #{patch.inspect}"
21
+ end
22
+ rescue => e
23
+ Rails.logger.error "Failed to apply patch #{revision}: #{e}"
24
+
25
+ GreyscaleRecord::Base.data_store.remove_patch
26
+ end
27
+
28
+ def remove_patch
29
+ GreyscaleRecord::Base.data_store.remove_patch
30
+ end
31
+
32
+ private
33
+
34
+ def patch_driver
35
+ GreyscaleRails.patch_driver
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,66 @@
1
+ module GreyscaleRails
2
+ class Railtie < Rails::Railtie
3
+ config.greyscale = ActiveSupport::OrderedOptions.new
4
+
5
+ config.greyscale.config_path = "config/greyscale.yml"
6
+
7
+ initializer "greyscale.configure" do | app |
8
+
9
+ load_config!( app )
10
+
11
+ GreyscaleRecord.logger = Rails.logger
12
+
13
+ data_store = GreyscaleRecord::DataStore::Engine.new config.greyscale.data_driver
14
+
15
+ GreyscaleRecord::Base.data_store = data_store
16
+
17
+ if config.greyscale.patch_driver.present?
18
+ GreyscaleRails.patch_driver = config.greyscale.patch_driver
19
+ end
20
+
21
+ end
22
+
23
+ private
24
+
25
+ def load_config!( app )
26
+
27
+ path = config_path( app )
28
+
29
+ yaml = YAML.load_file( path ).with_indifferent_access[Rails.env.to_s]
30
+
31
+ config.greyscale.data_driver = data_driver yaml
32
+
33
+ if yaml[:revision_root].present?
34
+ config.greyscale.patch_driver = data_driver yaml.merge( data_root: yaml[ :revision_root ] )
35
+ end
36
+
37
+ rescue => e
38
+ raise "Failed to process #{config.greyscale.config_path}. Make sure the file exists and is not malformed. Error: \"#{e}\""
39
+ end
40
+
41
+ def config_path( app )
42
+ File.expand_path(config.greyscale.config_path, app.root)
43
+ end
44
+
45
+ def data_driver( yaml )
46
+ type = yaml[ :driver ].to_sym
47
+ root = yaml[ :data_root ]
48
+
49
+ driver_class = DRIVER_TYPES[type]
50
+ raise "Grreyscale Rails error: #{type} is not a valid driver. Please choose from: #{DRIVER_TYPES.keys.join(", ")}" unless driver_class
51
+
52
+ driver = driver_class.new root
53
+
54
+ if driver.respond_to?( :api_key ) && driver.respond_to?( :api_id )
55
+ driver.api_id = yaml[:api_id]
56
+ driver.api_key = yaml[:api_key]
57
+ end
58
+
59
+ driver
60
+ end
61
+
62
+ DRIVER_TYPES = { yaml: GreyscaleRecord::Drivers::Yaml,
63
+ # greyscale: GreyscaleRails::Drivers::Greyscale
64
+ }
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module GreyscaleRails
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ require "greyscale_rails/engine"
2
+ require 'greyscale_record'
3
+ require 'hana'
4
+ require 'greyscale_rails/railtie'
5
+
6
+ module GreyscaleRails
7
+ autoload :Patchable, "greyscale_rails/patchable"
8
+
9
+ class << self
10
+ attr_accessor :patch_driver
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :greyscale_rails do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greyscale_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Greg Orlov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-31 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: 5.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: greyscale_record
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: hana
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'Rails integration with GReyscale platform tools: setup, environment
70
+ management, plugins'
71
+ email:
72
+ - gaorlov@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - MIT-LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - app/assets/config/greyscale_rails_manifest.js
81
+ - config/routes.rb
82
+ - lib/greyscale_rails.rb
83
+ - lib/greyscale_rails/engine.rb
84
+ - lib/greyscale_rails/patchable.rb
85
+ - lib/greyscale_rails/railtie.rb
86
+ - lib/greyscale_rails/version.rb
87
+ - lib/tasks/greyscale_rails_tasks.rake
88
+ homepage: http://github.com/greyscale-io/greyscale_rails
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A collection of tools to make GReywscale development easier
112
+ test_files: []