ascheink-active_yaml 0.0.1
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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/active_yaml.gemspec +53 -0
- data/lib/active_yaml.rb +35 -0
- data/test/active_yaml_test.rb +44 -0
- data/test/app/models/city.rb +4 -0
- data/test/db/yaml/city.yml +9 -0
- data/test/test_helper.rb +10 -0
- metadata +76 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andrei Scheinkman
|
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
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "active_yaml"
|
8
|
+
gem.summary = %Q{ActiveYAML}
|
9
|
+
gem.email = "andreischeinkman@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/ascheink/active_yaml"
|
11
|
+
gem.authors = ["Andrei Scheinkman"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
gem.add_dependency('activesupport', '>= 1.0.0')
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION.yml')
|
46
|
+
config = YAML.load(File.read('VERSION.yml'))
|
47
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "active_yaml #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
57
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/active_yaml.gemspec
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{active_yaml}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Andrei Scheinkman"]
|
9
|
+
s.date = %q{2009-07-06}
|
10
|
+
s.email = %q{andreischeinkman@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"active_yaml.gemspec",
|
23
|
+
"lib/active_yaml.rb",
|
24
|
+
"test/active_yaml_test.rb",
|
25
|
+
"test/app/models/city.rb",
|
26
|
+
"test/db/yaml/city.yml",
|
27
|
+
"test/test_helper.rb"
|
28
|
+
]
|
29
|
+
s.has_rdoc = true
|
30
|
+
s.homepage = %q{http://github.com/ascheink/active_yaml}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.1}
|
34
|
+
s.summary = %q{ActiveYAML}
|
35
|
+
s.test_files = [
|
36
|
+
"test/active_yaml_test.rb",
|
37
|
+
"test/app/models/city.rb",
|
38
|
+
"test/test_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 2
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 1.0.0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<activesupport>, [">= 1.0.0"])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<activesupport>, [">= 1.0.0"])
|
52
|
+
end
|
53
|
+
end
|
data/lib/active_yaml.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'activesupport'
|
3
|
+
class ActiveYAML
|
4
|
+
@instances = []
|
5
|
+
def initialize(h)
|
6
|
+
@h = h
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.inherited(p)
|
10
|
+
data = YAML.load_file("#{RAILS_ROOT}/db/yaml/#{p.name.underscore}.yml")
|
11
|
+
p.class_eval do
|
12
|
+
@instances = []
|
13
|
+
fields = []
|
14
|
+
for id, entry in data
|
15
|
+
entry.merge!({'id' => id})
|
16
|
+
@instances << self.new(entry)
|
17
|
+
for key, value in entry
|
18
|
+
unless fields.include? key
|
19
|
+
fields << key
|
20
|
+
eval "def #{key}; @h[\"#{key}\"]; end"
|
21
|
+
class_eval "def self.find_by_#{key}(x); @instances.find { |i| i.#{key} == x }; end"
|
22
|
+
class_eval "def self.find_all_by_#{key}(x); @instances.find_all { |i| i.#{key} == x }; end"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class_eval "def self.find(id); find_by_id(id) or raise ActiveRecord::RecordNotFound; end"
|
26
|
+
class_eval "def self.first; @instances.first or raise ActiveRecord::RecordNotFound; end"
|
27
|
+
class_eval "def self.last; @instances.last or raise ActiveRecord::RecordNotFound; end"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find_all
|
31
|
+
@instances
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveYamlTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
ActiveYAML::RAILS_ROOT = 'test'
|
6
|
+
require 'app/models/city.rb'
|
7
|
+
|
8
|
+
context "class" do
|
9
|
+
should "create find_all" do
|
10
|
+
assert_respond_to City, :find_all
|
11
|
+
end
|
12
|
+
|
13
|
+
should "create first and last" do
|
14
|
+
assert_respond_to City, :first
|
15
|
+
assert_respond_to City, :last
|
16
|
+
end
|
17
|
+
|
18
|
+
should "create find_by methods for each attribute" do
|
19
|
+
assert_respond_to City, :find_by_id
|
20
|
+
assert_respond_to City, :find_by_display_name
|
21
|
+
assert_respond_to City, :find_by_population
|
22
|
+
end
|
23
|
+
|
24
|
+
should "create find_all_by methods for each attribute" do
|
25
|
+
assert_respond_to City, :find_all_by_id
|
26
|
+
assert_respond_to City, :find_all_by_display_name
|
27
|
+
assert_respond_to City, :find_all_by_population
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "instance" do
|
32
|
+
setup do
|
33
|
+
@i = City.first
|
34
|
+
end
|
35
|
+
|
36
|
+
should "create attribute accessors" do
|
37
|
+
assert_respond_to @i, :id
|
38
|
+
assert_respond_to @i, :display_name
|
39
|
+
assert_respond_to @i, :population
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ascheink-active_yaml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrei Scheinkman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-06 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: andreischeinkman@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- active_yaml.gemspec
|
42
|
+
- lib/active_yaml.rb
|
43
|
+
- test/active_yaml_test.rb
|
44
|
+
- test/app/models/city.rb
|
45
|
+
- test/db/yaml/city.yml
|
46
|
+
- test/test_helper.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/ascheink/active_yaml
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: ActiveYAML
|
73
|
+
test_files:
|
74
|
+
- test/active_yaml_test.rb
|
75
|
+
- test/app/models/city.rb
|
76
|
+
- test/test_helper.rb
|