Class: TinyGID
- Inherits:
-
Object
- Object
- TinyGID
- Extended by:
- MethodMissing
- Includes:
- MethodMissing
- Defined in:
- lib/tiny_gid.rb
Defined Under Namespace
Modules: MethodMissing
Constant Summary collapse
- VERSION =
"0.1.2"- FORMAT =
"gid://%s/%s/%s"- REGEX =
%r{\Agid://([^/]+)/([^/]+)/([^/?]+)(?:\?(.*?))?\z}
Class Method Summary collapse
- .app(name = nil) ⇒ Object
-
.app=(name) ⇒ Object
In GlobalID app names must be valid URI hostnames: alphanumeric and hyphen characters only.
- .parse(gid) ⇒ Object
- .to_sc(gid) ⇒ Object
Instance Method Summary collapse
-
#initialize(app) ⇒ TinyGID
constructor
A new instance of TinyGID.
- #method_missing(name, *arguments, &block) ⇒ Object
- #parse(gid) ⇒ Object
- #to_sc(gid) ⇒ Object
Constructor Details
#initialize(app) ⇒ TinyGID
Returns a new instance of TinyGID.
79 80 81 82 |
# File 'lib/tiny_gid.rb', line 79 def initialize(app) raise ArgumentError, "app required" if app.to_s.strip.empty? @app = app end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *arguments, &block) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/tiny_gid.rb', line 95 def method_missing(name, *arguments, &block) id = arguments.shift = arguments.shift || {} = .merge(:__app__ => @app) unless .include?(:app) super(name, id, , &block) end |
Class Method Details
.app(name = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tiny_gid.rb', line 39 def app(name = nil) if block_given? raise ArgumentError, "block provided without an app name to scope to" unless name begin Thread.current[:__tiny_gid_app__] = name yield self ensure Thread.current[:__tiny_gid_app__] = nil end return end # No block but given a name, just set it :| @app = name if name case when Thread.current[:__tiny_gid_app__] Thread.current[:__tiny_gid_app__] when @app @app when defined?(Rails) && Rails.respond_to?(:application) && Rails.application.respond_to?(:name) Rails.application.name end end |
.app=(name) ⇒ Object
In GlobalID app names must be valid URI hostnames: alphanumeric and hyphen characters only
35 36 37 |
# File 'lib/tiny_gid.rb', line 35 def app=(name) @app = name end |