Class: Roar::Rails::Formats

Inherits:
Hash
  • Object
show all
Defined in:
lib/roar/rails/formats.rb

Defined Under Namespace

Classes: Path

Instance Method Summary collapse

Instance Method Details

#add(format, opts) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/roar/rails/formats.rb', line 3

def add(format, opts)
  # FIXME: use controller_path here as well!
  # by pre-computing the representer name we allow "one-step inheritance": if B doesn't call ::represents it "inherits" A's settings.
  unless opts.is_a?(Hash)
    model_name = opts.name.underscore
    opts = {
      :entity     => add_representer_suffix(model_name),
      :collection => add_representer_suffix(model_name.pluralize)
    }
  end

  self[format] = opts
end

#for(*args) ⇒ Object



17
18
19
20
21
22
# File 'lib/roar/rails/formats.rb', line 17

def for(*args)
  name = name_for(*args) or return

  return name if name.is_a?(Module) # i hate is_a? but this is really handy here.
  name.camelize.constantize
end