Class: HostBuilder
- Inherits:
-
UsesAttributes
- Object
- UsesAttributes
- HostBuilder
- Defined in:
- lib/hosties/Reification.rb
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(type, hostname) ⇒ HostBuilder
constructor
A new instance of HostBuilder.
Methods inherited from UsesAttributes
Constructor Details
#initialize(type, hostname) ⇒ HostBuilder
Returns a new instance of HostBuilder.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hosties/Reification.rb', line 40 def initialize(type, hostname) if Hosties::HostDefinitions[type].nil? then raise ArgumentError, "Unrecognized host type" end @type = type @definition = Hosties::HostDefinitions[@type] @hostname = hostname @service_ports = {} # Map of service type to port super(@definition) # Creates attribute code # Services are really just a special kind of attribute, but for now I'll # keep them separate. I'm thinking maybe I could add a new type of attribute # constraint that let's a user specify that an attribute must be numeric, or # a string for instance. @definition.services.each do |service_type| self..send(:attr_accessor, service_type) self..send(:define_method, service_type) do |port| raise ArgumentError, "Port number required" unless port.is_a? Integer @service_ports[service_type] = port end end end |
Instance Method Details
#finish ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/hosties/Reification.rb', line 62 def finish # Ensure all services have been set @definition.services.each do |svc| raise ArgumentError, "Missing service #{svc}" if @service_ports[svc].nil? end # TODO: More clever data repackaging super.merge({ :hostname => @hostname }).merge(@service_ports) end |