include_constants 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e93b0487b44065912b60f5512edb60d15f8fc23
4
+ data.tar.gz: e8550a1f22cb52808de1f76a5b8e2a72e6b472b3
5
+ SHA512:
6
+ metadata.gz: 1792c3c1bbcc9b305ccda4a6c2d7e230063bee5ae31115ff7f4f08a96d67078030a5db35fb571bcc18fe1c032b647ef00a66399c6225d7f8aaf9657e44921831
7
+ data.tar.gz: 8770de3ae254c7ae2102295f7251512f11120ac6fb8743e55cc95152f4f8273281054714ef2f4e06f6051b06a9caa8343d30ae48e91a1169cd12e3d2e1a71d38
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,9 @@
1
+ Gem::Specification.new do |g|
2
+ g.name = 'include_constants'
3
+ g.files = `git ls-files`.split($/)
4
+ g.version = '0.0.0'
5
+ g.summary = 'A way to include constants from a module, without including its methods.'
6
+ g.authors = ['Anatoly Chernow']
7
+
8
+ g.add_development_dependency 'minitest-power_assert'
9
+ end
@@ -0,0 +1 @@
1
+ require_relative './include_constants/core_ext/module'
@@ -0,0 +1,11 @@
1
+ class Module
2
+ def include_constants(*constants, from:)
3
+ constants = from.constants if constants.empty?
4
+ constants.each do |constant|
5
+ unless from.constants.include? constant
6
+ raise "Cannot include the constant #{constant} from #{from}, because #{from} doesn't have one with such a name."
7
+ end
8
+ const_set constant, (const_get "#{from}::#{constant}")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ require 'include_constants'
2
+ require 'minitest'
3
+ require 'minitest-power_assert'
4
+
5
+ Minitest.autorun
6
+ Test = Minitest::Test
7
+
8
+ module M
9
+ A = 0
10
+ B = 1
11
+ C = 2
12
+ end
13
+
14
+ class Acceptance < Test
15
+ def setup
16
+ @m = Module.new
17
+ end
18
+
19
+ def test_including_all_constants
20
+ @m.include_constants from: M
21
+
22
+ [:A,:B,:C].each do |c|
23
+ assert { @m.constants.include? c }
24
+ end
25
+ end
26
+
27
+ def test_including_some_constants
28
+ @m.include_constants :A, :B, from: M
29
+
30
+ assert { @m.constants.include? :A }
31
+ assert { @m.constants.include? :B }
32
+ assert { not @m.constants.include? :C }
33
+ end
34
+
35
+ def test_trying_to_include_nonexistent_constant
36
+ assert_raises RuntimeError do
37
+ @m.include_constants :A, :B, :D, from: M
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: include_constants
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anatoly Chernow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest-power_assert
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
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - Gemfile
34
+ - include_constants.gemspec
35
+ - lib/include_constants.rb
36
+ - lib/include_constants/core_ext/module.rb
37
+ - test/test.rb
38
+ homepage:
39
+ licenses: []
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.4.5
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A way to include constants from a module, without including its methods.
61
+ test_files: []
62
+ has_rdoc: