orbit-4-2/lib/orbit_app/plugin/registration.rb

99 lines
2.4 KiB
Ruby
Raw Permalink Normal View History

module OrbitApp
module Plugin
module Registration
Version = "0.2"
module ClassMethods
@@registrations = []
def new( name ,&block)
@@registrations << DataSheet.new(name,&block)
end
def new_from_module_app(name,key,base_path,*args)
@@registrations << DataSheet.new(name,args,:base_path=>base_path)
end
def find_by_app_name(name)
@@registrations.each{|t|
return t if t.app_name == name
}
return nil
end
def find_by_key(key)
@@registrations.each{|t|
return t if t.name == key
}
return nil
end
def all
return @@registrations
end
end
extend ClassMethods
def self.included( other )
other.extend( ClassMethods )
end
class DataSheet
attr_reader :name
attr_reader :base_path
def name
if @name.is_a? Proc
@name.call
else
@name
end
end
def initialize(name,partial=nil,*args ,&block)
@base_path = args[0][:base_path]
@name = partial[0][:i18n].nil? ? name : lambda{ I18n.t(partial[0][:i18n]) }
@sort_number = partial[0][:sort_number]
@app_name = partial[0][:app_name]
@intro_app_name = partial[0][:intro_app_name]
@partial_path = ''
@front_partial_path = ''
@admin_partial_path = ''
unless partial.nil?
@partial_path = partial[0][:path]
@front_partial_path = partial[0][:front_path]
@admin_partial_path = partial[0][:admin_path]
end
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
end
def sort_number
return @sort_number
end
def app_name
return @app_name
end
def intro_app_name
return @intro_app_name
end
def profile_partial_path
return @partial_path
end
def front_partial_path
return @front_partial_path
end
def admin_partial_path
return @admin_partial_path
end
end
end
end
end