Sha256: 41aa800969a0c701bf3c54b471508dcd1fbaa8929fe5dccabded1454a5b3c4af

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

require "roar/representer/feature/http_verbs"

module Roar
  # Automatically add accessors for properties and collections. Also mixes in HttpVerbs.
  module Representer
    module Feature
      module Client
        include HttpVerbs

        def self.extended(base)
          base.instance_eval do
            representable_attrs.each do |attr|
              next unless attr.instance_of? Representable::Definition # ignore hyperlinks etc for now.
              name = attr.name

              # TODO: could anyone please make this better?
              instance_eval %Q{
                def #{name}=(v)
                  @#{name} = v
                end

                def #{name}
                  @#{name}
                end
              }
            end
          end
        end

        # DISCUSS: should we just override #serialize here? otherwise if you later include Hypermedia, it'll run before that method.
        def before_serialize(options={})
          options[:links] ||= false

          super(options)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
roar-0.12.9 lib/roar/representer/feature/client.rb
roar-0.12.8 lib/roar/representer/feature/client.rb
roar-0.12.7 lib/roar/representer/feature/client.rb
roar-0.12.6 lib/roar/representer/feature/client.rb
roar-0.12.5 lib/roar/representer/feature/client.rb
roar-0.12.4 lib/roar/representer/feature/client.rb
roar-0.12.3 lib/roar/representer/feature/client.rb
roar-0.12.2 lib/roar/representer/feature/client.rb
roar-0.12.1 lib/roar/representer/feature/client.rb