mameconf 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ vendor
20
+
21
+ # for emacs
22
+ *~
23
+ \#*
24
+ .\#*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fs --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mameconf.gemspec
4
+ gemspec
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ notification :growl
5
+
6
+ guard 'rspec' do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 sutetotanuki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Mameconf
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mameconf'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mameconf
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Bundler.setup
4
+
5
+ require "rspec"
6
+ require "rspec/core/rake_task"
7
+
8
+ RSpec::Core::RakeTask.new(:rspec) do |config|
9
+ end
10
+
11
+ task default: :spec
12
+
13
+
@@ -0,0 +1,58 @@
1
+ require "mameconf/version"
2
+
3
+ module Mameconf
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ base.__send__(:include, InstanceMethods)
7
+ end
8
+
9
+ module InstanceMethods
10
+ def initialize_mameconf(options={})
11
+ options.each do |key, value|
12
+ method = "#{key}="
13
+
14
+ __send__(method, value) if respond_to?(method)
15
+ end
16
+ end
17
+
18
+ def initialize(options={})
19
+ initialize_mameconf(options)
20
+ end
21
+ end
22
+
23
+ module ClassMethods
24
+ attr_accessor :mameconf_attr_names
25
+
26
+ def mameconf_attr_names
27
+ @mameconf_attr_names ||= []
28
+ end
29
+
30
+ def mameconf(name, options={})
31
+ mameconf_attr_names << name
32
+
33
+ default_value = options[:default]
34
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
35
+ def #{name}
36
+ if !instance_variables.include?(:@#{name})
37
+ @#{name} ||= #{default_value.inspect}
38
+ end
39
+
40
+ @#{name}
41
+ end
42
+
43
+ def #{name}=(val)
44
+ @#{name} = val
45
+ end
46
+
47
+ def to_hash
48
+ ret = {}
49
+ self.class.mameconf_attr_names.each do |attr|
50
+ attr_sym = attr.to_sym
51
+ ret[attr_sym] = self.__send__(attr_sym)
52
+ end
53
+ ret
54
+ end
55
+ RUBY
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Mameconf
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mameconf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mameconf"
8
+ spec.version = Mameconf::VERSION
9
+ spec.authors = ["sutetotanuki"]
10
+ spec.email = ["sutetotanuki@gmail.com"]
11
+ spec.description = %q{mame config}
12
+ spec.summary = %q{mame config}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec"
25
+ spec.add_development_dependency "growl"
26
+ spec.add_development_dependency "rb-fsevent"
27
+ end
@@ -0,0 +1,125 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ describe Mameconf do
5
+ describe "basic behavor" do
6
+ subject do
7
+ Class.new do
8
+ include Mameconf
9
+ mameconf :host, default: "localhost"
10
+ end.new
11
+ end
12
+
13
+ it "returns default value if not present" do
14
+ subject.host.should eq "localhost"
15
+ end
16
+
17
+ it "allows to override default value" do
18
+ instance = subject
19
+ instance.host = "google.com"
20
+
21
+ instance.host.should eq "google.com"
22
+ end
23
+
24
+ it "allows to set nil value to attribute" do
25
+ instance = subject
26
+ instance.host = "google.com"
27
+ instance.host = nil
28
+
29
+ instance.host.should be_nil
30
+ end
31
+ end
32
+
33
+ describe "#to_hash" do
34
+ subject do
35
+ Class.new do
36
+ include Mameconf
37
+
38
+ mameconf :host, default: "localhost"
39
+ mameconf :port, default: 3337
40
+ end
41
+ end
42
+
43
+ it "returns hash that included default values" do
44
+ subject.new.to_hash.should eq ({ host: "localhost", port: 3337 })
45
+ end
46
+
47
+ context "has no default value attribute" do
48
+ before do
49
+ subject.class_eval do
50
+ mameconf :namespace
51
+ end
52
+ end
53
+
54
+ it "has no dafalut value attribtue" do
55
+ subject.new.namespace.should be_nil
56
+ end
57
+
58
+ it "has attributes that has default value" do
59
+ subject.new.host.should eq "localhost"
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "inheritance" do
65
+ before do
66
+ @parent = Class.new do
67
+ include Mameconf
68
+
69
+ mameconf :host, default: "localhost"
70
+ end
71
+
72
+ @sub = Class.new(@parent)
73
+ end
74
+
75
+ it "has mameconf attribute" do
76
+ @sub.new.host.should eq "localhost"
77
+ end
78
+
79
+ context "add new attribute on Sub Class" do
80
+ before do
81
+ @sub.class_eval do
82
+ mameconf :sub, default: "inu"
83
+ end
84
+ end
85
+
86
+ it "has different memory space" do
87
+ @sub.new.sub.should eq "inu"
88
+
89
+ expect {
90
+ @parent.new.sub
91
+ }.to raise_error NoMethodError
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "#initialize" do
97
+ subject do
98
+ Class.new do
99
+ include Mameconf
100
+
101
+ mameconf :host, default: "localhost"
102
+ end
103
+ end
104
+
105
+ it "can initiate from constructor" do
106
+ subject.new(host: "sibainu.com").host.should eq "sibainu.com"
107
+ end
108
+
109
+ context "override initializer on Sub Class" do
110
+ before do
111
+ subject.class_eval do
112
+ def initialize(options)
113
+ # TODO: 本当はココになにも書かず初期化したい。
114
+ # でも多分無理。
115
+ initialize_mameconf(options)
116
+ end
117
+ end
118
+ end
119
+
120
+ it "can initiate from constructor" do
121
+ subject.new(host: "sibainu.com").host.should eq "sibainu.com"
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path(__FILE__, "../lib")
2
+
3
+ require "mameconf"
4
+
5
+ Rspec.configure do |c|
6
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mameconf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sutetotanuki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: growl
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rb-fsevent
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: mame config
111
+ email:
112
+ - sutetotanuki@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - Gemfile
120
+ - Guardfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/mameconf.rb
125
+ - lib/mameconf/version.rb
126
+ - mameconf.gemspec
127
+ - spec/mameconf_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: ''
130
+ licenses:
131
+ - MIT
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.23
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: mame config
154
+ test_files:
155
+ - spec/mameconf_spec.rb
156
+ - spec/spec_helper.rb
157
+ has_rdoc: