[Groonga-commit] droonga/droonga-engine at 48e28ad [master] Make Droonga::Address subclass of Droonga::NodeName

Back to archive index

Kouhei Sutou kou****@clear*****
Wed Mar 25 10:48:21 JST 2015


>     Make Droonga::Address subclass of Droonga::NodeName

ちょっとよくわかっていないんですけど、NodeNameというものは
Addressというものを包含しているものですか?であれば、これで
いいと思うんですが、包含しているわけじゃない(違う概念のもの)
だけど実装が似ている、ということならサブクラスにはせずにこの
変更の前のようにコンポジションしてまとめておいた方が、実体に
即した理解しやすいコードになると思います。

>      def to_s
> +      node
> +    end
> +
> +    def node
>        "#{@host}:#{@port}/#{@tag}"
>      end

これはいいと思います。

In <48e28ad810e74bb985f00f801fc9ca615ed9f9b5 �� jenkins.clear-code.com>
  "[Groonga-commit] droonga/droonga-engine �� 48e28ad [master] Make Droonga::Address subclass of Droonga::NodeName" on Wed, 25 Mar 2015 10:21:30 +0900,
  YUKI Hiroshi <null+groonga �� clear-code.com> wrote:

> YUKI Hiroshi	2015-03-25 10:21:30 +0900 (Wed, 25 Mar 2015)
> 
>   New Revision: 48e28ad810e74bb985f00f801fc9ca615ed9f9b5
>   https://github.com/droonga/droonga-engine/commit/48e28ad810e74bb985f00f801fc9ca615ed9f9b5
> 
>   Message:
>     Make Droonga::Address subclass of Droonga::NodeName
> 
>   Modified files:
>     lib/droonga/address.rb
>     lib/droonga/node_name.rb
> 
>   Modified: lib/droonga/address.rb (+4 -20)
> ===================================================================
> --- lib/droonga/address.rb    2015-03-25 00:17:56 +0900 (89e8f33)
> +++ lib/droonga/address.rb    2015-03-25 10:21:30 +0900 (34acf5d)
> @@ -16,7 +16,7 @@
>  require "droonga/node_name"
>  
>  module Droonga
> -  class Address
> +  class Address < NodeName
>      class << self
>        def parse(string)
>          if /\A(.+):(\d+)\/([^.]+)(?:\.(.+))?\z/ =~ string
> @@ -37,38 +37,22 @@ module Droonga
>  
>      attr_reader :name
>      def initialize(components={})
> -      @node = NodeName.new(components)
> +      super
>        @name = components[:name]
>      end
>  
> -    def host
> -      @node.host
> -    end
> -
> -    def port
> -      @node.port
> -    end
> -
> -    def tag
> -      @node.tag
> -    end
> -
>      def to_s
> -      string = node
> +      string = super
>        string << ".#{@name}" if @name
>        string
>      end
>  
>      def to_a
> -      @node.to_a + [@name]
> +      super + [@name]
>      end
>  
>      def ==(other)
>        other.is_a?(self.class) and to_a == other.to_a
>      end
> -
> -    def node
> -      @node.to_s
> -    end
>    end
>  end
> 
>   Modified: lib/droonga/node_name.rb (+4 -0)
> ===================================================================
> --- lib/droonga/node_name.rb    2015-03-25 00:17:56 +0900 (7abc6b6)
> +++ lib/droonga/node_name.rb    2015-03-25 10:21:30 +0900 (2b4e09b)
> @@ -58,6 +58,10 @@ module Droonga
>      end
>  
>      def to_s
> +      node
> +    end
> +
> +    def node
>        "#{@host}:#{@port}/#{@tag}"
>      end
>  




More information about the Groonga-commit mailing list
Back to archive index