Class: Rubyists::Linear::BaseModel

Inherits:
Object
  • Object
show all
Extended by:
GQLi::DSL, ClassMethods
Includes:
GQLi::DSL, SemanticLogger::Loggable
Defined in:
lib/linear/models/base_model.rb,
lib/linear/models/base_model/method_magic.rb,
lib/linear/models/base_model/class_methods.rb

Overview

The base model for all Linear models

Defined Under Namespace

Modules: ClassMethods, MethodMagic

Constant Summary collapse

CANCELLED_STATES =
%w[cancelled canceled].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

all, all_query, allq, base_fragment, basic_filter, const_added, find, full_fragment, getter!, gql_query, just_name, many_setter!, many_to_one, one_to_many, plural, setter!

Constructor Details

#initialize(data) ⇒ BaseModel

Returns a new instance of BaseModel.



22
23
24
25
26
# File 'lib/linear/models/base_model.rb', line 22

def initialize(data)
  data.each_key { |k| raise SmellsBad, "Unknown key #{k}" unless respond_to? "#{k}=" }
  @data = data
  @updated_data = data.dup
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



18
19
20
# File 'lib/linear/models/base_model.rb', line 18

def data
  @data
end

#updated_dataObject (readonly)

Returns the value of attribute updated_data.



18
19
20
# File 'lib/linear/models/base_model.rb', line 18

def updated_data
  @updated_data
end

Instance Method Details

#cancelled_statesObject



36
37
38
# File 'lib/linear/models/base_model.rb', line 36

def cancelled_states
  workflow_states.select { |ws| CANCELLED_STATES.include? ws.type }
end

#changed?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/linear/models/base_model.rb', line 28

def changed?
  data != updated_data
end

#completed_statesObject



32
33
34
# File 'lib/linear/models/base_model.rb', line 32

def completed_states
  workflow_states.select { |ws| ws.type == 'completed' }
end

#inspectObject



52
53
54
# File 'lib/linear/models/base_model.rb', line 52

def inspect
  format '#<%<name>s:%<id>s %<inspection>s>', name: self.class.name, id:, inspection:
end

#inspectionObject



48
49
50
# File 'lib/linear/models/base_model.rb', line 48

def inspection
  format('name: "%<name>s"', name:)
end

#to_hObject



40
41
42
# File 'lib/linear/models/base_model.rb', line 40

def to_h
  updated_data
end

#to_json(*_args) ⇒ Object



44
45
46
# File 'lib/linear/models/base_model.rb', line 44

def to_json(*_args)
  updated_data.to_json
end