Get_Set 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/Get_Set.gemspec +29 -0
- data/Rakefile +1 -0
- data/lib/Get_Set/version.rb +3 -0
- data/lib/Get_Set.rb +45 -0
- data/spec/helper.rb +15 -0
- data/spec/main.rb +19 -0
- data/spec/tests/DSL.rb +56 -0
- metadata +99 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Get_Set.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "Get_Set/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "Get_Set"
|
7
|
+
s.version = Get_Set::VERSION
|
8
|
+
s.authors = ["da99"]
|
9
|
+
s.email = ["i-hate-spam-45671204@mailinator.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{An alternative to :attr_accessor}
|
12
|
+
s.description = %q{
|
13
|
+
Creates instance method that can both get or set an instance variable.
|
14
|
+
It's like squeezing :attr_writer into :attr_reader.
|
15
|
+
}
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "bacon"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency 'Bacon_Colored'
|
25
|
+
|
26
|
+
# s.rubyforge_project = "Get_Set"
|
27
|
+
# specify any dependencies here; for example:
|
28
|
+
s.add_runtime_dependency "Checked"
|
29
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/Get_Set.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "Get_Set/version"
|
2
|
+
require 'Checked'
|
3
|
+
|
4
|
+
module Get_Set
|
5
|
+
|
6
|
+
module DSL
|
7
|
+
|
8
|
+
include Checked::DSL
|
9
|
+
|
10
|
+
def self.included klass
|
11
|
+
klass.extend Class_Methods
|
12
|
+
end
|
13
|
+
|
14
|
+
module Class_Methods
|
15
|
+
|
16
|
+
include Checked::DSL
|
17
|
+
|
18
|
+
def attr_get_set *names
|
19
|
+
Array!(names).symbols!
|
20
|
+
names.each { |n|
|
21
|
+
class_eval %~
|
22
|
+
def #{n} *args
|
23
|
+
Get_Set! :@#{n}, *args
|
24
|
+
end
|
25
|
+
~, __FILE__, __LINE__
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
end # === module Class_Methods
|
30
|
+
|
31
|
+
def Get_Set! *args
|
32
|
+
Size! args, 1..2
|
33
|
+
name = args.shift
|
34
|
+
raise ArgumentError, "Instance variable #{name.inspect} has not been defined." unless instance_variable_defined?(name)
|
35
|
+
|
36
|
+
if args.empty?
|
37
|
+
instance_variable_get name
|
38
|
+
else
|
39
|
+
instance_variable_set name, args.first
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end # === module DSL
|
44
|
+
|
45
|
+
end # === module Get_Set
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'bacon'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
|
15
|
+
Bacon.summary_on_exit
|
data/spec/main.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('spec/helper')
|
3
|
+
require 'Get_Set'
|
4
|
+
require 'Bacon_Colored'
|
5
|
+
|
6
|
+
Klass = Class.new {
|
7
|
+
|
8
|
+
include Get_Set::DSL
|
9
|
+
attr_get_set :name
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@name = 'Ultra Force'
|
13
|
+
end
|
14
|
+
|
15
|
+
}
|
16
|
+
|
17
|
+
Dir.glob('spec/tests/*.rb').each { |file|
|
18
|
+
require File.expand_path(file.sub('.rb', '')) if File.file?(file)
|
19
|
+
}
|
data/spec/tests/DSL.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
describe "Get_Set! :@var" do
|
4
|
+
|
5
|
+
before { extend Get_Set::DSL }
|
6
|
+
|
7
|
+
it 'raises ArgumentError if instance variable has not been initialized.' do
|
8
|
+
lambda { Get_Set! :@something }
|
9
|
+
.should.raise(ArgumentError)
|
10
|
+
.message.should.match %r!@something has not been defined!
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'gets instance variable if array is empty.' do
|
14
|
+
@server = :hi
|
15
|
+
Get_Set!( :@server ).should == @server
|
16
|
+
end
|
17
|
+
|
18
|
+
end # === describe Get_Set!
|
19
|
+
|
20
|
+
describe "Get_Set! :@var, var" do
|
21
|
+
|
22
|
+
before { extend Get_Set::DSL }
|
23
|
+
|
24
|
+
it 'raises ArgumentError if instance variable has not been initialized.' do
|
25
|
+
lambda { Get_Set! :@someg, :hi}
|
26
|
+
.should.raise(ArgumentError)
|
27
|
+
.message.should.match %r!@someg has not been defined!
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'sets instance variable.' do
|
31
|
+
@server = :hi
|
32
|
+
Get_Set!( :@server, :bye)
|
33
|
+
@server.should == :bye
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns last value' do
|
37
|
+
@server = :hi
|
38
|
+
Get_Set!( :@server, :bye ).should == :bye
|
39
|
+
end
|
40
|
+
|
41
|
+
end # === describe Get_Set!
|
42
|
+
|
43
|
+
describe ":attr_get_set :name" do
|
44
|
+
|
45
|
+
before { @klass = Klass.new }
|
46
|
+
|
47
|
+
it 'defines method to retrieve value' do
|
48
|
+
@klass.name.should == 'Ultra Force'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'defines method to set value' do
|
52
|
+
@klass.name(:Ultra)
|
53
|
+
@klass.name.should == :Ultra
|
54
|
+
end
|
55
|
+
|
56
|
+
end # === describe :attr_get_set :name
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Get_Set
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- da99
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bacon
|
16
|
+
requirement: &17488100 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *17488100
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &17487380 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *17487380
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: Bacon_Colored
|
38
|
+
requirement: &17485840 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *17485840
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: Checked
|
49
|
+
requirement: &17400580 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *17400580
|
58
|
+
description: ! "\n Creates instance method that can both get or set an instance
|
59
|
+
variable. \n It's like squeezing :attr_writer into :attr_reader.\n "
|
60
|
+
email:
|
61
|
+
- i-hate-spam-45671204@mailinator.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- Gemfile
|
68
|
+
- Get_Set.gemspec
|
69
|
+
- Rakefile
|
70
|
+
- lib/Get_Set.rb
|
71
|
+
- lib/Get_Set/version.rb
|
72
|
+
- spec/helper.rb
|
73
|
+
- spec/main.rb
|
74
|
+
- spec/tests/DSL.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses: []
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.8.15
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: An alternative to :attr_accessor
|
99
|
+
test_files: []
|