mongo_mapper-strict_keys 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -cfs
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mongo_mapper-strict_keys.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec'
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+
7
+ task :release => :spec
8
+
9
+ desc "Run Specs"
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = "spec/**/*_spec.rb"
12
+ spec.verbose = true
13
+ spec.rspec_opts = ['--color']
14
+ end
@@ -0,0 +1,7 @@
1
+ module MongoMapper
2
+ module Plugins
3
+ module StrictKeys
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ require 'mongo_mapper'
2
+ require 'mongo_mapper/plugins'
3
+ require 'mongo_mapper/strict_keys/version'
4
+
5
+ module MongoMapper
6
+ module Plugins
7
+ module StrictKeys
8
+ extend ActiveSupport::Concern
9
+
10
+ module ClassMethods; end
11
+
12
+ module InstanceMethods
13
+ def ensure_key_exists(name)
14
+ # Do nothing.
15
+ unless respond_to?("#{name}=")
16
+ raise ArgumentError.new("Attribute #{name} has not been explicitly defined as a key.")
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ require 'mongo_mapper/strict_keys'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mongo_mapper/strict_keys/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mongo_mapper-strict_keys"
7
+ s.version = MongoMapper::Plugins::StrictKeys::VERSION
8
+ s.authors = ["Scott Gonyea"]
9
+ s.email = ["me@sgonyea.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Mongo Mapper Strict Keys Plugin}
12
+ s.description = %q{Mongo Mapper Strict Keys Plugin.}
13
+
14
+ s.add_dependency 'mongo_mapper'
15
+ s.add_dependency 'activesupport'
16
+ s.add_dependency 'i18n'
17
+
18
+ s.add_development_dependency 'rspec', '~>2.6.0'
19
+ s.add_development_dependency 'bson_ext', '~>1.3.1'
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+
3
+ describe MongoMapper::Plugins::StrictKeys do
4
+
5
+ class SimpleModel
6
+ include MongoMapper::Document
7
+ include MongoMapper::Plugins::StrictKeys
8
+
9
+ key :string_key, String
10
+ end
11
+
12
+ describe 'Instance attributes' do
13
+ before(:each) do
14
+ @sm = SimpleModel.new
15
+ end
16
+
17
+ context 'attributes-as-methods' do
18
+ it 'should accept attributes-as-methods for pre-defined keys' do
19
+ lambda {
20
+ @sm.string_key = "I work!"
21
+ }.should_not raise_error
22
+
23
+ @sm.string_key.should == "I work!"
24
+ end
25
+
26
+ it 'should reject attributes-as-methods for never-defined keys' do
27
+ lambda {
28
+ @sm.not_defined = 'blowed up'
29
+ }.should raise_error(NoMethodError)
30
+ end
31
+ end
32
+
33
+ context 'attributes-in-brackets' do
34
+ it 'should accept attributes-in-brackets for pre-defined keys' do
35
+ lambda {
36
+ @sm[:string_key] = "I work!"
37
+ }.should_not raise_error
38
+
39
+ @sm[:string_key].should == "I work!"
40
+ end
41
+
42
+ it 'should reject attributes-in-brackets for never-defined keys' do
43
+ lambda {
44
+ @sm[:not_defined] = 'blowed up'
45
+ }.should raise_error(ArgumentError)
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+
3
+ Bundler.require :development
4
+ Bundler.require :default
5
+
6
+ MongoMapper.connection = ::Mongo::ReplSetConnection.new(["localhost", 27017])
7
+ MongoMapper.database = 'mongo_mapper-strict_keys-test'
8
+
9
+ Dir[ Bundler.root.join("spec/support/**/*.rb") ].each{|f| require f}
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_mapper-strict_keys
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Scott Gonyea
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-06-07 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mongo_mapper
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: i18n
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 2
69
+ - 6
70
+ - 0
71
+ version: 2.6.0
72
+ type: :development
73
+ version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: bson_ext
76
+ prerelease: false
77
+ requirement: &id005 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 1
84
+ - 3
85
+ - 1
86
+ version: 1.3.1
87
+ type: :development
88
+ version_requirements: *id005
89
+ description: Mongo Mapper Strict Keys Plugin.
90
+ email:
91
+ - me@sgonyea.com
92
+ executables: []
93
+
94
+ extensions: []
95
+
96
+ extra_rdoc_files: []
97
+
98
+ files:
99
+ - .gitignore
100
+ - .rspec
101
+ - Gemfile
102
+ - Rakefile
103
+ - lib/mongo_mapper-strict_keys.rb
104
+ - lib/mongo_mapper/strict_keys.rb
105
+ - lib/mongo_mapper/strict_keys/version.rb
106
+ - mongo_mapper-strict_keys.gemspec
107
+ - spec/mongo_mapper/strict_keys_spec.rb
108
+ - spec/spec_helper.rb
109
+ has_rdoc: true
110
+ homepage: ""
111
+ licenses: []
112
+
113
+ post_install_message:
114
+ rdoc_options: []
115
+
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.3.7
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Mongo Mapper Strict Keys Plugin
141
+ test_files:
142
+ - spec/mongo_mapper/strict_keys_spec.rb
143
+ - spec/spec_helper.rb