Sha256: 64f1d2eead189065bdc480c3444e552eeaefbc9277d988f9d52357904cff9966

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

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
          end

          def path_to_instances
            path = File.expand_path("../../#{model_name.pluralize.underscore}", __FILE__ )

            File.join(path,"*#{suffix}")
          end

          def name(path)
            name = File.basename(path, suffix ).to_sym
            raise FeduxOrg::Stdlib::Models::Exceptions::UnauthorizedUseOfKeyword if forbidden_keywords.include? 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

1 entries across 1 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.0.2 lib/fedux_org/stdlib/models/filesystem_based_model.rb