Skip to content

Commit

Permalink
Remove active support dependency for ood-portal-generator (#1572)
Browse files Browse the repository at this point in the history
* Remove active support dependency for ood-portal-generator
Fixes #1347

* Add comment about RAILS-LICENSE
  • Loading branch information
treydock authored Nov 5, 2021
1 parent 5da1b3a commit 40f9ab2
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 16 deletions.
1 change: 0 additions & 1 deletion ood-portal-generator/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'activesupport', '5.2.4.3'
gem 'dotenv', '~> 2.1'
gem "bcrypt"

Expand Down
13 changes: 0 additions & 13 deletions ood-portal-generator/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (5.2.4.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
bcrypt (3.1.16)
climate_control (0.2.0)
concurrent-ruby (1.1.6)
diff-lcs (1.3)
dotenv (2.7.5)
i18n (1.8.3)
concurrent-ruby (~> 1.0)
minitest (5.14.1)
rake (13.0.0)
rspec (3.9.0)
rspec-core (~> 3.9.0)
Expand All @@ -28,15 +19,11 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
activesupport (= 5.2.4.3)
bcrypt
climate_control
dotenv (~> 2.1)
Expand Down
20 changes: 20 additions & 0 deletions ood-portal-generator/RAILS-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2005-2021 David Heinemeier Hansson

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 3 additions & 2 deletions ood-portal-generator/lib/ood_portal_generator/dex.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'active_support'
require 'active_support/core_ext'
require 'ood_portal_generator/hash_extensions'
require 'securerandom'
require 'fileutils'
require 'bcrypt'

using OodPortalGenerator::HashExtensions

module OodPortalGenerator
# A view class that renders a Dex configuration
class Dex
Expand Down
81 changes: 81 additions & 0 deletions ood-portal-generator/lib/ood_portal_generator/hash_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module OodPortalGenerator
# Some elements have been taken from Rails (https://github.com/rails/rails)
# and it's LICENSE has been added as RAILS-LICENSE in the root directory of this project.
module HashExtensions
refine Hash do
# Returns a hash that includes everything except given keys.
# hash = { a: true, b: false, c: nil }
# hash.except(:c) # => { a: true, b: false }
# hash.except(:a, :b) # => { c: nil }
# hash # => { a: true, b: false, c: nil }
#
# This is useful for limiting a set of parameters to everything but a few known toggles:
# @person.update(params[:person].except(:admin))
def except(*keys)
slice(*self.keys - keys)
end unless method_defined?(:except)

# Returns a new hash with all keys converted to symbols, as long as
# they respond to +to_sym+. This includes the keys from the root hash
# and from all nested hashes and arrays.
#
# hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
#
# hash.deep_symbolize_keys
# # => {:person=>{:name=>"Rob", :age=>"28"}}
def deep_symbolize_keys
deep_transform_keys { |key| key.to_sym rescue key }
end

# Returns a new hash with all keys converted by the block operation.
# This includes the keys from the root hash and from all
# nested hashes and arrays.
#
# hash = { person: { name: 'Rob', age: '28' } }
#
# hash.deep_transform_keys{ |key| key.to_s.upcase }
# # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
def deep_transform_keys(&block)
_deep_transform_keys_in_object(self, &block)
end

# Destructively converts all keys by using the block operation.
# This includes the keys from the root hash and from all
# nested hashes and arrays.
def deep_transform_keys!(&block)
_deep_transform_keys_in_object!(self, &block)
end

private

# Support methods for deep transforming nested hashes and arrays.
def _deep_transform_keys_in_object(object, &block)
case object
when Hash
object.each_with_object(self.class.new) do |(key, value), result|
result[yield(key)] = _deep_transform_keys_in_object(value, &block)
end
when Array
object.map { |e| _deep_transform_keys_in_object(e, &block) }
else
object
end
end

def _deep_transform_keys_in_object!(object, &block)
case object
when Hash
object.keys.each do |key|
value = object.delete(key)
object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
end
object
when Array
object.map! { |e| _deep_transform_keys_in_object!(e, &block) }
else
object
end
end
end
end
end

0 comments on commit 40f9ab2

Please sign in to comment.