valuable 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +10 -0
- data/README.markdown +2 -0
- data/docs/validations.markdown +60 -0
- data/lib/valuable/utils.rb +2 -4
- data/valuable.version +1 -1
- metadata +10 -11
- data/todo.txt +0 -84
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b73106fa82246539ba8267f4fe67f37fa852bcc
|
4
|
+
data.tar.gz: e3129d8e0e5cb8598724a8b3e9d0e8b03e75a120
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca0da48eac6c68d6eab0c89810912326dff0dad697ed7dd60ded222b36ce3ea877a22e71d9319f2685879af3136ed695b702a234a693dbdf73fbf448654f2b37
|
7
|
+
data.tar.gz: 1a273f03d269426b36ce6d889c19126b5cdcd1c224370404dadae8340d2c4004fa8155014500d57be3f2f552c810cb066db01684eeedebedca801f240f733dcd
|
data/LICENSE
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Copyright (c) 2009 Johnathon Wright
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
|
+
|
data/README.markdown
CHANGED
@@ -33,6 +33,8 @@ Contents
|
|
33
33
|
- [Advanced Input Parsing](#advanced-input-parsing)
|
34
34
|
- [Advanced Defaults](#advanced-defaults)
|
35
35
|
- [Advanced Collection Formatting](#advanced-collection-formatting)
|
36
|
+
- Other Examples
|
37
|
+
- [Validations](/docs/validations.markdown)
|
36
38
|
|
37
39
|
Frequent Uses
|
38
40
|
=============
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Validations via ActiveModel::Validations
|
2
|
+
========================================
|
3
|
+
|
4
|
+
Valuable doesn't support validations because other people are already doing that well. Here are examples of using the ActiveModel gem for validations:
|
5
|
+
|
6
|
+
class Entity < Valuable
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
has_value :name
|
10
|
+
has_value :avatar
|
11
|
+
|
12
|
+
validates_presence_of :name
|
13
|
+
validates_presence_of :avatar
|
14
|
+
end
|
15
|
+
|
16
|
+
>> entity = Entity.new(:name => 'Crystaline Entity')
|
17
|
+
|
18
|
+
>> entity.valid?
|
19
|
+
=> false
|
20
|
+
|
21
|
+
>> entity.errors.full_messages
|
22
|
+
=> ["Avatar can't be blank"]
|
23
|
+
|
24
|
+
Example using validators
|
25
|
+
------------------------
|
26
|
+
|
27
|
+
less talk; more code:
|
28
|
+
|
29
|
+
class BorgValidator < ActiveModel::Validator
|
30
|
+
def validate( entity )
|
31
|
+
if( entity.name.to_s == "" )
|
32
|
+
entity.errors[:name] << 'is blank and will be assimilated.'
|
33
|
+
elsif( entity.name !~ /(\d+) of (\d+)/ )
|
34
|
+
entity.errors[:name] << 'does not conform and will be assimilated.'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Entity < Valuable
|
40
|
+
include ActiveModel::Validations
|
41
|
+
validates_with BorgValidator
|
42
|
+
|
43
|
+
has_value :name
|
44
|
+
|
45
|
+
validates_presence_of :name
|
46
|
+
end
|
47
|
+
|
48
|
+
>> hugh = Entity.new(:name => 'Hugh')
|
49
|
+
|
50
|
+
>> hugh.valid?
|
51
|
+
=> false
|
52
|
+
|
53
|
+
>> hugh.errors.full_messages
|
54
|
+
=> ["Name does not conform and will be assimilated"]
|
55
|
+
|
56
|
+
>> high = Entity.new(:name => '3 of 7')
|
57
|
+
|
58
|
+
>> hugh.valid?
|
59
|
+
=> true
|
60
|
+
|
data/lib/valuable/utils.rb
CHANGED
@@ -49,10 +49,8 @@ module Valuable::Utils
|
|
49
49
|
end
|
50
50
|
|
51
51
|
when :collection
|
52
|
-
|
53
|
-
|
54
|
-
Valuable::Utils.format( name, item, attributes, true )
|
55
|
-
end
|
52
|
+
value.map do |item|
|
53
|
+
Valuable::Utils.format( name, item, attributes, true )
|
56
54
|
end
|
57
55
|
|
58
56
|
when :date
|
data/valuable.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.9
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valuable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Johnathon Wright
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Valuable is a ruby base class that is essentially attr_accessor on steroids.
|
15
14
|
A simple and intuitive interface allows you to get on with modeling in your app.
|
@@ -18,10 +17,12 @@ executables: []
|
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
|
-
- .gitignore
|
20
|
+
- ".gitignore"
|
22
21
|
- Gemfile
|
22
|
+
- LICENSE
|
23
23
|
- README.markdown
|
24
24
|
- Rakefile
|
25
|
+
- docs/validations.markdown
|
25
26
|
- examples/baseball.rb
|
26
27
|
- examples/person.rb
|
27
28
|
- examples/phone_number.rb
|
@@ -40,33 +41,31 @@ files:
|
|
40
41
|
- test/typical_test.rb
|
41
42
|
- test/valuable_test.rb
|
42
43
|
- test/write_and_read_attribute_test.rb
|
43
|
-
- todo.txt
|
44
44
|
- valuable.gemspec
|
45
45
|
- valuable.version
|
46
46
|
homepage: http://valuable.mustmodify.com/
|
47
47
|
licenses:
|
48
48
|
- MIT
|
49
|
+
metadata: {}
|
49
50
|
post_install_message:
|
50
51
|
rdoc_options: []
|
51
52
|
require_paths:
|
52
53
|
- lib
|
53
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
55
|
requirements:
|
56
|
-
- -
|
56
|
+
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
60
|
requirements:
|
62
|
-
- -
|
61
|
+
- - ">="
|
63
62
|
- !ruby/object:Gem::Version
|
64
63
|
version: '0'
|
65
64
|
requirements: []
|
66
65
|
rubyforge_project:
|
67
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.4.5
|
68
67
|
signing_key:
|
69
|
-
specification_version:
|
68
|
+
specification_version: 4
|
70
69
|
summary: attr_accessor on steroids with defaults, attribute formatting, alias methods,
|
71
70
|
etc.
|
72
71
|
test_files: []
|
data/todo.txt
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
- has_value :start_date, :default => {Date.today}
|
2
|
-
- has_value :price, :default => 50, :extend => MoneyFormatter
|
3
|
-
|
4
|
-
class SomeSearchThing < Valuable
|
5
|
-
|
6
|
-
has_value :dob
|
7
|
-
has_value :sign
|
8
|
-
|
9
|
-
parser_for( dob ) do |input|
|
10
|
-
Date.parse(input)
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
BEST PRACTICES DOC
|
16
|
-
|
17
|
-
When creating a searcher:
|
18
|
-
|
19
|
-
class UserSearcher < Valuable
|
20
|
-
|
21
|
-
has_value :age
|
22
|
-
has_value :query
|
23
|
-
has_value :expertise
|
24
|
-
has_value :eye_color
|
25
|
-
|
26
|
-
def conditions
|
27
|
-
[ eye_color_conditions, name_conditions, ... ].compact.join(' OR ')
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
- Rails 3 support
|
34
|
-
- Add Valuable#to_yaml and Valuable.from_yaml
|
35
|
-
- make it easy to include validatable or ActiveRecord::Validations
|
36
|
-
- make it easy to use has_value from activerecord model.
|
37
|
-
- add optional :always_klass ?
|
38
|
-
- for :klass => :integer, 'abc' resolves to 0 ... fix that.
|
39
|
-
- optionally, values should be on the class rather than the instance, as in:
|
40
|
-
Config < ValuableClass
|
41
|
-
has_value :background_color
|
42
|
-
end
|
43
|
-
|
44
|
-
Config.background_color
|
45
|
-
|
46
|
-
- 2. Create a 'Valuable::Presenter' base class that filters out rails params, handles nested params, knows 0 is false for checkboxes, works with form_for#checkbox...
|
47
|
-
|
48
|
-
class ProductsController < ApplicationController
|
49
|
-
|
50
|
-
def reviews
|
51
|
-
@presenter = ReviewPresenter.new(params)
|
52
|
-
|
53
|
-
@product = @presenter.product
|
54
|
-
@reviews = @presenter.reviews
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
which currently raises:
|
61
|
-
undefined method `action=' for #<ReviewPresenter:0x5e7fa18>
|
62
|
-
|
63
|
-
|
64
|
-
like this:
|
65
|
-
def initialize(atts = {})
|
66
|
-
super(atts.except('action', 'controller'))
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
:klass => :decimal
|
72
|
-
- When is decimal available? Only load then.
|
73
|
-
- If calling :decimal and it hasn't loaded, error
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
class Change < Decimal
|
78
|
-
extend Valuable::whatever or
|
79
|
-
extend Valuable
|
80
|
-
|
81
|
-
...
|
82
|
-
end
|
83
|
-
|
84
|
-
- do a better job with method_missing
|