active_attr 0.1.0

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.

Potentially problematic release.


This version of active_attr might be problematic. Click here for more details.

data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ coverage
4
+ Gemfile.lock
5
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/.rvmrc ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.2-p290@active_attr"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create use "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ # if command -v bundle && [[ -s Gemfile ]]
51
+ # then
52
+ # bundle
53
+ # fi
54
+
55
+
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - ree
3
+ - 1.9.2
4
+ bundler_args: --without development
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # ActiveAttr 0.1.0 (September 30, 2011) #
2
+
3
+ * Added MassAssignment#initialize
4
+ * Added MassAssignment#attributes=
5
+ * Added MassAssignment#assign_attributes
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :development_group => :test
4
+
5
+ group :development do
6
+ gem "growl"
7
+ gem "guard"
8
+ gem "guard-bundler"
9
+ gem "guard-rspec"
10
+ gem "rb-fsevent"
11
+ gem 'ruby-debug', :platforms => :mri_18
12
+ gem "ruby-debug19", :platforms => :mri_19 if RUBY_VERSION < "1.9.3"
13
+ gem "spec_coverage", :platforms => :mri_19
14
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'rspec', :version => 2, :cli=> '--format nested --debugger' do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (C) 2011 by Chris Griego
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # ActiveAttr #
2
+
3
+ [![Build History][2]][1]
4
+
5
+ ActiveAttr makes it easy to create plain old ruby models without reinventing the wheel.
6
+
7
+ [1]: http://travis-ci.org/cgriego/active_attr
8
+ [2]: https://secure.travis-ci.org/cgriego/active_attr.png?branch=master
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ task :default => ["spec"]
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ namespace :spec do
10
+ desc "Run RSpec specs with code coverate analysis"
11
+ RSpec::Core::RakeTask.new(:cov) do |spec|
12
+ spec.rspec_opts = "--format nested --format SpecCoverage"
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "active_attr/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "active_attr"
7
+ s.version = ActiveAttr::VERSION
8
+ s.authors = ["Chris Griego"]
9
+ s.email = ["cgriego@gmail.com"]
10
+ s.homepage = "https://github.com/cgriego/active_attr"
11
+ s.summary = %q{What ActiveModel left out}
12
+ s.description = %q{Create plain old ruby models without reinventing the wheel.}
13
+
14
+ s.rubyforge_project = "active_attr"
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
+ s.add_runtime_dependency "activemodel", "~> 3.1"
22
+ s.add_runtime_dependency "activesupport", "~> 3.1"
23
+
24
+ s.add_development_dependency "bundler", "~> 1.0"
25
+ s.add_development_dependency "rake", "~> 0.9.0"
26
+ s.add_development_dependency "rspec", "~> 2.6"
27
+ end
@@ -0,0 +1,4 @@
1
+ require "active_attr/version"
2
+
3
+ module ActiveAttr
4
+ end
@@ -0,0 +1,18 @@
1
+ module ActiveAttr
2
+ module MassAssignment
3
+ def initialize(attributes=nil, options={})
4
+ assign_attributes attributes, options
5
+ end
6
+
7
+ def attributes=(new_attributes)
8
+ assign_attributes new_attributes
9
+ end
10
+
11
+ def assign_attributes(new_attributes, options={})
12
+ new_attributes.each do |name, value|
13
+ writer = "#{name}="
14
+ send writer, value if respond_to? writer
15
+ end if new_attributes
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAttr
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,119 @@
1
+ require "spec_helper"
2
+ require "active_attr/mass_assignment"
3
+
4
+ module ActiveAttr
5
+ describe MassAssignment do
6
+ subject do
7
+ Class.new do
8
+ include MassAssignment
9
+
10
+ attr_accessor :first_name, :last_name, :middle_name
11
+ private :middle_name=
12
+
13
+ def name=(name)
14
+ self.last_name, self.first_name = name.split(nil, 2).reverse
15
+ end
16
+ end
17
+ end
18
+
19
+ let(:person) { subject.new }
20
+ let(:first_name) { "Chris" }
21
+ let(:last_name) { "Griego" }
22
+
23
+ def should_assign_names_to(person)
24
+ person.first_name.should == first_name
25
+ person.last_name.should == last_name
26
+ end
27
+
28
+ shared_examples_for "a mass assigning method" do
29
+ it "does not raise when assigning nil attributes" do
30
+ expect { mass_assign_attributes nil }.not_to raise_error
31
+ end
32
+
33
+ it "assigns all valid attributes when passed as a hash with string keys" do
34
+ should_assign_names_to mass_assign_attributes('first_name' => first_name, 'last_name' => last_name)
35
+ end
36
+
37
+ it "assigns all valid attributes when passed as a hash with symbol keys" do
38
+ should_assign_names_to mass_assign_attributes(:first_name => first_name, :last_name => last_name)
39
+ end
40
+
41
+ it "uses any available writer methods" do
42
+ should_assign_names_to mass_assign_attributes(:name => "#{first_name} #{last_name}")
43
+ end
44
+
45
+ it "ignores attributes which do not have a writer" do
46
+ person = mass_assign_attributes(:middle_initial => "J")
47
+ person.instance_variable_get("@middle_initial").should be_nil
48
+ person.should_not respond_to :middle_initial
49
+ end
50
+
51
+ it "ignores trying to assign a private attribute" do
52
+ person = mass_assign_attributes(:middle_name => "J")
53
+ person.middle_name.should be_nil
54
+ end
55
+ end
56
+
57
+ describe "#initialize" do
58
+ it "raises ArgumentError when called with three arguments" do
59
+ expect { subject.new({}, {}, nil) }.to raise_error ArgumentError
60
+ end
61
+
62
+ it "does not raise when called with two arguments" do
63
+ expect { subject.new({}, {}) }.not_to raise_error
64
+ end
65
+
66
+ it "does not raise when called with a single argument" do
67
+ expect { subject.new({}) }.not_to raise_error
68
+ end
69
+
70
+ it "does not raise when called with no arguments" do
71
+ expect { subject.new }.not_to raise_error
72
+ end
73
+
74
+ def mass_assign_attributes(attributes)
75
+ subject.new(attributes)
76
+ end
77
+
78
+ it_should_behave_like "a mass assigning method"
79
+ end
80
+
81
+ describe "#attributes=" do
82
+ it "raises ArgumentError when called with two arguments" do
83
+ expect { person.send(:attributes=, {}, {}) }.to raise_error ArgumentError
84
+ end
85
+
86
+ def mass_assign_attributes(attributes)
87
+ person.attributes = attributes
88
+ person
89
+ end
90
+
91
+ it_should_behave_like "a mass assigning method"
92
+ end
93
+
94
+ describe "#assign_attributes" do
95
+ it "raises ArgumentError when called with three arguments" do
96
+ expect { subject.new.assign_attributes({}, {}, nil) }.to raise_error ArgumentError
97
+ end
98
+
99
+ it "does not raise when called with two arguments" do
100
+ expect { subject.new.assign_attributes({}, {}) }.not_to raise_error
101
+ end
102
+
103
+ it "does not raise when called with a single argument" do
104
+ expect { subject.new.assign_attributes({}) }.not_to raise_error
105
+ end
106
+
107
+ it "raises ArgumentError when called with no arguments" do
108
+ expect { subject.new.assign_attributes }.to raise_error ArgumentError
109
+ end
110
+
111
+ def mass_assign_attributes(attributes)
112
+ person.assign_attributes attributes
113
+ person
114
+ end
115
+
116
+ it_should_behave_like "a mass assigning method"
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,10 @@
1
+ require "bundler/setup"
2
+ require "rspec/autorun"
3
+
4
+ # Requires supporting files with custom matchers and macros, etc,
5
+ # in ./support/ and its subdirectories.
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_framework = :rspec
10
+ end
@@ -0,0 +1,15 @@
1
+ require "active_model/lint"
2
+ require "test/unit/assertions"
3
+
4
+ shared_examples_for "ActiveModel" do
5
+ include ActiveModel::Lint::Tests
6
+ include Test::Unit::Assertions
7
+
8
+ before { @model = subject }
9
+
10
+ ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/).each do |test|
11
+ example test.gsub('_',' ') do
12
+ send test
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_attr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Griego
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-30 00:00:00.000000000 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activemodel
17
+ requirement: &70301304935460 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '3.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70301304935460
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &70301304934380 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70301304934380
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &70301304933700 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '1.0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70301304933700
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: &70301304932520 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 0.9.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70301304932520
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ requirement: &70301304931300 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '2.6'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70301304931300
70
+ description: Create plain old ruby models without reinventing the wheel.
71
+ email:
72
+ - cgriego@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - .rvmrc
80
+ - .travis.yml
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - Guardfile
84
+ - MIT-LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - active_attr.gemspec
88
+ - lib/active_attr.rb
89
+ - lib/active_attr/mass_assignment.rb
90
+ - lib/active_attr/version.rb
91
+ - spec/active_attr/mass_assignment_spec.rb
92
+ - spec/spec_helper.rb
93
+ - spec/support/active_model_lint.rb
94
+ has_rdoc: true
95
+ homepage: https://github.com/cgriego/active_attr
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ segments:
108
+ - 0
109
+ hash: -2511944466975604265
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ segments:
117
+ - 0
118
+ hash: -2511944466975604265
119
+ requirements: []
120
+ rubyforge_project: active_attr
121
+ rubygems_version: 1.5.2
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: What ActiveModel left out
125
+ test_files:
126
+ - spec/active_attr/mass_assignment_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/support/active_model_lint.rb