has_magic_fields 0.0.1 → 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.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/Gemfile +2 -1
- data/README.md +9 -8
- data/Rakefile +6 -6
- data/lib/has_magic_fields/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31bc757d95225e509a6013dc6b53f782b6699d34
|
4
|
+
data.tar.gz: 723cf257a31047170f431c91e4bbf2caeb927ec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a15a87a56202a8a068f069639528abe982964dea3b385f4cffafbc884345042a5e7033529c4cc0e5b09e7f60c48a17a8c743105d33241297124b8afdcc8f225
|
7
|
+
data.tar.gz: e3f5cbad80d4192ab97860574178492cb988c926e7670c31b4b28c79389c16df9938d120bde08f9741a03d71a7255a93279942e6c70310008697f07a30087240
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# HasMagicFields
|
2
2
|
[](http://badge.fury.io/rb/has_magic_fields)
|
3
|
+
[](https://travis-ci.org/ikeqiao/has_magic_fields)
|
3
4
|
|
4
5
|
Allows the addition of custom "magic" fields and attributes on a per-model
|
5
6
|
or per-parent-model basis. This is useful for situations where custom fields are
|
@@ -41,15 +42,15 @@ Add magic fields to your model:
|
|
41
42
|
|
42
43
|
```ruby
|
43
44
|
@charlie = Person.create(:email => "charlie@example.com")
|
44
|
-
@charlie.
|
45
|
+
@charlie.create_magic_field(:name => "first_name")
|
45
46
|
```
|
46
47
|
|
47
48
|
Supply additional options if you have more specific requirements for your fields:
|
48
49
|
|
49
50
|
```ruby
|
50
|
-
@charlie.
|
51
|
-
@charlie.
|
52
|
-
@charlie.
|
51
|
+
@charlie.create_magic_field(:name => "last_name", :is_required => true)
|
52
|
+
@charlie.create_magic_field(:name => "birthday", :datatype => :date)
|
53
|
+
@charlie.create_magic_field(:name => "salary", :default => "40000", :pretty_name => "Yearly Salary")
|
53
54
|
```
|
54
55
|
|
55
56
|
The `:datatype` option supports: `:check_box_boolean`, `:date`, `:datetime`, `:integer`
|
@@ -107,14 +108,14 @@ To see all the magic fields available for a type_scoped(User) child from its par
|
|
107
108
|
To add magic fields, go through the parent or child:
|
108
109
|
|
109
110
|
```ruby
|
110
|
-
@alice.
|
111
|
-
@account.
|
111
|
+
@alice.create_magic_field(...)
|
112
|
+
@account.create_magic_field(…,:type_scoped => "User")
|
112
113
|
```
|
113
114
|
|
114
115
|
All User children for a given parent will have access to the same magic fields:
|
115
116
|
|
116
117
|
```ruby
|
117
|
-
@alice.
|
118
|
+
@alice.create_magic_field(:name => "salary")
|
118
119
|
@alice.salary = "40000"
|
119
120
|
|
120
121
|
@bob = User.create(:name => "bob", :account => @account)
|
@@ -140,7 +141,7 @@ end
|
|
140
141
|
|
141
142
|
parent @account also haven't salary magic field
|
142
143
|
|
143
|
-
##
|
144
|
+
## Get All Magic Fields
|
144
145
|
```ruby
|
145
146
|
@account.magic_fields #get all meagic_fields both self and children
|
146
147
|
@account.magic_fields_with_scoped #get all meagic_fields self
|
data/Rakefile
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_magic_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ikeqiao
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
63
|
- .rspec
|
64
|
+
- .travis.yml
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|