ex_struct 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 takkaw
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = ex_struct
2
+ ExStruct is expandable OpenStruct.
3
+
4
+ == Usage
5
+ require 'ex_struct'
6
+ foo = ExStruct.new
7
+ foo.bar.baz = :hello
8
+
9
+ foo.bar.baz? # => :hello
10
+
11
+ == Contributing to ex_struct
12
+
13
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
14
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
15
+ * Fork the project
16
+ * Start a feature/bugfix branch
17
+ * Commit and push until you are happy with your contribution
18
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
19
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2011 takkaw. See LICENSE.txt for
24
+ further details.
25
+
data/Rakefile ADDED
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
9
+ gem.name = "ex_struct"
10
+ gem.homepage = "http://github.com/takkaw/ex_struct"
11
+ gem.license = "MIT"
12
+ gem.summary = %Q{ExStruct is expandable OpenStruct.}
13
+ gem.description = %Q{ExStruct is expandable OpenStruct.For example, ExStruct.new.foo.bar.baz = :hello}
14
+ gem.email = "takkaw@gmail.com"
15
+ gem.authors = ["takkaw"]
16
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
17
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
18
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
19
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
20
+ gem.add_development_dependency "shoulda", ">= 0"
21
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
22
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
24
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
25
+ # gem.add_development_dependency "bundler", "~> 1.0.0"
26
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
27
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
28
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
29
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
30
+ gem.add_development_dependency "jeweler", "~> 1.6.4"
31
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
32
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
33
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
34
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
35
+ gem.add_development_dependency "rcov", ">= 0"
36
+ end
37
+ Jeweler::RubygemsDotOrgTasks.new
38
+
39
+ require 'rake/testtask'
40
+ Rake::TestTask.new(:test) do |test|
41
+ test.libs << 'lib' << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ end
45
+
46
+ require 'rcov/rcovtask'
47
+ Rcov::RcovTask.new do |test|
48
+ test.libs << 'test'
49
+ test.pattern = 'test/**/test_*.rb'
50
+ test.verbose = true
51
+ test.rcov_opts << '--exclude "gems/*"'
52
+ end
53
+
54
+ task :default => :test
55
+
56
+ gem 'rdoc'
57
+ require 'rdoc/task'
58
+ RDoc::Task.new do |rdoc|
59
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
60
+
61
+ rdoc.rdoc_dir = 'rdoc'
62
+ rdoc.title = "ex_struct #{version}"
63
+ rdoc.rdoc_files.include('README*')
64
+ rdoc.rdoc_files.include('lib/**/*.rb')
65
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/ex_struct.gemspec ADDED
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ex_struct}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["takkaw"]
12
+ s.date = %q{2011-08-09}
13
+ s.description = %q{ExStruct is expandable OpenStruct.For example, ExStruct.new.foo.bar.baz = :hello}
14
+ s.email = %q{takkaw@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE.txt",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "ex_struct.gemspec",
26
+ "lib/ex_struct.rb",
27
+ "test/helper.rb",
28
+ "test/test_ex_struct.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/takkaw/ex_struct}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.6.2}
34
+ s.summary = %q{ExStruct is expandable OpenStruct.}
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
41
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
42
+ s.add_development_dependency(%q<rcov>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
46
+ s.add_dependency(%q<rcov>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
51
+ s.add_dependency(%q<rcov>, [">= 0"])
52
+ end
53
+ end
54
+
data/lib/ex_struct.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'ostruct'
2
+ class ExStruct < OpenStruct
3
+ def method_missing(mid, *args)
4
+ mname = mid.id2name
5
+ len = args.length
6
+ if mname.chomp!('=')
7
+ if len != 1
8
+ raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
9
+ end
10
+ modifiable[new_ostruct_member(mname)] = args[0]
11
+ elsif mname.chomp!('?')
12
+ if len != 0
13
+ raise ArgumentError, "wrong number of arguments (#{len} for 0)", caller(1)
14
+ end
15
+ @table[mname.to_sym]
16
+ elsif len == 0
17
+ ret = @table[mid]
18
+ ret = (modifiable[new_ostruct_member(mname)] = self.class.new) unless ret
19
+ ret
20
+ else
21
+ raise ArgumentError, "wrong number of arguments (#{len} for 0)", caller(1)
22
+ end
23
+ end
24
+ end
25
+
data/test/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'minifilter/pretty' if Gem.available? 'minifilter'
8
+ require 'ex_struct'
9
+
10
+ class Test::Unit::TestCase
11
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ class TestExStruct < Test::Unit::TestCase
4
+ should "add new method as value = 100" do
5
+ conf = ExStruct.new
6
+ conf.value = 100
7
+ conf.foo.value = 200
8
+ assert_equal conf.value,100
9
+ end
10
+ should "touch new method" do
11
+ conf = ExStruct.new
12
+ conf.test
13
+ assert ExStruct === conf.test
14
+ end
15
+ should "add new multiple method" do
16
+ conf = ExStruct.new
17
+ conf.foo.bar.baz = "ok"
18
+ assert_equal conf.foo.bar.baz ,"ok"
19
+ end
20
+ should "not yet touch method is nil" do
21
+ conf = ExStruct.new
22
+ assert_equal conf.not_yet? , nil
23
+ end
24
+ should "raise ArgumentError" do
25
+ conf = ExStruct.new
26
+ assert_raise(ArgumentError) {
27
+ conf[1,2,3] = :test
28
+ }
29
+ assert_raise(ArgumentError) {
30
+ conf.test? :foo,:bar
31
+ }
32
+ assert_raise(ArgumentError){
33
+ conf.test :foo
34
+ }
35
+ end
36
+ end
37
+
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ex_struct
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - takkaw
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-09 00:00:00.000000000 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ requirement: &2152538620 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2152538620
26
+ - !ruby/object:Gem::Dependency
27
+ name: jeweler
28
+ requirement: &2152537400 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2152537400
37
+ - !ruby/object:Gem::Dependency
38
+ name: rcov
39
+ requirement: &2152536300 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2152536300
48
+ description: ExStruct is expandable OpenStruct.For example, ExStruct.new.foo.bar.baz
49
+ = :hello
50
+ email: takkaw@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files:
54
+ - LICENSE.txt
55
+ - README.rdoc
56
+ files:
57
+ - .document
58
+ - LICENSE.txt
59
+ - README.rdoc
60
+ - Rakefile
61
+ - VERSION
62
+ - ex_struct.gemspec
63
+ - lib/ex_struct.rb
64
+ - test/helper.rb
65
+ - test/test_ex_struct.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/takkaw/ex_struct
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.6.2
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: ExStruct is expandable OpenStruct.
92
+ test_files: []