Class: Immutabler::DSL::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/immutabler/dsl/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Group

Returns a new instance of Group.



12
13
14
15
16
17
18
19
20
# File 'lib/immutabler/dsl/group.rb', line 12

def initialize(name)
  @prefix = ''
  @base_model = 'NSObject'
  @name = name
  @models = []
  @enums = []
  @links = []
  @module_links = []
end

Instance Attribute Details

#enumsObject

Returns the value of attribute enums.



10
11
12
# File 'lib/immutabler/dsl/group.rb', line 10

def enums
  @enums
end

Returns the value of attribute links.



10
11
12
# File 'lib/immutabler/dsl/group.rb', line 10

def links
  @links
end

#modelsObject

Returns the value of attribute models.



10
11
12
# File 'lib/immutabler/dsl/group.rb', line 10

def models
  @models
end

Returns the value of attribute module_links.



10
11
12
# File 'lib/immutabler/dsl/group.rb', line 10

def module_links
  @module_links
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/immutabler/dsl/group.rb', line 10

def name
  @name
end

#output_directoryObject

Returns the value of attribute output_directory.



10
11
12
# File 'lib/immutabler/dsl/group.rb', line 10

def output_directory
  @output_directory
end

#prefix(prefix) ⇒ Object

Returns the value of attribute prefix.



10
11
12
# File 'lib/immutabler/dsl/group.rb', line 10

def prefix
  @prefix
end

Instance Method Details

#base_model(name) ⇒ Object



38
39
40
# File 'lib/immutabler/dsl/group.rb', line 38

def base_model(name)
  @base_model = name
end

#buildObject



62
63
64
65
66
67
68
69
70
# File 'lib/immutabler/dsl/group.rb', line 62

def build
  {
    name: name,
    models: models,
    links: links,
    module_links: module_links,
    enums: enums,
  }
end

#enum(name, &block) ⇒ Object



42
43
44
45
46
47
# File 'lib/immutabler/dsl/group.rb', line 42

def enum(name, &block)
  attributes = []
  prefix = "#{@prefix}#{name}"
  EnumAttributesBuilder.new(attributes, prefix, &block)
  @enums << Enum.new(prefix, attributes)
end


26
27
28
# File 'lib/immutabler/dsl/group.rb', line 26

def link_to(model_group_name)
  links << model_group_name
end

#model(name, options = {}, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/immutabler/dsl/group.rb', line 49

def model(name, options = {}, &block)
  prefix = @prefix + name.to_s
  base = options.fetch(:base, @base_model).to_s
  base_immutable = options.fetch(:base_immutable, false)
  builder_base = options.fetch(:builder_base, base).to_s
  props = []
  ModelAttributesBuilder.new(props, &block)

  model = Model.new(prefix, base, base_immutable, builder_base, props)

  models << model
end


30
31
32
# File 'lib/immutabler/dsl/group.rb', line 30

def module_link_to(module_name, file_name)
  module_links << ModuleImport.new(module_name, file_name)
end

#output_dir(dir) ⇒ Object



34
35
36
# File 'lib/immutabler/dsl/group.rb', line 34

def output_dir(dir)
  self.output_directory = dir
end