simple_hash 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: 521d45ff55c32320ac029b38673e1512a97500ca
4
+ data.tar.gz: 726f1571457a46a9965632f25a9ac27204db6afe
5
+ SHA512:
6
+ metadata.gz: b1aa816b9a9da25d411b5b4e40b0635ef4818c20a30b84c41196227b7e51bea234fe67d9301d3dc014d8237980a2f32ca64215f184914941eb9a321652d3825a
7
+ data.tar.gz: 728785f9443f1651de96f5dad793a23068674b5ceb85f7c31a49fb8c61ead6939a0fa055533d163b3962582e959e6304ad774d64378a09eabc4626813d7ec9ac
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Documentation cache and generated files:
14
+ /.yardoc/
15
+ /_yardoc/
16
+ /doc/
17
+ /rdoc/
18
+
19
+ ## Environment normalization:
20
+ /.bundle/
21
+ /vendor/bundle
22
+ /lib/bundler/man/
23
+
24
+ # for a library or gem, you might want to ignore these files since the code is
25
+ # intended to run in multiple environments; otherwise, check them in:
26
+ # Gemfile.lock
27
+ # .ruby-version
28
+ # .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - "2.3"
5
+ - "2.2"
6
+ - "2.1"
7
+ - "rbx-2"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_hash (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ codeclimate-test-reporter (0.5.0)
10
+ simplecov (>= 0.7.1, < 1.0.0)
11
+ coderay (1.1.1)
12
+ coveralls (0.8.13)
13
+ json (~> 1.8)
14
+ simplecov (~> 0.11.0)
15
+ term-ansicolor (~> 1.3)
16
+ thor (~> 0.19.1)
17
+ tins (~> 1.6.0)
18
+ diff-lcs (1.2.5)
19
+ docile (1.1.5)
20
+ json (1.8.3)
21
+ method_source (0.8.2)
22
+ pry (0.10.3)
23
+ coderay (~> 1.1.0)
24
+ method_source (~> 0.8.1)
25
+ slop (~> 3.4)
26
+ rake (11.1.2)
27
+ rspec (3.4.0)
28
+ rspec-core (~> 3.4.0)
29
+ rspec-expectations (~> 3.4.0)
30
+ rspec-mocks (~> 3.4.0)
31
+ rspec-core (3.4.4)
32
+ rspec-support (~> 3.4.0)
33
+ rspec-expectations (3.4.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.4.0)
36
+ rspec-mocks (3.4.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.4.0)
39
+ rspec-support (3.4.1)
40
+ simplecov (0.11.2)
41
+ docile (~> 1.1.0)
42
+ json (~> 1.8)
43
+ simplecov-html (~> 0.10.0)
44
+ simplecov-html (0.10.0)
45
+ slop (3.6.0)
46
+ term-ansicolor (1.3.2)
47
+ tins (~> 1.0)
48
+ thor (0.19.1)
49
+ tins (1.6.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ codeclimate-test-reporter (~> 0.4)
56
+ coveralls
57
+ pry (~> 0.10)
58
+ rake (~> 11.1)
59
+ rspec (~> 3.4)
60
+ simple_hash!
61
+
62
+ BUNDLED WITH
63
+ 1.11.2
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016 Karloku Sang
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
+ DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ ## SimpleHash
2
+
3
+ Brings ES6 object initializer sugar to Ruby.
4
+
5
+ ## Usage
6
+
7
+ suppose you have these variables
8
+ ```Ruby
9
+ year = 2016
10
+ month = 3
11
+ day = 30
12
+ hour = 18
13
+ minute = 50
14
+ second = 23
15
+ ```
16
+
17
+ Build a hash requires much redundancy:
18
+ ```Ruby
19
+ {year: year, month: month, day: day, hour: hour, minute: minute, second: second}
20
+ ```
21
+
22
+ With SimpleHash, build like this:
23
+ ```Ruby
24
+ SimpleHash{[:year, :month, :day, :hour, :minute, :second]}
25
+ ```
26
+
27
+ Further, you can load the short cut by calling ```SimpleHash.short_cut!```, this method would add a method ```#h``` to Object.
28
+ Then you can build like this:
29
+ ```Ruby
30
+ h{[:year, :month, :day, :hour, :minute, :second]}
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ Install the gem
36
+ ```sh
37
+ gem install simple_hash
38
+ ```
39
+ or require it in your Gemfile
40
+ ```Ruby
41
+ gem 'simple_hash'
42
+ ```
43
+
44
+ ## Development
45
+
46
+ Test:
47
+ ```
48
+ bundle exec rspec
49
+ ```
50
+
51
+ ## License
52
+
53
+ This gem is released under the [MIT License](MIT-LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/setup'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module SimpleHash
3
+ VERSION = '0.0.1'
4
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ module SimpleHash
3
+ module_function
4
+
5
+ # Make a hash from an array of symbols wrapped in a block
6
+ # Suppose you have variables
7
+ #
8
+ # year = 2016
9
+ # month = 3
10
+ # day = 30
11
+ # hour = 18
12
+ # minute = 50
13
+ # second = 23
14
+ #
15
+ # Bulid the hash like this
16
+ #
17
+ # SimpleHash.h{[:year, :month, :day, :hour, :minute, :second]}
18
+ #
19
+ # This method gets the keys by yieling the block passed in
20
+ # and look up the variable values thourgh the block's binding
21
+ # @param [&list_block] block with an array of keys, e.g. {[:key1, :key2, ...]}
22
+ # @return [Hash] hash with passed-in keys, e.g. {key1: 'key1_value', key2: 'key2_value', ...}
23
+ def h(&list_block)
24
+ variables = yield.map(&:to_s)
25
+ Hash[
26
+ variables.map do |variable|
27
+ [variable.to_sym, list_block.binding.local_variable_get(variable)]
28
+ end
29
+ ]
30
+ end
31
+
32
+ # Adds #h method to Object, delegating to SimpleHash::h
33
+ def self.short_cut!
34
+ Object.include(SimpleHash)
35
+ end
36
+ end
37
+
38
+ # Delegates to SimpleHash::h
39
+ # @param [&list_block] block with an array of keys, e.g. {[:key1, :key2, ...]}
40
+ # @return [Hash] hash with passed-in keys, e.g. {key1: 'key1_value', key2: 'key2_value', ...}
41
+ def SimpleHash(&list_block)
42
+ SimpleHash.h(&list_block)
43
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+
4
+ require 'simple_hash/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'simple_hash'
8
+ gem.version = SimpleHash::VERSION
9
+ gem.date = Date.today.to_s
10
+ gem.summary = 'Ruby short cut for making hash'
11
+ gem.description = 'Ruby short cut for making hash'
12
+ gem.homepage = 'https://github.com/karloku/simple_hash'
13
+ gem.authors = ['Karloku Sang']
14
+ gem.email = ['karloku@gmail.com']
15
+ gem.license = 'MIT'
16
+ gem.required_ruby_version = '>= 2.1.0' # bc optional keyword args
17
+
18
+ gem.require_paths = ['lib']
19
+ gem.files = Dir['{lib}/**/*', 'MIT-LICENSE', 'README.md']
20
+ gem.files = `git ls-files`.split("\n")
21
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
22
+
23
+ gem.add_development_dependency 'coveralls'
24
+ gem.add_development_dependency 'codeclimate-test-reporter', '~>0.4'
25
+ gem.add_development_dependency 'pry', '~> 0.10'
26
+ gem.add_development_dependency 'rspec', '~> 3.4'
27
+ gem.add_development_dependency 'rake', '~> 11.1'
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ describe SimpleHash do
3
+ describe '#h' do
4
+ it 'builds hash' do
5
+ a = 1
6
+ b = 2
7
+ expect(SimpleHash {[:a, :b]}).to eq(a: a, b: b)
8
+ end
9
+ end
10
+
11
+ describe '::short_cut!' do
12
+ it 'adds #h to Object' do
13
+ SimpleHash.short_cut!
14
+ a = 1
15
+ b = 2
16
+ expect(h{[:a, :b]}).to eq(a: a, b: b)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
5
+ # this file to always be loaded, without a need to explicitly require it in any
6
+ # files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need
14
+ # it.
15
+ #
16
+ # The `.rspec` file also contains a few flags that are not defaults but that
17
+ # users commonly want.
18
+ #
19
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
+ require 'bundler/setup'
21
+ Bundler.setup
22
+
23
+ require 'pry'
24
+ require 'coveralls'
25
+ Coveralls.wear!
26
+
27
+ require 'simple_hash'
28
+
29
+ RSpec.configure do |config|
30
+ # rspec-expectations config goes here. You can use an alternate
31
+ # assertion/expectation library such as wrong or the stdlib/minitest
32
+ # assertions if you prefer.
33
+ config.expect_with :rspec do |expectations|
34
+ # This option will default to `true` in RSpec 4. It makes the `description`
35
+ # and `failure_message` of custom matchers include text for helper methods
36
+ # defined using `chain`, e.g.:
37
+ # be_bigger_than(2).and_smaller_than(4).description
38
+ # # => "be bigger than 2 and smaller than 4"
39
+ # ...rather than:
40
+ # # => "be bigger than 2"
41
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
42
+ end
43
+
44
+ # rspec-mocks config goes here. You can use an alternate test double
45
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
46
+ config.mock_with :rspec do |mocks|
47
+ # Prevents you from mocking or stubbing a method that does not exist on
48
+ # a real object. This is generally recommended, and will default to
49
+ # `true` in RSpec 4.
50
+ mocks.verify_partial_doubles = true
51
+ end
52
+
53
+ # The settings below are suggested to provide a good initial experience
54
+ # with RSpec, but feel free to customize to your heart's content.
55
+ # # These two settings work together to allow you to limit a spec run
56
+ # # to individual examples or groups you care about by tagging them with
57
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
58
+ # # get run.
59
+ # config.filter_run :focus
60
+ # config.run_all_when_everything_filtered = true
61
+ #
62
+ # # Allows RSpec to persist some state between runs in order to support
63
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
64
+ # # you configure your source control system to ignore this file.
65
+ # config.example_status_persistence_file_path = "spec/examples.txt"
66
+ #
67
+ # # Limits the available syntax to the non-monkey patched syntax that is
68
+ # # recommended. For more details, see:
69
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
70
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
72
+ # config.disable_monkey_patching!
73
+ #
74
+ # # This setting enables warnings. It's recommended, but in some cases may
75
+ # # be too noisy due to issues in dependencies.
76
+ # config.warnings = true
77
+ #
78
+ # # Many RSpec users commonly either run the entire suite or an individual
79
+ # # file, and it's useful to allow more verbose output when running an
80
+ # # individual spec file.
81
+ # if config.files_to_run.one?
82
+ # # Use the documentation formatter for detailed output,
83
+ # # unless a formatter has already been configured
84
+ # # (e.g. via a command-line flag).
85
+ # config.default_formatter = 'doc'
86
+ # end
87
+ #
88
+ # # Print the 10 slowest examples and example groups at the
89
+ # # end of the spec run, to help surface which specs are running
90
+ # # particularly slow.
91
+ # config.profile_examples = 10
92
+ #
93
+ # # Run specs in random order to surface order dependencies. If you find an
94
+ # # order dependency and want to debug it, you can fix the order by providing
95
+ # # the seed, which is printed after each run.
96
+ # # --seed 1234
97
+ # config.order = :random
98
+ #
99
+ # # Seed global randomization in this process using the `--seed` CLI option.
100
+ # # Setting this allows you to use `--seed` to deterministically reproduce
101
+ # # test failures related to randomization by passing the same `--seed` value
102
+ # # as the one that triggered the failure.
103
+ # Kernel.srand config.seed
104
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_hash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Karloku Sang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coveralls
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codeclimate-test-reporter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '11.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '11.1'
83
+ description: Ruby short cut for making hash
84
+ email:
85
+ - karloku@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - MIT-LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - lib/simple_hash.rb
99
+ - lib/simple_hash/version.rb
100
+ - simple_hash.gemspec
101
+ - spec/simple_hash/simple_hash_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/karloku/simple_hash
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 2.1.0
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.5.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Ruby short cut for making hash
127
+ test_files: []