Class: Fob::Fob

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
lib/fob/fob.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Fob

Returns a new instance of Fob.



25
26
27
28
# File 'lib/fob/fob.rb', line 25

def initialize(*args, &block)
  super
  @persisted = false
end

Class Method Details

.has_one(name, options = {}) ⇒ Object



21
22
23
# File 'lib/fob/fob.rb', line 21

def self.has_one(name, options={})
  include_model(name, options)
end

.represents(name, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/fob/fob.rb', line 11

def self.represents(name, options={})
  include_model(name, options)
  klass = name.to_s.camelcase
  singleton_class.instance_eval do
    define_method(:model_name) do
      ::ActiveModel::Name.new(self, nil, "#{klass}")
    end
  end
end

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/fob/fob.rb', line 34

def persisted?
  @persisted
end

#saveObject



30
31
32
# File 'lib/fob/fob.rb', line 30

def save
  @persisted = yield attributes
end