Module: RubySerializer::Dsl
- Included in:
- Base
- Defined in:
- lib/ruby_serializer/dsl.rb
Instance Method Summary collapse
- #belongs_to(field, options = {}) ⇒ Object
- #expose(field, options = {}) ⇒ Object
- #fields ⇒ Object
- #has_many(field, options = {}) ⇒ Object
- #has_one(field, options = {}) ⇒ Object
- #namespace(ns = nil, &block) ⇒ Object
-
#serializes(name) ⇒ Object
———————————————————————————————-.
Instance Method Details
#belongs_to(field, options = {}) ⇒ Object
16 17 18 19 |
# File 'lib/ruby_serializer/dsl.rb', line 16 def belongs_to(field, = {}) fields << Field.new("#{field}_id", namespace, ) fields << Association.new(field, namespace, ) end |
#expose(field, options = {}) ⇒ Object
12 13 14 |
# File 'lib/ruby_serializer/dsl.rb', line 12 def expose(field, = {}) fields << Field.new(field, namespace, ) end |
#fields ⇒ Object
37 38 39 |
# File 'lib/ruby_serializer/dsl.rb', line 37 def fields @fields ||= [] end |
#has_many(field, options = {}) ⇒ Object
21 22 23 |
# File 'lib/ruby_serializer/dsl.rb', line 21 def has_many(field, = {}) fields << Association.new(field, namespace, ) end |
#has_one(field, options = {}) ⇒ Object
25 26 27 |
# File 'lib/ruby_serializer/dsl.rb', line 25 def has_one(field, = {}) fields << Association.new(field, namespace, ) end |
#namespace(ns = nil, &block) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/ruby_serializer/dsl.rb', line 29 def namespace(ns = nil, &block) @namespace ||= [] return @namespace if ns.nil? # this method acts as both getter (this line) and setter (subsequent) @namespace.push(ns) block.call(binding) @namespace.pop end |
#serializes(name) ⇒ Object
6 7 8 9 10 |
# File 'lib/ruby_serializer/dsl.rb', line 6 def serializes(name) define_method(name) do # provide a friendly-name accessor to the underlying resource resource end end |