Class: Cathode::Version
- Inherits:
-
Object
- Object
- Cathode::Version
- Defined in:
- lib/cathode/version.rb
Constant Summary collapse
- @@all =
{}
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .all ⇒ Object
- .perform_request_with_version(version, resource, params) ⇒ Object
- .standardize(rough_version) ⇒ Object
Instance Method Summary collapse
-
#initialize(version_number, &block) ⇒ Version
constructor
A new instance of Version.
- #perform_request(resource, params) ⇒ Object
Constructor Details
#initialize(version_number, &block) ⇒ Version
Returns a new instance of Version.
10 11 12 13 14 15 16 17 |
# File 'lib/cathode/version.rb', line 10 def initialize(version_number, &block) @version = Semantic::Version.new Version.standardize(version_number) @resources = {} self.instance_eval &block if block_given? Version.all[@version.to_s] = self end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
5 6 7 |
# File 'lib/cathode/version.rb', line 5 def resources @resources end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/cathode/version.rb', line 5 def version @version end |
Class Method Details
.all ⇒ Object
24 25 26 |
# File 'lib/cathode/version.rb', line 24 def all @@all end |
.perform_request_with_version(version, resource, params) ⇒ Object
38 39 40 |
# File 'lib/cathode/version.rb', line 38 def perform_request_with_version(version, resource, params) Version.all[standardize(version)].perform_request resource, params end |
.standardize(rough_version) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/cathode/version.rb', line 28 def standardize(rough_version) version_parts = rough_version.to_s.split '.' if version_parts.count < 2 version_parts << [0, 0] elsif version_parts.count < 3 version_parts << [0] end version_parts.join '.' end |
Instance Method Details
#perform_request(resource, params) ⇒ Object
19 20 21 |
# File 'lib/cathode/version.rb', line 19 def perform_request(resource, params) resources[resource].actions[params[:action].to_sym].perform params end |