laserlemon-dry_serial 0.1.0 → 0.1.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/VERSION +1 -1
- data/dry_serial.gemspec +3 -4
- data/lib/dry_serial.rb +24 -1
- data/lib/serialization.rb +0 -16
- metadata +2 -3
- data/.document +0 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/dry_serial.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dry_serial}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["laserlemon"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-30}
|
13
13
|
s.description = %q{Define serialization styles for your ActiveRecord models}
|
14
14
|
s.email = %q{steve@laserlemon.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,8 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
".
|
21
|
-
".gitignore",
|
20
|
+
".gitignore",
|
22
21
|
"LICENSE",
|
23
22
|
"README.rdoc",
|
24
23
|
"Rakefile",
|
data/lib/dry_serial.rb
CHANGED
@@ -4,19 +4,24 @@ module LaserLemon
|
|
4
4
|
module DrySerial
|
5
5
|
def self.included(base)
|
6
6
|
base.class_eval do
|
7
|
+
extend ClassMethods
|
8
|
+
|
7
9
|
class_inheritable_hash :serialization_options
|
8
10
|
self.serialization_options = {}
|
9
11
|
|
10
12
|
class_inheritable_accessor :default_serialization_style
|
11
13
|
self.default_serialization_style = nil
|
14
|
+
|
15
|
+
alias_method_chain :to_xml, :breakfast
|
16
|
+
alias_method_chain :to_json, :breakfast
|
12
17
|
end
|
13
|
-
base.extend ClassMethods
|
14
18
|
end
|
15
19
|
|
16
20
|
module ClassMethods
|
17
21
|
def dry_serial(*args)
|
18
22
|
options = args.extract_options!
|
19
23
|
style = args.first || :default
|
24
|
+
|
20
25
|
self.serialization_options[style] = options
|
21
26
|
self.default_serialization_style ||= style
|
22
27
|
end
|
@@ -24,6 +29,24 @@ module LaserLemon
|
|
24
29
|
def default_serialization_options
|
25
30
|
self.serialization_options.fetch(self.default_serialization_style, {})
|
26
31
|
end
|
32
|
+
|
33
|
+
def styled_serialization_options(*args)
|
34
|
+
options = args.extract_options!
|
35
|
+
style = args.first || options[:style] || default_serialization_style
|
36
|
+
|
37
|
+
style_options = serialization_options.fetch(style, default_serialization_options)
|
38
|
+
style_options.merge(options).merge(:style => style)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_xml_with_breakfast(*args, &block)
|
43
|
+
options = self.class.styled_serialization_options(*args)
|
44
|
+
to_xml_without_breakfast(options, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_json_with_breakfast(*args)
|
48
|
+
options = self.class.styled_serialization_options(*args)
|
49
|
+
to_json_without_breakfast(options)
|
27
50
|
end
|
28
51
|
end
|
29
52
|
end
|
data/lib/serialization.rb
CHANGED
@@ -2,26 +2,10 @@ module LaserLemon
|
|
2
2
|
module DrySerial
|
3
3
|
module Serializer
|
4
4
|
def self.included(base)
|
5
|
-
base.alias_method_chain :initialize, :breakfast
|
6
5
|
base.alias_method_chain :add_includes, :breakfast
|
7
6
|
base.alias_method_chain :serializable_names, :breakfast
|
8
7
|
end
|
9
8
|
|
10
|
-
def initialize_with_breakfast(record, options = nil)
|
11
|
-
default_options = record.class.default_serialization_options
|
12
|
-
|
13
|
-
new_options = case options
|
14
|
-
when Hash
|
15
|
-
options.reverse_merge!(:style => record.class.default_serialization_style)
|
16
|
-
style_options = record.class.serialization_options.fetch(options[:style], default_options)
|
17
|
-
options.reverse_merge(style_options)
|
18
|
-
else
|
19
|
-
record.class.serialization_options.fetch(options, default_options).merge(:style => options)
|
20
|
-
end
|
21
|
-
|
22
|
-
initialize_without_breakfast(record, new_options)
|
23
|
-
end
|
24
|
-
|
25
9
|
def add_includes_with_breakfast(&block)
|
26
10
|
if include_associations = options.delete(:include)
|
27
11
|
include_has_options = include_associations.is_a?(Hash)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: laserlemon-dry_serial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- laserlemon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,7 +42,6 @@ extra_rdoc_files:
|
|
42
42
|
- LICENSE
|
43
43
|
- README.rdoc
|
44
44
|
files:
|
45
|
-
- .document
|
46
45
|
- .gitignore
|
47
46
|
- LICENSE
|
48
47
|
- README.rdoc
|