Skip to content

Commit

Permalink
Merge pull request #22 from leifg/remove-activesupport
Browse files Browse the repository at this point in the history
Completely get rid of activesupport
  • Loading branch information
leifg authored Mar 31, 2017
2 parents 5b9b145 + 81d7009 commit 4f6942d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/morfo.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "active_support/core_ext/hash"
require 'deep_merge/rails_compat'
require "morfo/version"
require "morfo/tools"
require "morfo/actions"
Expand All @@ -20,7 +20,7 @@ def self.morf input, options = {}
def self.morf_single input, options = {}
output = {}
mapping_actions.each do |field_path, action|
output.deep_merge!(store_value(action.execute(input), field_path, options))
output.deeper_merge!(store_value(action.execute(input), field_path, options))
end
output
end
Expand Down
2 changes: 1 addition & 1 deletion lib/morfo/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(definitions)
def build
# WTF??? `definitions` is not accessible inside class
# so this javascript technique is necesseray
tmp_definitions = definitions.map { |h| h.symbolize_keys }
tmp_definitions = definitions.map { |h| Morfo::Tools::ExtendedHash.symbolize_keys(h) }
Class.new(Morfo::Base) do
tmp_definitions.each do |definition|
f = field(*definition[:field])
Expand Down
21 changes: 19 additions & 2 deletions lib/morfo/tools.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
module Morfo
module Tools
module ExtendedHash
extend self

def symbolize_keys(hash)
transform_keys(hash) { |key| key.to_sym rescue key }
end

def transform_keys(hash)
return hash.enum_for(:transform_keys) { size } unless block_given?
result = {}
hash.each_key do |key|
result[yield(key)] = hash[key]
end
result
end
end

class FlattenHashKeys
attr_reader :input_hash

Expand All @@ -10,10 +27,10 @@ def initialize(input_hash)
def flatten
input_hash.inject({}) do |result_hash, (key, value)|
inner_hash = false
if value.is_a?(Hash)
if value.is_a?(::Hash)
inner_hash = true
value.each do |inner_key, inner_value|
if inner_value.is_a?(Hash)
if inner_value.is_a?(::Hash)
inner_hash = true
end
result_hash.merge!("#{key}.#{inner_key}".to_sym => inner_value)
Expand Down
2 changes: 1 addition & 1 deletion morfo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.0.0'

spec.add_runtime_dependency "json"
spec.add_runtime_dependency "activesupport", "< 5.0"
spec.add_runtime_dependency "deep_merge"
spec.add_runtime_dependency "rubysl" if RUBY_ENGINE == "rbx"

spec.add_development_dependency "rake"
Expand Down

0 comments on commit 4f6942d

Please sign in to comment.