Sha256: b577703ac51dc58e56b3552fcd71d39e71e179170d7b78dfd8fc3a27d027e79c

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Zertico
  class Service
    attr_reader :interface_class, :interface_name, :interface_id

    autoload :ClassMethods, 'zertico/service/class_methods'
    autoload :InstanceMethods, 'zertico/service/instance_methods'

    extend ClassMethods
    include InstanceMethods

    def initialize(options = {})
      @interface_class = options.fetch(:interface_class, self.class.interface_class)
      @interface_class ||= custom_interface_class
      @interface_name = options.fetch(:interface_name, self.class.interface_name)
      @interface_name ||= interface_class.name.singularize.underscore
      @interface_id = options.fetch(:interface_id, self.class.interface_id)
      @interface_id ||= custom_interface_id
    end

    private

    def custom_interface_class
      self.class.name.chomp('Service').singularize.constantize
    rescue NameError
      self.class.name.chomp('Service').split('::').last.singularize.constantize
    end

    def custom_interface_id
      if self.class.name.chomp('Controller').split('::').size > 1
        "#{interface_name.gsub('/', '_')}_id"
      else
        'id'
      end
    rescue NameError
      'id'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zertico-2.0.0.alpha.2 lib/zertico/service.rb