set_const 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/set_const.rb +13 -0
  3. data/tests/tests.rb +44 -0
  4. metadata +116 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58a36abe6346bbeaa023657b250f96c7823f2ca7
4
+ data.tar.gz: cc39350a673a9a212e7fe8aa735679fda1e7f914
5
+ SHA512:
6
+ metadata.gz: 474d00788f0c5c1b7f84ad710cba54638948d256478b5c4ea4f839f6f39e555f4a602cdcf30a0ea07bd4e769e0027a5925c8a24ee34337020049e488fdfaee5a
7
+ data.tar.gz: 133b028df98ed97eb38f3cefc9b4c275eb8fbe5f909be62703493a98294158eca2f22686b2ab42149a09bd4c21cebd5fc9324a2f94a97b8c080e40018a248cfb
data/lib/set_const.rb ADDED
@@ -0,0 +1,13 @@
1
+ # -*- coding: UTF-8 -*-
2
+
3
+ require 'silent'
4
+
5
+ def set_const(name, value, **opts)
6
+ parent = opts[:parent] || Object
7
+
8
+ silent(:stderr) do
9
+ parent.send(:const_set, name, value)
10
+ end
11
+
12
+ value
13
+ end
data/tests/tests.rb ADDED
@@ -0,0 +1,44 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ require 'test/unit'
8
+ require 'simplecov'
9
+
10
+ test_dir = File.expand_path( File.dirname(__FILE__) )
11
+
12
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
13
+ SimpleCov.start { add_filter '/tests/' }
14
+
15
+ require 'set_const'
16
+
17
+ class SetConstTests < Test::Unit::TestCase
18
+ def setup
19
+ @_stderr, $stderr = $stderr, StringIO.new
20
+ end
21
+
22
+ def teardown
23
+ $stderr = @_stderr
24
+ end
25
+
26
+ def test_returned_value
27
+ v = rand
28
+ assert_equal(v, set_const('ARGV', v))
29
+ end
30
+
31
+ def test_nonexitent_const
32
+ assert_nothing_raised { set_const('IDONTEXIST_210X43A', 18) }
33
+ end
34
+
35
+ def test_simple_set_const_ARGV
36
+ set_const('ARGV', 42)
37
+ assert_equal(42, ARGV)
38
+ $stderr.seek(0)
39
+ assert_equal('', $stderr.read)
40
+ end
41
+ end
42
+
43
+
44
+ exit Test::Unit::AutoRunner.run
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: set_const
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Baptiste Fontaine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: silent
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ description: Change a constant's value without any warning
84
+ email: batifon@yahoo.fr
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/set_const.rb
90
+ - tests/tests.rb
91
+ homepage: https://github.com/bfontaine/set_const
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Modify constants without warning
115
+ test_files:
116
+ - tests/tests.rb