Sha256: 4ffc856079c88990a10fa0d4fa4bf1c54954e4efd8e2678ba2bb85fd029b3c60

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

module Extface
  class Mapping
    attr_reader :name, :i_klass, :i_param, :i_find_key, :i_extra_module
    def initialize(resource, options)
      @name = options[:as] || resource.to_s
      
      @i_klass = (options[:interfaceable_type] || name.to_s.classify).to_s.constantize
      
      @i_param = options[:interfaceable_param] || "#{name}_id" #default #{resource}_id

      # key to find interfaceable in controller, when
      # :uuid then find_by! :uuid => params[:uuid]
      # :shop_uuid then find_by! :uuid => params[:shop_uuid]
      # :shop_id then find_by! :id => params[:shop_id]
      @i_find_key = @i_param[/^(#{@name}_|)(\w+)/,2]
      raise "#{@i_klass.name} has no method #{@i_find_key}" unless @i_klass.new.respond_to? @i_find_key
      raise "Did you forget to add 'has_extface_devices' in #{@i_klass.name} ?" unless @i_klass.new.respond_to? :extface_devices
      @i_extra_module = options[:controller_include].to_s.constantize if options[:controller_include].present?
    end
    
    def mount_point
      "#{name}_extface"
    end
    
    class << self
      def find(fullpath)
        Extface.mappings[fullpath[%r{/(\w+)_extface\/}, 1]]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
extface-0.1.0 lib/extface/mapping.rb
extface-0.0.8 lib/extface/mapping.rb
extface-0.0.7 lib/extface/mapping.rb
extface-0.0.6 lib/extface/mapping.rb
extface-0.0.5 lib/extface/mapping.rb
extface-0.0.3 lib/extface/mapping.rb
extface-0.0.2 lib/extface/mapping.rb
extface-0.0.1 lib/extface/mapping.rb