Class: URI::PlateID

Inherits:
Generic
  • Object
show all
Defined in:
lib/uri/plate_id.rb

Constant Summary collapse

MAPPING =
{
  "Site" => { host: "Base", base_class: "Site" },
  "Ngn::Site" => { host: "Base", base_class: "Site" },
  "Org::Site" => { host: "Base", base_class: "Site" },
  "Ngn::Attachment" => { host: "Base", base_class: "Attachment" },
  "Ngn::AttachmentSetting" => { host: "Base", base_class: "AttachmentSetting" },
  "Ngn::AttachmentFolder" => { host: "Base", base_class: "AttachmentFolder" },
  "Ngn::Domain" => { host: "Base", base_class: "Domain" },
  "Ngn::ClipboardItem" => { host: "Base", base_class: "ClipboardItem" },
  "Ngn::VersionControl::Actions::Action" => { host: "Base", base_class: "VersionControl" },
  "Ngn::Redirect" => { host: "Base", base_class: "Redirect" },

  "Ngn::Content::Post" => { host: "Content", base_class: "Post" },
  "Ngn::Content::Section" => { host: "Content", base_class: "Section" },
  "Ngn::Content::Row" => { host: "Content", base_class: "Row" },
  "Ngn::Content::Column" => { host: "Content", base_class: "Column" },
  "Ngn::Content::Element" => { host: "Content", base_class: "Element" },
  "Ngn::Content::ContentObject" => { host: "Content", base_class: "ContentObject" },
  "Ngn::Content::SiteTranslation" => { host: "Content", base_class: "SiteTranslation" },
  "Ngn::Content::AuthenticationObject" => { host: "Content", base_class: "AuthenticationObject" },

  "Ngn::ContentModel::ContentField" => { host: "ContentModel", base_class: "ContentField" },
  "Ngn::ContentModel::ContentFieldTab" => { host: "ContentModel", base_class: "ContentFieldGroup" },
  "Ngn::ContentModel::PostType" => { host: "ContentModel", base_class: "PostType" },
  "Ngn::ContentModel::SectionType" => { host: "ContentModel", base_class: "SectionType" },
  "Ngn::ContentModel::ElementType" => { host: "ContentModel", base_class: "ElementType" },
  "Ngn::ContentModel::ObjectTypeKind" => { host: "ContentModel", base_class: "ContentType" },
  "Ngn::ContentModel::ObjectType" => { host: "ContentModel", base_class: "ObjectType" }, # TODO: legacy, to be replaced with typed kinds
  "Ngn::ContentModel::TrayType" => { host: "ContentModel", base_class: "TrayType" },
  "Ngn::ContentModel::AuthenticationType" => { host: "ContentModel", base_class: "AuthenticationType" },

  "Ngn::Theming::Theme" => { host: "Theming", base_class: "Theme" },
  "Ngn::Theming::ThemeFile" => { host: "Theming", base_class: "ThemeFile" },
  "Ngn::Theming::Prerender" => { host: "Theming", base_class: "Prerender" },

  "Org::Auth::User" => { host: "Auth", base_class: "User" },
  "Api::Integration" => { host: "Auth", base_class: "ApiIntegration" },

  "Org::Company" => { host: "Organization", base_class: "Company" },
  "Org::Partner" => { host: "Organization", base_class: "Partner" },
  "Org::FormMessage" => { host: "Organization", base_class: "FormMessage" },

  # Access control
  "AccessControl::Policy" => { host: "AccessControl", base_class: "Policy" },
  "AccessControl::Role" => { host: "AccessControl", base_class: "Role" },
  "AccessControl::Group" => { host: "AccessControl", base_class: "Group" }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_classObject (readonly)

Returns the value of attribute base_class.



62
63
64
# File 'lib/uri/plate_id.rb', line 62

def base_class
  @base_class
end

#idObject

Returns the value of attribute id.



62
63
64
# File 'lib/uri/plate_id.rb', line 62

def id
  @id
end

Class Method Details

.build(args) ⇒ Object

Create a new URI::PlateID from components with argument check.

The allowed components are model_name and model_id, which can be either a hash or an array.

Using a hash:

URI::PlateID.build(
  model_name: 'Ngn::ContentModel::ElementType',
  model_id: '1'
)


94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/uri/plate_id.rb', line 94

def build(args)
  comps = Util.make_components_hash(self, args)
  return unless comps

  parts = MAPPING[comps[:model_name]].dup
  return unless parts

  parts[:scheme] = comps[:scheme]
  parts[:id] = comps[:model_id]
  parts[:path] = "/#{parts[:base_class]}/#{CGI.escape(parts[:id].to_s)}"

  super(parts)
end

.create(model) ⇒ Object

Shorthand to build a URI::PlateID from a model.

URI::PlateID.create(Ngn::Content::Post.find(5))
URI::PlateID.create(Ngn::Content::Post)


78
79
80
81
# File 'lib/uri/plate_id.rb', line 78

def create(model)
  model = model.new if model.class == Class
  build(model_name: model.class.name, model_id: model.id)
end

.parse(uri) ⇒ Object

Create a new URI::PlateID by parsing a plateid string with argument check.

URI::PlateID.parse 'plateid://Group/Class/1'


69
70
71
72
# File 'lib/uri/plate_id.rb', line 69

def parse(uri)
  generic_components = URI.split(uri) << nil << true # nil parser, true arg_check
  new(*generic_components)
end

Instance Method Details

#to_sObject

Implement #to_s to avoid no implicit conversion of nil into string when path is nil



110
111
112
# File 'lib/uri/plate_id.rb', line 110

def to_s
  "plateid://#{host}/#{base_class}/#{id}"
end