Class: PactBroker::DB::Clean::BranchSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/db/clean/branch_selector.rb

Constant Summary collapse

ATTRIBUTES =
[:max_age, :branch]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ BranchSelector

Returns a new instance of BranchSelector.



13
14
15
16
17
18
# File 'lib/pact_broker/db/clean/branch_selector.rb', line 13

def initialize(attributes = {})
  attributes.each do | (name, value) |
    instance_variable_set("@#{name}", value) if respond_to?(name)
  end
  @source_hash = attributes[:source_hash]
end

Class Method Details

.from_hash(hash) ⇒ Object



20
21
22
23
24
25
# File 'lib/pact_broker/db/clean/branch_selector.rb', line 20

def self.from_hash(hash)
  standard_hash = hash.symbolize_keys.snakecase_keys
  new_hash = standard_hash.slice(*ATTRIBUTES)
  new_hash[:source_hash] = hash
  new(new_hash.compact)
end

Instance Method Details

#to_hashObject Also known as: to_h



27
28
29
30
31
# File 'lib/pact_broker/db/clean/branch_selector.rb', line 27

def to_hash
  ATTRIBUTES.each_with_object({}) do | key, hash |
    hash[key] = send(key)
  end.compact
end

#to_json(_opts = nil) ⇒ Object



34
35
36
# File 'lib/pact_broker/db/clean/branch_selector.rb', line 34

def to_json(_opts = nil)
  (@source_hash || to_hash).to_json
end