class Easyfire::EasyfireModel

Attributes

spec[RW]

Public Class Methods

new() click to toggle source
# File lib/easyfire/easyfire_model.rb, line 17
def initialize()
  @spec = ModelSpec.new
end

Public Instance Methods

attr_association(value) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 112
def attr_association(value)
  @spec.attributes[@attribute_name][:association] = value
end
attr_data_type(symbol) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 128
def attr_data_type(symbol)
  @spec.attributes[@attribute_name][:type] = symbol
end
attr_description(text) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 124
def attr_description(text)
 @spec.attributes[@attribute_name][:description] = text
end
attr_example(text) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 120
def attr_example(text)
  @spec.attributes[@attribute_name][:example] = text
end
attr_options(options) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 116
def attr_options(options)
  @spec.attributes[@attribute_name][:options] = options
end
attribute(attribute_name, &block) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 101
def attribute(attribute_name, &block)
  @attribute_name = attribute_name
  new_attribute = {
    description: "",
    example: "",
    type: nil,
    options: [],
    association: nil
  }

  unless self.respond_to? :attr_association
    def attr_association(value)
      @spec.attributes[@attribute_name][:association] = value
    end
  
    def attr_options(options)
      @spec.attributes[@attribute_name][:options] = options
    end
    
    def attr_example(text)
      @spec.attributes[@attribute_name][:example] = text
    end

    def attr_description(text)
     @spec.attributes[@attribute_name][:description] = text
    end

    def attr_data_type(symbol)
      @spec.attributes[@attribute_name][:type] = symbol
    end
  end
  
  
  @spec.attributes[@attribute_name] = new_attribute
  block.call
end
belongs_to(bt_name, &block) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 49
def belongs_to(bt_name, &block)
  
  @bt_name = bt_name

  new_association = {
    type: :belongs_to,
    description: "",
    example: "",
    navigable: false,
    load: :lazy
  }

  unless self.respond_to? :bt_navigable
    
    def bt_navigable(value)
      @spec.associations[@bt_name][:navigable] = value
    end
  
    def bt_load(value)
      @spec.associations[@bt_name][:load] = value
    end

    def bt_example(text)
      @spec.associations[@bt_name][:example] = text
    end

    def bt_description(text)
      @spec.associations[@bt_name][:description] = text
    end
    
  end

  @spec.associations[@bt_name] = new_association
  block.call
  
  
  proc = Proc.new do
      attr_description ""
      attr_data_type :String
  end
  attribute("#{bt_name.to_s.uncapitalize}EFPath".to_sym,&proc)

  proc = Proc.new do
      attr_description ""
      attr_data_type "#{bt_name}EF"
      attr_options [:transient]
      attr_association bt_name
  end

  attribute("#{bt_name.to_s.uncapitalize}EF".to_sym,&proc)
end
bt_description(text) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 75
def bt_description(text)
  @spec.associations[@bt_name][:description] = text
end
bt_example(text) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 71
def bt_example(text)
  @spec.associations[@bt_name][:example] = text
end
bt_load(value) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 67
def bt_load(value)
  @spec.associations[@bt_name][:load] = value
end
bt_navigable(value) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 63
def bt_navigable(value)
  @spec.associations[@bt_name][:navigable] = value
end
child(child_class) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 43
def child(child_class)
  @@spec.child = child_class
end
compile(&block) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 21
def compile(&block)
  instance_eval(&block)
  return @spec
end
description(text) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 34
def description(text)
  @spec.description = text
end
model_name(text) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 26
def model_name(text)
  @spec.model_name = text
end
model_type(value) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 38
def model_type(value)
  @spec.model_type = value
end
parents(value) click to toggle source
# File lib/easyfire/easyfire_model.rb, line 30
def parents(value)
  @spec.parents = value
end