apple_core 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ec1ae1430dfe1ab24c69a49f974b2b813caedb51494adfb673c053eebf9d806
4
- data.tar.gz: a515cc1970daccb49f2f34e82a466111ec15d6d999351bf6d0a3b6a74cb244d3
3
+ metadata.gz: b031ca8051ff8d6e391f4e9b4015bc9f80517202e6a597766f70c9a0756ade70
4
+ data.tar.gz: 63dcd8c0c2a70233b70729bcc07c37044cafad4573fbd0fe0e3bb395ec88ff94
5
5
  SHA512:
6
- metadata.gz: 444979ac9b0def2a0c7a9c6d3e6267b42f64e96f4ed7afc525deebbf5fa6a1083e7497c3bd83e6aea9113aa02169a9059238a8fb6c4ecacf5e239f97cf3a04c5
7
- data.tar.gz: d61d61ada162b541b1878e6ed0baaa4e824ccb74bcc8479f1b4ee983a407344d915570b1d761c0a55632d894cc69bf5072bcc421d4ceaa6f5bf44e30e5f29893
6
+ metadata.gz: 0f17c0ea2da214f24cbd48679415ff1d498a1e9e4d0f2964a365671f2a861119ed6ab149b332cae34cb628dd36b3645cfbc3cc9012b79aef8c55694261ab238b
7
+ data.tar.gz: f636bcd1eb98ece8ff046d8ceaeb7d03104b1faa63b3a3eec9f73770ed93ece0d56c0b762770d548234d1891fe3622333f6d91d8bd373770a6f2bb458713a6da
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2018 Grand Design
1
+ Copyright (c) 2010-2016 The Kompanee, Ltd
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/lib/apple_core.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'apple_core/version'
4
4
  require 'apple_core/active_record/base'
5
5
  require 'apple_core/active_model/validations/inclusion_validator'
6
+ require 'apple_core/railtie' if defined?(::Rails)
6
7
 
7
8
  module AppleCore
8
9
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'apple_core/refinements/query_string'
5
+
6
+ module AppleCore
7
+ module Helpers
8
+ module WebClientUrl
9
+ using ::AppleCore::Refinements::QueryString
10
+
11
+ def web_client_url(**options)
12
+ route_name = options.delete(:name)
13
+ default_options = Chamber.env.web_client.slice('host', 'port', 'protocol')
14
+ route_path = Chamber.env.web_client.urls[route_name]
15
+
16
+ options.dup.each do |key, value|
17
+ key_pattern = %r{/:#{key}(?=(/|\z))}
18
+
19
+ next unless route_path.match?(key_pattern)
20
+
21
+ route_path.gsub!(key_pattern, "/#{value}")
22
+ options.delete(key)
23
+ end
24
+
25
+ options = default_options.merge(options)
26
+ anchor = options.delete('anchor')
27
+ arguments = [
28
+ options.delete('protocol'),
29
+ options.delete('authentication'),
30
+ options.delete('host'),
31
+ options.delete('port') || 443,
32
+ nil,
33
+ route_path,
34
+ nil,
35
+ options.to_query,
36
+ anchor,
37
+ ]
38
+
39
+ URI::HTTPS.new(*arguments).to_s
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'apple_core/action_view/helpers/web_client_url'
4
+
5
+ module AppleCore
6
+ class Railtie < Rails::Railtie
7
+ initializer 'web_client_url.helper' do |_app|
8
+ ActionView::Base.public_send(:include, AppleCore::Helpers::WebClientUrl)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AppleCore
4
+ module Refinements
5
+ module QueryString
6
+ refine ::Array do
7
+ unless method_defined?(:to_param)
8
+ def to_param
9
+ map(&:to_param).join('/')
10
+ end
11
+
12
+ def to_query(key)
13
+ prefix = "#{key}[]"
14
+
15
+ return nil.to_query(prefix) if empty?
16
+
17
+ map { |value| value.to_query(prefix) }
18
+ .join('&')
19
+ end
20
+ end
21
+ end
22
+
23
+ refine ::FalseClass do
24
+ def to_param
25
+ self
26
+ end
27
+ end
28
+
29
+ refine ::Hash do
30
+ unless method_defined?(:to_param)
31
+ def to_param(namespace = nil)
32
+ map { |key, value|
33
+ unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
34
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
35
+ end
36
+ }
37
+ .compact
38
+ .sort!
39
+ .join('&')
40
+ end
41
+
42
+ alias_method :to_param, :to_query
43
+ end
44
+ end
45
+
46
+ refine ::NilClass do
47
+ unless method_defined?(:to_param)
48
+ def to_param
49
+ self
50
+ end
51
+ end
52
+ end
53
+
54
+ refine ::Object do
55
+ unless method_defined?(:to_param)
56
+ def to_param
57
+ to_s
58
+ end
59
+
60
+ def to_query(key)
61
+ "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
62
+ end
63
+ end
64
+ end
65
+
66
+ refine ::TrueClass do
67
+ def to_param
68
+ self
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ module ActiveSupport
76
+ class HashWithIndifferentAccess < Hash
77
+ using ::AppleCore::Refinements::QueryString
78
+
79
+ unless method_defined?(:to_param)
80
+ def to_param
81
+ dup.tap do |hash|
82
+ each_pair do |key, value|
83
+ if key.frozen? && key.is_a?(::String)
84
+ hash[key] = value.to_param
85
+ else
86
+ hash.delete(key)
87
+ hash[key.to_param] = value.to_param
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AppleCore
4
- VERSION = '1.3.1'
4
+ VERSION = '1.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -31,7 +31,7 @@ cert_chain:
31
31
  Y2GAoHKstmfIVhc4XHOPpmTd2o/C29O9oaRgjrkfQEhF/KvJ/PhoV5hvokzsCyI5
32
32
  iUeXPfvrGD/itYIBCgk+fnzyQQ4QtE5hTQaWQ3o2
33
33
  -----END CERTIFICATE-----
34
- date: 2018-05-26 00:00:00.000000000 Z
34
+ date: 2018-07-10 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activemodel
@@ -112,13 +112,16 @@ files:
112
112
  - README.md
113
113
  - lib/apple_core.rb
114
114
  - lib/apple_core/action_controller/resource_naming.rb
115
+ - lib/apple_core/action_view/helpers/web_client_url.rb
115
116
  - lib/apple_core/active_model/errors.rb
116
117
  - lib/apple_core/active_model/validations/inclusion_validator.rb
117
118
  - lib/apple_core/active_record/base.rb
119
+ - lib/apple_core/railtie.rb
118
120
  - lib/apple_core/refinements/array.rb
119
121
  - lib/apple_core/refinements/deep_dup.rb
120
122
  - lib/apple_core/refinements/hash.rb
121
123
  - lib/apple_core/refinements/integer.rb
124
+ - lib/apple_core/refinements/query_string.rb
122
125
  - lib/apple_core/refinements/string.rb
123
126
  - lib/apple_core/transforms/hash.rb
124
127
  - lib/apple_core/version.rb
@@ -143,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
146
  version: '0'
144
147
  requirements: []
145
148
  rubyforge_project:
146
- rubygems_version: 2.7.6
149
+ rubygems_version: 2.7.7
147
150
  signing_key:
148
151
  specification_version: 4
149
152
  summary: Non-Active Support
metadata.gz.sig CHANGED
Binary file