ohm-default 0.0.1

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: 0fc1f5002fa249ae0290807ff85b6475ecdaa8b3
4
+ data.tar.gz: 43c9a4666f714cc2a5423d8044146ac8f4df511a
5
+ SHA512:
6
+ metadata.gz: 89569a0d155e95f47be6fbaa1898a90f3415833879f006810245708ab8010b18b6b0a0d609726222335f54d54a556085b7454c20a880a51c201bf8261f861921
7
+ data.tar.gz: 3d3dddac3363a2a352ea25ba3675216e33eed4de089150d424a08c368d7632dd3644d6a90650844ed25b2753e0a706e2923de15d78302488a546c9a9116fc2c0
@@ -0,0 +1,17 @@
1
+ # Ohm::Default
2
+
3
+ Adds the ability to set default values to an Ohm Model
4
+
5
+ ```bash
6
+ gem install ohm-default
7
+ ```
8
+
9
+ ```ruby
10
+ class Model < Ohm::Model
11
+ include Ohm::Default
12
+
13
+ attribute :name
14
+
15
+ default :name, "Wolfgang"
16
+ end
17
+ ```
@@ -0,0 +1,8 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new("test") do |t|
4
+ t.libs << "test"
5
+ t.pattern = "test/**/*_test.rb"
6
+ end
7
+
8
+ task :default => [:test]
@@ -0,0 +1,23 @@
1
+ module Ohm::Default
2
+ def self.included(model)
3
+ model.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ def default_attributes
8
+ @default_attributes ||= {}
9
+ end
10
+
11
+ def default(name, value)
12
+ default_attributes[name] = value if attributes.include?(name)
13
+ end
14
+ end
15
+
16
+ def save
17
+ self.class.default_attributes.each do |k,v|
18
+ self.send("#{k}=", v) if !self.send(k)
19
+ end
20
+
21
+ super
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ohm-default"
3
+ s.version = "0.0.1"
4
+ s.summary = "Default values for Ohm"
5
+ s.description = "Allows the set of default values for Ohm"
6
+ s.authors = ["elcuervo"]
7
+ s.licenses = ["MIT", "HUGWARE"]
8
+ s.email = ["yo@brunoaguirre.com"]
9
+ s.homepage = "http://github.com/elcuervo/ohm-default"
10
+ s.files = `git ls-files`.split("\n")
11
+ s.test_files = `git ls-files test`.split("\n")
12
+
13
+ s.add_dependency("ohm", "~> 2.0.1")
14
+ s.add_development_dependency("cutest", "~> 1.2.1")
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'cutest'
2
+ require 'ohm'
3
+ require 'ohm/default'
4
+
5
+ prepare { Ohm.flush }
6
+
7
+ class Model < Ohm::Model
8
+ include Ohm::Default
9
+
10
+ attribute :a
11
+ attribute :b
12
+
13
+ default :a, "A"
14
+ end
15
+
16
+ test "sets a default value" do
17
+ m = Model.create
18
+
19
+ assert_equal m.a, "A"
20
+ assert_equal m.b, nil
21
+ end
22
+
23
+ test "can overwrite default" do
24
+ m = Model.create a: "Relax", b: "Always"
25
+
26
+ assert_equal m.a, "Relax"
27
+ assert_equal m.b, "Always"
28
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohm-default
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - elcuervo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ohm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: cutest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.1
41
+ description: Allows the set of default values for Ohm
42
+ email:
43
+ - yo@brunoaguirre.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - Rakefile
50
+ - lib/ohm/default.rb
51
+ - ohm-default.gemspec
52
+ - test/ohm_default_test.rb
53
+ homepage: http://github.com/elcuervo/ohm-default
54
+ licenses:
55
+ - MIT
56
+ - HUGWARE
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.0.14
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Default values for Ohm
78
+ test_files:
79
+ - test/ohm_default_test.rb
80
+ has_rdoc: