Sha256: a338f88ec3995a220841da58b482e1c6fa7a8037e19968d36764e40d332f4e8a

Contents?: true

Size: 1.89 KB

Versions: 8

Compression:

Stored size: 1.89 KB

Contents

require 'fedux_org/stdlib/models/base_model'

module FeduxOrg
  module Stdlib
    module Models
      # model for import action
      module FilesystemBasedModel

        def self.included(base)
          base.extend ClassMethods
        end

        module ClassMethods

          #initialize model
          def init
            load_from_filesystem
          end

          private

          def module_name
            name = fqcn
            name.pop

            name.join('::')
          end

          def fqcn
            self.to_s.split(/::/)
          end

          def model_name
            fqcn.last
          end

          def library_name
            fqcn.first
          end

          def suffix
            raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented, "Please defined the method \"suffix\" to make the library work."
          end

          def path
            raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented, "Please defined the method \"path\" to make the library work."
          end

          def path_to_instances
            local_path = ::File.expand_path("../../#{model_name.pluralize.underscore}", path )
            return_path = ::File.join(local_path,"*#{suffix}")

            FeduxOrg::Stdlib.logger.debug(self) { "Path to instances of model: #{return_path}" }

            return_path
          end

          def name(path)
            name = File.basename(path, suffix ).to_sym
            raise FeduxOrg::Stdlib::Models::Exceptions::UnauthorizedUseOfKeyword if forbidden_keywords.include? name

            FeduxOrg::Stdlib.logger.debug(self) { "Name of model: #{name}" }

            name
          end

          def load_from_filesystem
            raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented
          end

          def forbidden_keywords
            [ ]
          end

        end

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.0.16 lib/fedux_org/stdlib/models/filesystem_based_model.rb
fedux_org-stdlib-0.0.14 lib/fedux_org/stdlib/models/filesystem_based_model.rb
fedux_org-stdlib-0.0.13 lib/fedux_org/stdlib/models/filesystem_based_model.rb
fedux_org-stdlib-0.0.12 lib/fedux_org/stdlib/models/filesystem_based_model.rb
fedux_org-stdlib-0.0.11 lib/fedux_org/stdlib/models/filesystem_based_model.rb
fedux_org-stdlib-0.0.10 lib/fedux_org/stdlib/models/filesystem_based_model.rb
fedux_org-stdlib-0.0.9 lib/fedux_org/stdlib/models/filesystem_based_model.rb
fedux_org-stdlib-0.0.8 lib/fedux_org/stdlib/models/filesystem_based_model.rb