Class: RbsActivesupport::AttributeAccessor

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_activesupport/attribute_accessor.rb,
sig/rbs_activesupport/attribute_accessor.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ AttributeAccessor



10
11
12
13
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 10

def initialize(name, options) #: void
  @name = name
  @options = options
end

Instance Attribute Details

#nameSymbol (readonly)

: Symbol



5
6
7
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 5

def name
  @name
end

#optionsHash[untyped, untyped] (readonly)

: Hash[untyped, untyped]



6
7
8
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 6

def options
  @options
end

Instance Method Details

#default?Boolean

: boolish



47
48
49
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 47

def default? #: boolish
  options.fetch(:default, nil)
end

#default_typeString

: String



51
52
53
54
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 51

def default_type #: String
  default = options.fetch(:default, nil)
  RbsActivesupport::Types.guess_type(default)
end

#included?Boolean

: bool



64
65
66
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 64

def included? #: bool
  options.fetch(:included, false)
end

#instance_accessor?Boolean

: bool



35
36
37
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 35

def instance_accessor? #: bool
  options.fetch(:instance_accessor, true)
end

#instance_reader?Boolean

: bool



39
40
41
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 39

def instance_reader? #: bool
  options.fetch(:instance_reader, instance_accessor?)
end

#instance_writer?Boolean

: bool



43
44
45
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 43

def instance_writer? #: bool
  options.fetch(:instance_writer, instance_accessor?)
end

#private?Boolean

: bool



60
61
62
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 60

def private? #: bool
  options.fetch(:private, false)
end

#public?Boolean

: bool



56
57
58
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 56

def public? #: bool
  !private?
end

#singleton_reader?Boolean

: bool



27
28
29
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 27

def singleton_reader? #: bool
  options.fetch(:singleton_reader, true)
end

#singleton_writer?Boolean

: bool



31
32
33
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 31

def singleton_writer? #: bool
  options.fetch(:singleton_writer, true)
end

#typeString

: String



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rbs_activesupport/attribute_accessor.rb', line 15

def type #: String
  # @type var trailing_comment: String?
  trailing_comment = options[:trailing_comment]
  if trailing_comment&.start_with?("#:")
    trailing_comment[2..].strip
  elsif default?
    default_type
  else
    "untyped"
  end
end