defaults 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc734e69238d4fda99df26e36a733e7de84045f0
4
+ data.tar.gz: 533d486e9367b67eb614bdd128c9ca078a0c5c60
5
+ SHA512:
6
+ metadata.gz: 7ffda37edf3c7f3524b5176bc5dea771fc417032e6fd5a68b4758fdcef5adb290b172ff16d7dd4a18847025c143e09353b0b597fb624c4918e904248ad5c0bdd
7
+ data.tar.gz: ca9666b46363045ab7f43232ea3aeea29547b0f2624771e05a069d34eb0b0c8ca0256bcdc61586e00f229178efa850efac092ec96e09b74868e54ce0e036bc16
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  pkg
2
2
  .DS_Store
3
+ *.lock
data/.rspec CHANGED
@@ -1 +1 @@
1
- --format documentation --color
1
+ --color
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ script: bundle exec rspec
3
+ sudo: false
4
+ cache: bundler
5
+ addons:
6
+ code_climate:
7
+ repo_token:
8
+ secure: "aViiP4wSO11Sq/7aXMeoo4ksDj3/wPs3do+cP79jSFiF/ZyBnETWOG4BQoO+UWT1IctnlEN/jrAceZZ9VTbxrtkPbJriO4X8AZDweOq4TOvrRa+6jPfuAqh5QZeSbXucrTU54DWCyPDu404bIz+9yh1vFMBtstKQF1mx4MJVXY4="
9
+ rvm:
10
+ - '2.0'
11
+ - '2.1'
12
+ - '2.2'
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -1,36 +1,48 @@
1
- = Defaults
1
+ # Defaults
2
2
 
