deployable-patch 0.3.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: 88bd324ee45730f3e43cf66023b8b6d15bc63b30
4
+ data.tar.gz: 4706ab7c9faf64e7927ee448ebd4e394a11d1a29
5
+ SHA512:
6
+ metadata.gz: 582140540edc7fd63a99ce01407ddb17eea81f97cac2067a8c90be9e0a2092b7b61a2c2e6e90912fac8685404bfac04a16130c356069c023345373c2535fced3
7
+ data.tar.gz: ab98ea15820ccfca7f4ea81be654cc07b65449dea107135dba3e46bf0b76034a9bf9865d310130692c62e905fd13551e2c13b64d9743b0a53c88eb209eae5560
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title "deployable-patch Documentation" --protected
data/ChangeLog.md ADDED
@@ -0,0 +1,9 @@
1
+ ### 0.1.0 / 2014-10-19
2
+
3
+ * 0.2.0
4
+ Add hash any_keys all_keys + specs
5
+ Add specs for not_nil
6
+ Add ancestor classes and class helper methods
7
+
8
+ * Initial release:
9
+ 0.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deployable-patch.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 deployable
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Deployable::Patch
2
+
3
+ The place to store all the monkey patches
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'deployable-patch'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself:
18
+
19
+ $ gem install deployable-patch
20
+
21
+ ## Usage
22
+
23
+ Monkeypatches should be seperated into directories/files based on their classes initially
24
+ Then grouped into include files elsewhere for ease of use
25
+ The more granular the seperation the more control you have over their use
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/deployable/deployable-patch/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deployable/patch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "deployable-patch"
8
+ spec.version = Deployable::Patch::VERSION
9
+ spec.authors = ["Deployable - Matt Hoyle"]
10
+ spec.email = ["code@deployable.co"]
11
+ spec.summary = %q{Central repo for monkey patches to other ruby stuff}
12
+ spec.description = %q{A central repo to store common monkey patches}
13
+ spec.homepage = "https://code.deployable.co/ruby/deployable-patch"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,2 @@
1
+ require "deployable/magic/version"
2
+ require "deployalbe/patch/array/no_dot_entries"
@@ -0,0 +1,46 @@
1
+ # Monkeypatch in some methods to remove class setup boilerplate
2
+ class Module
3
+
4
+ # Provide accessors with a hash of defaults, and a default alias
5
+ def attr_accessor_default options = {}
6
+ options.each do |key, val|
7
+ attr_accessor key unless instance_variable_defined? "@#{key}"
8
+ instance_variable_set "@#{key}", val
9
+ end
10
+ end
11
+ alias_method :attr_default, :attr_accessor_default
12
+
13
+ # Provide readers with a hash of defaults
14
+ def attr_reader_default options = {}
15
+ options.each do |key, val|
16
+ attr_reader key unless instance_variable_defined? "@#{key}"
17
+ instance_variable_set "@#{key}", val
18
+ end
19
+ end
20
+
21
+ # Provide writers with a hash of defaults
22
+ def attr_writer_default options = {}
23
+ options.each do |key, val|
24
+ attr_writer key unless instance_variable_defined? "@#{key}"
25
+ instance_variable_set "@#{key}", val
26
+ end
27
+ end
28
+
29
+ def attr_initialize method = nil
30
+ # Create an `initialize` settings all the defaults
31
+ # Allow another constructor to run `attr_initialize :some_method`
32
+ # Would like to make this invisiable to initialize but
33
+ # haven't come up with a cood way yet.
34
+
35
+ raise 'initialize already defined 'if method_defined? :initialize
36
+
37
+ define_method :initialize do |options|
38
+ options_left = options.delete_if do |key, val|
39
+ instance_variable_defined? "@#{key}" or instance_variable_set "@#{key}", val
40
+ end
41
+ send method, options_left
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,14 @@
1
+
2
+ class Class
3
+ # Remove the modules from the classes
4
+ def ancestor_classes
5
+ ancestors - included_modules
6
+ end
7
+
8
+ # Parent class, first ancestor
9
+ def ancestor_class
10
+ list = ancestor_classes
11
+ self if list.length == 0
12
+ ancestor_classes[1]
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ require "deployable/magic/version"
2
+
3
+ module Dir
4
+ DOT_ENTRIES = [ '.', '..' ]
5
+
6
+ def self.entries_no_dots dir
7
+ self.entries( dir ).remove_dot_entries
8
+ end
9
+
10
+ def self.remove_dots arg
11
+ arg.delete_if{|e|
12
+ DOT_ENTRIES.any?{ |d| e == d }
13
+ }
14
+ end
15
+ end
16
+
17
+ module Array
18
+ def remove_dot_entries
19
+ self - Dir::DOT_ENTRIES
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ require "deployable/magic/version"
2
+ require "deployalbe/patch/dir/entries_no_dots"
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def ensure_array; [self] end
3
+ end
4
+ class Array
5
+ def ensure_array; to_a end
6
+ end
7
+ class NilClass
8
+ def ensure_array; to_a end
9
+ end
@@ -0,0 +1,12 @@
1
+
2
+ # Make testing for multiple keys easiers on a hash
3
+
4
+ class Hash
5
+ def has_all_keys? *keys
6
+ keys.all? do |key| has_key?(key) end
7
+ end
8
+
9
+ def has_any_keys? *keys
10
+ keys.any? do |key| has_key?(key) end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ # Easier instance variable getters that
2
+ # do the variable naming/symbol for you
3
+ class Object
4
+
5
+ def __ivg name
6
+ instance_variable_get :"@#{name}"
7
+ end
8
+
9
+ def __ivs name, value
10
+ instance_variable_set :"@#{name}", value
11
+ end
12
+
13
+ def __class_ivg name
14
+ self.class.__ivg name
15
+ end
16
+
17
+ def __class_ivs name, value
18
+ self.class.__ivs name, value
19
+ end
20
+
21
+ end
22
+
23
+
24
+ # Easier class variable access
25
+ # do the variable naming/symbol for you
26
+ class Module
27
+
28
+ def __cvg name
29
+ class_variable_get :"@@#{name}"
30
+ end
31
+
32
+ def __cvs name, value
33
+ class_variable_set :"@@#{name}", value
34
+ end
35
+
36
+ end
@@ -0,0 +1,19 @@
1
+ # Some methods to make meta definitions easier
2
+
3
+ class Object
4
+
5
+ # The hidden singleton lurks behind everyone
6
+ def metaclass; class << self; self; end; end
7
+ def meta_eval &blk; metaclass.instance_eval( &blk ); end
8
+
9
+ # Adds methods to a metaclass
10
+ def meta_def( name, &blk )
11
+ meta_eval { define_method name, &blk }
12
+ end
13
+
14
+ # Defines an instance method within a class
15
+ def class_def( name, &blk )
16
+ class_eval { define_method name, &blk }
17
+ end
18
+
19
+ end
@@ -0,0 +1,6 @@
1
+ # This can make not nil checks look nicer depending on the objects
2
+ class Object
3
+ def not_nil?
4
+ !nil?
5
+ end
6
+ end
@@ -0,0 +1,2 @@
1
+ # Null class so nil can be used as a value
2
+ class Null; end
@@ -0,0 +1,28 @@
1
+ class String
2
+
3
+ def quote char
4
+ # improve this to escape chars, if they aren't already escaped
5
+ raise if match char
6
+ "#{char}#{self}#{char}"
7
+ end
8
+
9
+ def quote_escape char
10
+ #if m = match char
11
+ # m.
12
+ #end
13
+ "#{char}#{self}#{char}"
14
+ end
15
+
16
+ def single_quote
17
+ quote "'"
18
+ end
19
+
20
+ def double_quote
21
+ quote '"'
22
+ end
23
+
24
+ def needs_quoting? check = /\s/
25
+ !!match(check)
26
+ end
27
+
28
+ end
@@ -0,0 +1,6 @@
1
+ module Deployable
2
+ module Patch
3
+ # deployable-patch version
4
+ VERSION = "0.3.0"
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require 'deployable/patch/version'
2
+
3
+ require 'deployable/patch/attr_defaults'
4
+ require 'deployable/patch/ensure_array'
5
+ require 'deployable/patch/instance_class_variables'
6
+ require 'deployable/patch/meta'
7
+ require 'deployable/patch/class_ancestor'
8
+ require 'deployable/patch/hash_keys'
9
+ require 'deployable/patch/not_nil'
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'deployable/patch/hash_keys'
3
+
4
+ describe 'Hash keys any/all' do
5
+ before :each do
6
+ @hash = { :one => 1, :two => 2 }
7
+ end
8
+
9
+ it "hash any key true" do
10
+ expect( @hash.has_any_keys? :one ).to be true
11
+ end
12
+
13
+ it "hash any key multiple true" do
14
+ expect( @hash.has_any_keys? :one, :two ).to be true
15
+ end
16
+
17
+ it "hash any key false" do
18
+ expect( @hash.has_any_keys? :three ).to be false
19
+ end
20
+
21
+ it "hash all keys" do
22
+ expect( @hash.has_all_keys? :one, :two ).to be true
23
+ end
24
+
25
+ it "hash all keys false" do
26
+ expect( @hash.has_all_keys? :three ).to be false
27
+ end
28
+
29
+ it "hash all keys false" do
30
+ expect( @hash.has_all_keys? :one, :three ).to be false
31
+ end
32
+
33
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'deployable/patch/not_nil'
3
+
4
+
5
+ describe 'Object not_nil ' do
6
+
7
+ it "string" do
8
+ expect( "test".not_nil? ).to be true
9
+ end
10
+
11
+ it "nil" do
12
+ expect( nil.not_nil? ).to be false
13
+ end
14
+
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'deployable/patch'
3
+
4
+ describe Deployable::Patch do
5
+ it "should have a VERSION constant" do
6
+ expect( subject.const_get('VERSION') ).to_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ gem 'rspec', '~> 3.1'
2
+ require 'rspec'
3
+ require 'deployable/patch/version'
4
+
5
+
6
+ include Deployable::Patch
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deployable-patch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Deployable - Matt Hoyle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A central repo to store common monkey patches
42
+ email:
43
+ - code@deployable.co
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".document"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".yardopts"
52
+ - ChangeLog.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - deployable-patch.gemspec
58
+ - lib/deployable/patch.rb
59
+ - lib/deployable/patch/array.rb
60
+ - lib/deployable/patch/attr_defaults.rb
61
+ - lib/deployable/patch/class_ancestor.rb
62
+ - lib/deployable/patch/dir.rb
63
+ - lib/deployable/patch/dir/entries_no_dots.rb
64
+ - lib/deployable/patch/ensure_array.rb
65
+ - lib/deployable/patch/hash_keys.rb
66
+ - lib/deployable/patch/instance_class_variables.rb
67
+ - lib/deployable/patch/meta.rb
68
+ - lib/deployable/patch/not_nil.rb
69
+ - lib/deployable/patch/null.rb
70
+ - lib/deployable/patch/string/quoting.rb
71
+ - lib/deployable/patch/version.rb
72
+ - spec/hash_keys_spec.rb
73
+ - spec/not_nil_spec.rb
74
+ - spec/patch_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://code.deployable.co/ruby/deployable-patch
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Central repo for monkey patches to other ruby stuff
100
+ test_files:
101
+ - spec/hash_keys_spec.rb
102
+ - spec/not_nil_spec.rb
103
+ - spec/patch_spec.rb
104
+ - spec/spec_helper.rb