Sha256: 0971404f7fd280f6221ca130ac3e5db36fe78c6716c0c361faaed77edadea891

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

module Resources
  class Configuration

    def initialize *args
      options = args.extract_options!
      self.rest_actions = options[:rest_actions] || true
      self.search = options[:search] || false
      self.search_options = options[:search_options] && options[:search_options].is_a?(Hash) ? options[:search_options] : {distinct: false}
      self.params_search = options[:params_search] || :q
      self.params_resource = options[:params_resource] || :resource
      self.params_page = options[:params_page] || :page
      self.pagination = options[:pagination] || false
      self.resource_scope = options[:resource_scope] || nil
      self.resources_scope = options[:resources_scope] || nil
      self.resource_method_name = options[:resource_method_name] || :resource
      self.resources_method_name = options[:resources_method_name] || nil
      if self.resource_method_name && self.resources_method_name.to_s.blank?
        self.resources_method_name = self.resource_method_name.to_s.pluralize
      end
    end


    def to_hash
      hash =HashWithIndifferentAccess.new
      self.class.accessors.each do |m|
        hash[m] = send(m)
      end
      hash
    end

    def self.accessors
      [:rest_actions, :search, :search_options, :params_search, :resource_class_name, :resource_scope, :resources_scope, :resource_method_name, :resources_method_name, :params_resource, :pagination, :params_page]
    end
    accessors.map{|a| attr_accessor a }


  end

  Config = Resources::Configuration.new()

  def self.config(&block)
    yield(Config)
  end


end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resources-0.2.0 lib/resources/configuration.rb
resources-0.1.3 lib/resources/configuration.rb
resources-0.1.2 lib/resources/configuration.rb