dynamo 0.0.1
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.
- data/LICENSE +22 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/lib/dynamo.rb +5 -0
- data/lib/dynamo/dynamic_fields.rb +74 -0
- data/lib/dynamo/version.rb +3 -0
- metadata +54 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jeff Felchner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/dynamo.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# TODO: We need to generalize the logic here such that we can pass in the necessary
|
2
|
+
# information to DynamicFields.dynamic_fields and have all of the other functionality
|
3
|
+
# behave properly.
|
4
|
+
#
|
5
|
+
# The `fields` call should not be hard coded, etc
|
6
|
+
#
|
7
|
+
module DynamicFields
|
8
|
+
FIELD_NAME_PATTERN = /(.+)_field(=)?$/
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def dynamic_fields(field_name)
|
12
|
+
self.class_eval do
|
13
|
+
serialize field_name, Array
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.extend ClassMethods
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate_dynamic_fields
|
23
|
+
self.fields.each do |field|
|
24
|
+
self.errors.add(:fields, field.errors) unless field.valid?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def field_errors
|
29
|
+
self.fields.each_with_object({}) do |f, h|
|
30
|
+
h.merge! f.field_errors
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def fields_metadata=(fields_metadata)
|
35
|
+
self.fields = []
|
36
|
+
|
37
|
+
fields_metadata.each do |field_metadata|
|
38
|
+
self.fields << CustomFieldValue.new(:metadata => field_metadata)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def respond_to_missing?(sym, include_private = false)
|
43
|
+
return super unless sym.match FIELD_NAME_PATTERN
|
44
|
+
|
45
|
+
field_name = $1
|
46
|
+
|
47
|
+
self.fields.find {|f| f.metadata.underscored_name == field_name}.present?
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing(sym, *args, &block)
|
51
|
+
return super unless sym.match FIELD_NAME_PATTERN
|
52
|
+
|
53
|
+
field_name = $1
|
54
|
+
is_setter = $2.present?
|
55
|
+
field = self.fields.find {|f| f.metadata.underscored_name == field_name} || CustomFieldValue.new
|
56
|
+
|
57
|
+
if is_setter
|
58
|
+
field.value = args.first
|
59
|
+
else
|
60
|
+
field.value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def attributes=(attrs)
|
65
|
+
field_attributes = attrs.delete('fields') {{}}
|
66
|
+
|
67
|
+
fields.each do |field|
|
68
|
+
field.set_value_from_attributes field_attributes
|
69
|
+
fields_will_change! if field.changed?
|
70
|
+
end
|
71
|
+
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dynamo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jfelchner
|
9
|
+
- m5rk
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-10-02 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: ''
|
16
|
+
email: support@chirrpy.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- LICENSE
|
22
|
+
files:
|
23
|
+
- lib/dynamo/dynamic_fields.rb
|
24
|
+
- lib/dynamo/version.rb
|
25
|
+
- lib/dynamo.rb
|
26
|
+
- Rakefile
|
27
|
+
- README.md
|
28
|
+
- LICENSE
|
29
|
+
homepage: https://github.com/chirrpy/dynamo
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options:
|
33
|
+
- --charset = UTF-8
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project: dynamo
|
50
|
+
rubygems_version: 1.8.24
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Ben Richards may be running, but he won't run far... from DYNAMO!
|
54
|
+
test_files: []
|