Class: FlightFacade::BaseHashieDashModel

Inherits:
Object
  • Object
show all
Defined in:
lib/flight_facade/models.rb

Direct Known Subclasses

Group, Node

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*a) ⇒ BaseHashieDashModel

Returns a new instance of BaseHashieDashModel.



57
58
59
# File 'lib/flight_facade/models.rb', line 57

def initialize(*a)
  @data = self.class::DataHash.new(*a)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



55
56
57
# File 'lib/flight_facade/models.rb', line 55

def data
  @data
end

Class Method Details

._jsonapi_serializer_class_nameObject



47
48
49
# File 'lib/flight_facade/models.rb', line 47

def self._jsonapi_serializer_class_name
  @_jsonapi_serializer_class_name ||= name.split('::').last + 'Serializer'
end

._typeObject



51
52
53
# File 'lib/flight_facade/models.rb', line 51

def self._type
  @_type ||= name.split('::').last.demodulize.tableize.dasherize
end

.inherited(klass) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/flight_facade/models.rb', line 33

def self.inherited(klass)
  data_class = Class.new(Hashie::Dash) do
    include Hashie::Extensions::IgnoreUndeclared
    include ActiveModel::Validations

    def self.method_added(m)
      parent.delegate(m, to: :data)
    end
  end

  klass.const_set('DataHash', data_class)
  klass.delegate(*(ActiveModel::Validations.instance_methods - Object.methods), to: :data)
end

Instance Method Details

#jsonapi_serializer_class_nameObject



61
62
63
# File 'lib/flight_facade/models.rb', line 61

def jsonapi_serializer_class_name
  self.class._jsonapi_serializer_class_name
end

#typeObject



65
66
67
# File 'lib/flight_facade/models.rb', line 65

def type
  self.class._type
end