Sha256: 7de359ee7d0504aeb8b0e55e2d2883369c235d482448876879f9bcdf8f60dd92

Contents?: true

Size: 945 Bytes

Versions: 1

Compression:

Stored size: 945 Bytes

Contents

module Crystal
  class OptionsForController
    attr_reader :controller

    def initialize(controller)
      @controller = controller
    end

    def options
      paths.inject(default_options){|memo, path| memo.deep_merge!(I18n.t(path, :scope => scope, :default => {}))}
    end

    private

    def paths
      %W{
        _defaults
        #{controller_path}._defaults
        #{controller_path}.#{alias_action}
        #{controller_path}.#{action}
      }.uniq
    end

    def scope
      'meta'
    end

    def default_options
      HashWithStringifyKeys.new(:'og:url' => url)
    end

    def url
      controller.request.url
    end

    def controller_path
      @controller_path ||= controller.controller_path.gsub(%r{/}, '.')
    end

    def action
      controller.action_name
    end

    def alias_action
      aliases[action] || action
    end

    def aliases
      {'update' => 'edit', 'create' => 'new'}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crystalmeta-0.9.0 lib/crystal/options_for_controller.rb