attr_readwrite 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rspec
6
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in attr_readwrite.gemspec
4
+ gemspec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ guard 'rspec', :version => 2, :all_on_start => true, :all_after_pass => false, :cli => '--color --format doc' do
4
+ watch( %r{^spec/.+_spec\.rb$} )
5
+ watch( %r{^lib/(.+)\.rb$} ) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch( 'spec/spec_helper.rb' ) { "spec" }
7
+ end
@@ -0,0 +1,43 @@
1
+ = attr_readwrite
2
+
3
+ attr_readwrite adds a method to compliment attr_readonly. This method is the exact opposite of attr_readonly and both should
4
+ not be used simultaneously.
5
+
6
+
7
+ == COMPATABILITY
8
+
9
+ * Ruby 1.8
10
+ * Rails 3
11
+ * Rails 2
12
+
13
+ Ruby 1.9.x is untested at this point.
14
+
15
+
16
+ == INSTALL
17
+
18
+ gem sources -a http://gemcutter.org
19
+ sudo gem install attr_readwrite
20
+
21
+ == Note on Patches/Pull Requests
22
+
23
+ * Fork the project.
24
+ * Make your feature addition or bug fix.
25
+ * Add tests for it. This is important so I don't break it in a
26
+ future version unintentionally.
27
+ * Commit, do not mess with rakefile, version, or history.
28
+ (if you want to have your own version, that is fine but
29
+ bump version in a commit by itself I can ignore when I pull)
30
+ * Send me a pull request. Bonus points for topic branches.
31
+
32
+
33
+ == LICENSE
34
+
35
+ Copyright (c) 2009 C. Jason Harrelson (midas)
36
+
37
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
38
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
40
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
41
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
42
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
43
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "attr_readwrite/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "attr_readwrite"
7
+ s.version = AttrReadwrite::VERSION
8
+ s.authors = ["C. Jason Harrelson"]
9
+ s.email = ["cjharrelson@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A companion to ActiveRecord's attr_readonly.}
12
+ s.description = %q{The opposite of ActiveRecord's attr_readonly.}
13
+
14
+ s.rubyforge_project = "attr_readwrite"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ %w(
22
+ gem-dandy
23
+ rb-fsevent
24
+ growl
25
+ guard-rspec
26
+ guard
27
+ rspec
28
+ rails
29
+ ruby-debug
30
+ sqlite3-ruby
31
+ ).each do |development_dependency|
32
+ s.add_development_dependency development_dependency
33
+ end
34
+
35
+ # s.add_runtime_dependency "rest-client"
36
+ end
@@ -0,0 +1,8 @@
1
+ require "attr_readwrite/railtie" if defined?( ::Rails )
2
+ require "attr_readwrite/version"
3
+
4
+ module AttrReadwrite
5
+
6
+ autoload :ActiveRecordExtensions, 'attr_readwrite/active_record_extensions'
7
+
8
+ end
@@ -0,0 +1,24 @@
1
+ module AttrReadwrite
2
+
3
+ module ActiveRecordExtensions
4
+
5
+ def self.included( base )
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ def attr_readwrite( attr_names )
12
+ readwrite_attr_names = Array( attr_names ).map( &:to_s )
13
+ attr_readonly *(column_names - readwrite_attr_names - %w(id))
14
+ end
15
+
16
+ def readwrite_attributes
17
+ column_names - readonly_attributes.to_a
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails'
2
+
3
+ module AttrReadwrite
4
+
5
+ class Railtie < ::Rails::Railtie
6
+
7
+ #initializer "attr_readwrite.initialize" do
8
+ #if defined?( ActiveRecord::Base )
9
+ #ActiveRecord::Base.send( :include, AttrReadwrite::ActiveRecordExtensions )
10
+ #end
11
+ #end
12
+
13
+ initializer 'attr_readwrite.insert_into_active_record' do
14
+ ActiveSupport.on_load :active_record do
15
+ ActiveRecord::Base.send( :include, AttrReadwrite::ActiveRecordExtensions )
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ module AttrReadwrite
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ ActiveRecord::Base.configurations = YAML::load( IO.read( File.dirname(__FILE__) + '/../spec/database.yml' ) )
2
+ ActiveRecord::Base.establish_connection( 'test' )
3
+
4
+ silence_stream STDOUT do
5
+
6
+ ActiveRecord::Schema.define :version => 1 do
7
+ create_table :somethings, :force => true do |t|
8
+ t.string :name, :description
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'rails_spec_helper'
3
+
4
+ describe AttrReadwrite do
5
+
6
+ context 'when attr_readwrite has not been used' do
7
+
8
+ before :each do
9
+ class Something < ActiveRecord::Base
10
+ end
11
+ end
12
+
13
+ it "should have the correct #column_names" do
14
+ Something.column_names.should == %w(id name description)
15
+ end
16
+
17
+ it "should add the correct read only attributes" do
18
+ Something.readonly_attributes.should == []
19
+ end
20
+
21
+ it "should have the correct #readwrite_attributes" do
22
+ Something.readwrite_attributes.should == %w(id name description)
23
+ end
24
+
25
+ end
26
+
27
+ context 'when attr_readwrite has been used' do
28
+
29
+ before :each do
30
+ class Something < ActiveRecord::Base
31
+ attr_readwrite :name
32
+ end
33
+ end
34
+
35
+ it "should have the correct #column_names" do
36
+ Something.column_names.should == %w(id name description)
37
+ end
38
+
39
+ it "should add the correct read only attributes" do
40
+ Something.readonly_attributes.to_a.should == %w(description)
41
+ end
42
+
43
+ it "should have the correct #readwrite_attributes" do
44
+ Something.readwrite_attributes.should == %w(id name)
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,4 @@
1
+ test:
2
+ :adapter: sqlite3
3
+ :database: ":memory:"
4
+
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Base.send :include, AttrReadwrite::ActiveRecordExtensions
2
+ require File.dirname(__FILE__) + '/../script/environment'
3
+
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'sqlite3'
3
+ require 'active_record'
4
+ require 'rails'
5
+ require 'bundler/setup'
6
+
7
+ require 'attr_readwrite'
8
+
9
+ RSpec.configure do |config|
10
+
11
+ config.mock_with :rspec
12
+
13
+ end
14
+
15
+ class Hash
16
+ # for excluding keys
17
+ def except(*exclusions)
18
+ self.reject { |key, value| exclusions.include? key.to_sym }
19
+ end
20
+
21
+ # for overriding keys
22
+ def with(overrides = {})
23
+ self.merge overrides
24
+ end
25
+ end
26
+
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attr_readwrite
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - C. Jason Harrelson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-26 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: gem-dandy
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rb-fsevent
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: growl
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: guard
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: rspec
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ type: :development
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: rails
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ type: :development
117
+ version_requirements: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ name: ruby-debug
120
+ prerelease: false
121
+ requirement: &id008 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ type: :development
131
+ version_requirements: *id008
132
+ - !ruby/object:Gem::Dependency
133
+ name: sqlite3-ruby
134
+ prerelease: false
135
+ requirement: &id009 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ type: :development
145
+ version_requirements: *id009
146
+ description: The opposite of ActiveRecord's attr_readonly.
147
+ email:
148
+ - cjharrelson@gmail.com
149
+ executables: []
150
+
151
+ extensions: []
152
+
153
+ extra_rdoc_files: []
154
+
155
+ files:
156
+ - .gitignore
157
+ - Gemfile
158
+ - Guardfile
159
+ - README.rdoc
160
+ - Rakefile
161
+ - attr_readwrite.gemspec
162
+ - lib/attr_readwrite.rb
163
+ - lib/attr_readwrite/active_record_extensions.rb
164
+ - lib/attr_readwrite/railtie.rb
165
+ - lib/attr_readwrite/version.rb
166
+ - script/environment.rb
167
+ - spec/attr_readwrite_spec.rb
168
+ - spec/database.yml
169
+ - spec/rails_spec_helper.rb
170
+ - spec/spec_helper.rb
171
+ homepage: ""
172
+ licenses: []
173
+
174
+ post_install_message:
175
+ rdoc_options: []
176
+
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ hash: 3
185
+ segments:
186
+ - 0
187
+ version: "0"
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ hash: 3
194
+ segments:
195
+ - 0
196
+ version: "0"
197
+ requirements: []
198
+
199
+ rubyforge_project: attr_readwrite
200
+ rubygems_version: 1.8.10
201
+ signing_key:
202
+ specification_version: 3
203
+ summary: A companion to ActiveRecord's attr_readonly.
204
+ test_files:
205
+ - spec/attr_readwrite_spec.rb
206
+ - spec/database.yml
207
+ - spec/rails_spec_helper.rb
208
+ - spec/spec_helper.rb