3
- == Instalation
3
+ [![Build Status](https://travis-ci.org/fnando/defaults.svg)](https://travis-ci.org/fnando/defaults)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/defaults/badges/gpa.svg)](https://codeclimate.com/github/fnando/defaults)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/defaults/badges/coverage.svg)](https://codeclimate.com/github/fnando/defaults)
4
6
 
5
- Just run <tt>gem install defaults</tt>
7
+ ## Instalation
6
8
 
7
- == Usage
9
+ Just run `gem install defaults`.
8
10
 
9
- Add the method call +defaults+ to your model.
11
+ ## Usage
10
12
 
11
- class Page < ActiveRecord::Base
12
- defaults :title => "New page", :body => "Put your text here"
13
- end
13
+ Add the method call `defaults` to your model.
14
+
15
+ ```ruby
16
+ class Page < ActiveRecord::Base
17
+ defaults title: "New page", body: "Put your text here"
18
+ end
19
+ ```
14
20
 
15
21
  Attributes will be set only if it's a new record and the attribute is blank.
16
22
 
17
- Retrieve the default attribute with the +default_for+ instance method:
23
+ Retrieve the default attribute with the `default_for` instance method:
18
24
 
19
- @page.default_for(:title)
25
+ ```ruby
26
+ @page.default_for(:title)
27
+ ```
20
28
 
21
29
  You can pass Proc as attribute:
22
30
 
23
- defaults :expires_at => proc { Time.now }
31
+ ```ruby
32
+ defaults expires_at: proc { Time.now }
33
+ ```
24
34
 
25
35
  You can override the default attributes as follow:
26
36
 
27
- Page.default_options = {:title => "Here's your new page", :body => "Write your page text"}
37
+ ```ruby
38
+ Page.default_options = {title: "Here's your new page", body: "Write your page text"}
39
+ ```
28
40
 
29
- == Maintainer
41
+ ## Maintainer
30
42
 
31
43
  * Nando Vieira - http://simplesideias.com.br
32
44
 
33
- == License
45
+ ## License
34
46
 
35
47
  (The MIT License)
36
48
 
@@ -51,4 +63,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
63
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
64
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
65
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,4 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "defaults/version"
1
+ require "./lib/defaults/version"
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = "defaults"
@@ -17,8 +15,8 @@ Gem::Specification.new do |s|
17
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
16
  s.require_paths = ["lib"]
19
17
 
20
- s.add_development_dependency "activerecord", "~> 3.0.0"
18
+ s.add_development_dependency "activerecord", ">= 3.0.0"
21
19
  s.add_development_dependency "sqlite3-ruby"
22
- s.add_development_dependency "rspec", "~> 2.5.0"
23
- s.add_development_dependency "ruby-debug19" if RUBY_VERSION >= "1.9"
20
+ s.add_development_dependency "rspec"
21
+ s.add_development_dependency "codeclimate-test-reporter"
24
22
  end
@@ -47,10 +47,4 @@ module Defaults
47
47
  end
48
48
  end
49
49
 
50
- # ActiveRecord only calls after_initialize callbacks only if is
51
- # explicit defined in a class.
52
- if ActiveRecord::VERSION::STRING < "3.0"
53
- class ActiveRecord::Base; def after_initialize; end; end
54
- end
55
-
56
50
  ActiveRecord::Base.send(:include, Defaults)
@@ -1,8 +1,8 @@
1
1
  module Defaults
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 1
5
- PATCH = 1
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -26,27 +26,27 @@ describe Defaults do
26
26
  end
27
27
 
28
28
  it "sets default values" do
29
- @new_donut.flavor.should == "cream"
30
- @new_donut.name.should == "Cream"
31
- @new_donut.maker.should == "Dunkin Donuts"
32
- @new_donut.class_name.should == "Donut"
33
- @new_donut.quantity.should == 5
29
+ expect(@new_donut.flavor).to eq("cream")
30
+ expect(@new_donut.name).to eq("Cream")
31
+ expect(@new_donut.maker).to eq("Dunkin Donuts")
32
+ expect(@new_donut.class_name).to eq("Donut")
33
+ expect(@new_donut.quantity).to eq(5)
34
34
  end
35
35
 
36
36
  it "sets default values only when have blank attributes" do
37
- @donut.flavor.should == "vanilla"
38
- @donut.quantity.should == 5
37
+ expect(@donut.flavor).to eq("vanilla")
38
+ expect(@donut.quantity).to eq(5)
39
39
  end
40
40
 
41
41
  it "returns default value for an attribute" do
42
- @donut.default_for(:flavor).should == "cream"
43
- @donut.default_for(:maker).should == "Dunkin Donuts"
44
- @donut.default_for(:class_name).should == "Donut"
45
- @donut.default_for(:quantity).should == 5
42
+ expect(@donut.default_for(:flavor)).to eq("cream")
43
+ expect(@donut.default_for(:maker)).to eq("Dunkin Donuts")
44
+ expect(@donut.default_for(:class_name)).to eq("Donut")
45
+ expect(@donut.default_for(:quantity)).to eq(5)
46
46
  end
47
47
 
48
48
  it "does not set default values" do
49
- Donut.first.flavor.should == "vanilla"
49
+ expect(Donut.first.flavor).to eq("vanilla")
50
50
  end
51
51
 
52
52
  private
@@ -1,6 +1,6 @@
1
1
  ActiveRecord::Schema.define(:version => 0) do
2
2
  create_table :donuts do |t|
3
3
  t.string :flavor, :name, :maker
4
- t.integer :quantity, :default => 0, :null => false
4
+ t.integer :quantity, :null => false
5
5
  end
6
6
  end
@@ -1,7 +1,9 @@
1
- # encoding: utf-8
2
- require "rspec"
3
- require "active_record"
4
- require "defaults"
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'bundler/setup'
5
+ require 'active_record'
6
+ require 'defaults'
5
7
 
6
8
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
7
9
  load File.dirname(__FILE__) + "/schema.rb"
metadata CHANGED
@@ -1,77 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: defaults
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Nando Vieira
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-04-04 00:00:00 -03:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
17
14
  name: activerecord
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
22
- - - ~>
23
- - !ruby/object:Gem::Version
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
24
19
  version: 3.0.0
25
20
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: sqlite3-ruby
29
21
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
33
24
  - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
36
34
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: rspec
40
35
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ~>
45
- - !ruby/object:Gem::Version
46
- version: 2.5.0
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
47
48
  type: :development
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: ruby-debug19
51
49
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
55
52
  - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
58
62
  type: :development
59
- version_requirements: *id004
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
60
69
  description: Set default values for ActiveRecord attributes
61
- email:
70
+ email:
62
71
  - fnando.vieira@gmail.com
63
72
  executables: []
64
-
65
73
  extensions: []
66
-
67
74
  extra_rdoc_files: []
68
-
69
- files:
70
- - .gitignore
71
- - .rspec
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
72
79
  - Gemfile
73
- - Gemfile.lock
74
- - README.rdoc
80
+ - README.md
75
81
  - Rakefile
76
82
  - defaults.gemspec
77
83
  - lib/defaults.rb
@@ -79,35 +85,30 @@ files:
79
85
  - spec/defaults_spec.rb
80
86
  - spec/schema.rb
81
87
  - spec/spec_helper.rb
82
- has_rdoc: true
83
88
  homepage: http://rubygems.org/gems/defaults
84
89
  licenses: []
85
-
90
+ metadata: {}
86
91
  post_install_message:
87
92
  rdoc_options: []
88
-
89
- require_paths:
93
+ require_paths:
90
94
  - lib
91
- required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
- requirements:
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
94
97
  - - ">="
95
- - !ruby/object:Gem::Version
96
- version: "0"
97
- required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
100
102
  - - ">="
101
- - !ruby/object:Gem::Version
102
- version: "0"
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
103
105
  requirements: []
104
-
105
106
  rubyforge_project:
106
- rubygems_version: 1.6.0
107
+ rubygems_version: 2.4.6
107
108
  signing_key:
108
- specification_version: 3
109
+ specification_version: 4
109
110
  summary: Set default values for ActiveRecord attributes
110
- test_files:
111
+ test_files:
111
112
  - spec/defaults_spec.rb
112
113
  - spec/schema.rb
113
114
  - spec/spec_helper.rb
@@ -1,58 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- defaults (0.1.1)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- activemodel (3.0.5)
10
- activesupport (= 3.0.5)
11
- builder (~> 2.1.2)
12
- i18n (~> 0.4)
13
- activerecord (3.0.5)
14
- activemodel (= 3.0.5)
15
- activesupport (= 3.0.5)
16
- arel (~> 2.0.2)
17
- tzinfo (~> 0.3.23)
18
- activesupport (3.0.5)
19
- archive-tar-minitar (0.5.2)
20
- arel (2.0.9)
21
- builder (2.1.2)
22
- columnize (0.3.2)
23
- diff-lcs (1.1.2)
24
- i18n (0.5.0)
25
- linecache19 (0.5.12)
26
- ruby_core_source (>= 0.1.4)
27
- rspec (2.5.0)
28
- rspec-core (~> 2.5.0)
29
- rspec-expectations (~> 2.5.0)
30
- rspec-mocks (~> 2.5.0)
31
- rspec-core (2.5.1)
32
- rspec-expectations (2.5.0)
33
- diff-lcs (~> 1.1.2)
34
- rspec-mocks (2.5.0)
35
- ruby-debug-base19 (0.11.25)
36
- columnize (>= 0.3.1)
37
- linecache19 (>= 0.5.11)
38
- ruby_core_source (>= 0.1.4)
39
- ruby-debug19 (0.11.6)
40
- columnize (>= 0.3.1)
41
- linecache19 (>= 0.5.11)
42
- ruby-debug-base19 (>= 0.11.19)
43
- ruby_core_source (0.1.5)
44
- archive-tar-minitar (>= 0.5.2)
45
- sqlite3 (1.3.3)
46
- sqlite3-ruby (1.3.3)
47
- sqlite3 (>= 1.3.3)
48
- tzinfo (0.3.26)
49
-
50
- PLATFORMS
51
- ruby
52
-
53
- DEPENDENCIES
54
- activerecord (~> 3.0.0)
55
- defaults!
56
- rspec (~> 2.5.0)
57
- ruby-debug19
58
- sqlite3-ruby