Class: Service
- Inherits:
-
Object
- Object
- Service
- Defined in:
- lib/has_helpers/utils/service.rb
Overview
typed: true frozen_string_literal: true
Instance Attribute Summary collapse
-
#external ⇒ Object
Returns the value of attribute external.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
- #icon ⇒ Object
-
#icon_placement ⇒ Object
:right or :left, default to :left.
-
#nested ⇒ Object
Returns the value of attribute nested.
Attributes included from HasHelpers::UIAttributes::HTMLAttributes
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, **options) ⇒ Service
constructor
Handle options passed to new.
- #props ⇒ Object
- #raw_html_attrs ⇒ Object
- #to_action ⇒ Object
- #to_partial_path ⇒ Object
- #to_renderable ⇒ Object
- #to_s ⇒ Object
- #to_service(**options) ⇒ Object
-
#url ⇒ Object
Returns the current url value or falls back to the current object.
- #url=(value) ⇒ Object
Methods included from HasHelpers::Attributes::GuardedAttributes
Methods included from HasHelpers::Attributes::AttributeAssignment
Constructor Details
#initialize(name, **options) ⇒ Service
Handle options passed to new. Hash args are assigned to attributes like ActiveRecord does.
Examples
Service.new("http://derp.com") Service.new("Derp", :url => "http://derp.com") Service.new("Derp", :url => "http://derp.com", :external => true)
17 18 19 20 |
# File 'lib/has_helpers/utils/service.rb', line 17 def initialize(name, **) @name = name assign_attributes() end |
Instance Attribute Details
#external ⇒ Object
Returns the value of attribute external.
7 8 9 |
# File 'lib/has_helpers/utils/service.rb', line 7 def external @external end |
#http_method ⇒ Object
Returns the value of attribute http_method.
7 8 9 |
# File 'lib/has_helpers/utils/service.rb', line 7 def http_method @http_method end |
#icon ⇒ Object
51 52 53 |
# File 'lib/has_helpers/utils/service.rb', line 51 def icon @icon && @icon.to_icon end |
#icon_placement ⇒ Object
:right or :left, default to :left
56 57 58 |
# File 'lib/has_helpers/utils/service.rb', line 56 def icon_placement @icon_placement == :right ? :right : :left end |
#nested ⇒ Object
Returns the value of attribute nested.
7 8 9 |
# File 'lib/has_helpers/utils/service.rb', line 7 def nested @nested end |
Instance Method Details
#==(other) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/has_helpers/utils/service.rb', line 79 def ==(other) case other when self.class url == other.url && to_s == other.to_s else super end end |
#props ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/has_helpers/utils/service.rb', line 70 def props {}.tap do |hash| hash[:type] = "Service" hash[:icon] = icon hash[:url] = url hash[:children] = @name end.camelize_keys! end |
#raw_html_attrs ⇒ Object
64 65 66 67 68 |
# File 'lib/has_helpers/utils/service.rb', line 64 def raw_html_attrs super.tap do |raw_attrs| raw_attrs.reverse_merge!(external: nil) if external end end |
#to_action ⇒ Object
43 44 45 |
# File 'lib/has_helpers/utils/service.rb', line 43 def to_action ::Action.new(service: self) end |
#to_partial_path ⇒ Object
47 48 49 |
# File 'lib/has_helpers/utils/service.rb', line 47 def to_partial_path "has_helpers/services/service" end |
#to_renderable ⇒ Object
60 61 62 |
# File 'lib/has_helpers/utils/service.rb', line 60 def to_renderable self end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/has_helpers/utils/service.rb', line 34 def to_s @name end |
#to_service(**options) ⇒ Object
38 39 40 41 |
# File 'lib/has_helpers/utils/service.rb', line 38 def to_service(**) assign_attributes(**) # Apply any given attributes self end |
#url ⇒ Object
Returns the current url value or falls back to the current object. Note that if url is explicitly set to nil, then no fallback will be used, but rather nil will be returned.
30 31 32 |
# File 'lib/has_helpers/utils/service.rb', line 30 def url @url_cached ? @url : to_s end |
#url=(value) ⇒ Object
22 23 24 25 |
# File 'lib/has_helpers/utils/service.rb', line 22 def url=(value) @url_cached = true @url = value end |